{
    "mode": "man",
    "parameter": "nc",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/nc/1/json",
    "generated": "2026-05-30T05:10:06Z",
    "synopsis": "nc [-46bCDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl] [-m minttl] [-O length]\n[-P proxyusername] [-p sourceport] [-q seconds] [-s sourceaddr] [-T keyword] [-V rtable]\n[-W recvlimit] [-w timeout] [-X proxyprotocol] [-x proxyaddress[:port]] [destination]\n[port]",
    "sections": {
        "NAME": {
            "content": "nc — arbitrary TCP and UDP connections and listens\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "nc [-46bCDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl] [-m minttl] [-O length]\n[-P proxyusername] [-p sourceport] [-q seconds] [-s sourceaddr] [-T keyword] [-V rtable]\n[-W recvlimit] [-w timeout] [-X proxyprotocol] [-x proxyaddress[:port]] [destination]\n[port]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The nc (or netcat) utility is used for just about anything under the sun involving TCP, UDP, or\nUNIX-domain sockets.  It can open TCP connections, send UDP packets, listen on arbitrary TCP\nand UDP ports, do port scanning, and deal with both IPv4 and IPv6.  Unlike telnet(1), nc\nscripts nicely, and separates error messages onto standard error instead of sending them to\nstandard output, as telnet(1) does with some.\n\nCommon uses include:\n\n••   simple TCP proxies\n••   shell-script based HTTP clients and servers\n••   network daemon testing\n••   a SOCKS or HTTP ProxyCommand for ssh(1)\n••   and much, much more\n\nThe options are as follows:\n",
            "subsections": [
                {
                    "name": "-4",
                    "content": "",
                    "flag": "-4"
                },
                {
                    "name": "-6",
                    "content": "",
                    "flag": "-6"
                },
                {
                    "name": "-b",
                    "content": "",
                    "flag": "-b"
                },
                {
                    "name": "-C",
                    "content": "lated into CR+LF before being written to the socket.  Line feed characters that are al‐\nready preceded with a carriage return (CR) are not translated.  Received data is not\naffected.\n",
                    "flag": "-C"
                },
                {
                    "name": "-D",
                    "content": "",
                    "flag": "-D"
                },
                {
                    "name": "-d",
                    "content": "",
                    "flag": "-d"
                },
                {
                    "name": "-F",
                    "content": "conjunction with -X to have nc perform connection setup with a proxy but then leave the\nrest of the connection to another program (e.g. ssh(1) using the sshconfig(5)\nProxyUseFdpass option).  Cannot be used with -U.\n",
                    "flag": "-F"
                },
                {
                    "name": "-h",
                    "content": "",
                    "flag": "-h"
                },
                {
                    "name": "-I",
                    "content": "Specify the size of the TCP receive buffer.\n",
                    "flag": "-I"
                },
                {
                    "name": "-i",
                    "content": "Sleep for interval seconds between lines of text sent and received.  Also causes a de‐\nlay time between connections to multiple ports.\n",
                    "flag": "-i"
                },
                {
                    "name": "-k -l",
                    "content": "gether with the -u option, the server socket is not connected and it can receive UDP\ndatagrams from multiple hosts.\n",
                    "flag": "-l"
                },
                {
                    "name": "-l",
                    "content": "The destination and port to listen on can be specified either as non-optional argu‐\nments, or with options -s and -p respectively.  Cannot be used together with -x or -z.\nAdditionally, any timeouts specified with the -w option are ignored.\n",
                    "flag": "-l"
                },
                {
                    "name": "-M",
                    "content": "",
                    "flag": "-M"
                },
                {
                    "name": "-m",
                    "content": "Ask the kernel to drop incoming packets whose TTL / hop limit is under minttl.\n",
                    "flag": "-m"
                },
                {
                    "name": "-N",
                    "content": "finish their work.\n",
                    "flag": "-N"
                },
                {
                    "name": "-n",
                    "content": "error will be reported.\n",
                    "flag": "-n"
                },
                {
                    "name": "-O",
                    "content": "Specify the size of the TCP send buffer.\n",
                    "flag": "-O"
                },
                {
                    "name": "-P",
                    "content": "Specifies a username to present to a proxy server that requires authentication.  If no\nusername is specified then authentication will not be attempted.  Proxy authentication\nis only supported for HTTP CONNECT proxies at present.\n",
                    "flag": "-P"
                },
                {
                    "name": "-p",
                    "content": "Specify the source port nc should use, subject to privilege restrictions and availabil‐\nity.\n",
                    "flag": "-p"
                },
                {
                    "name": "-q",
                    "content": "after EOF on stdin, wait the specified number of seconds and then quit. If seconds is\nnegative, wait forever (default).  Specifying a non-negative seconds implies -N.\n",
                    "flag": "-q"
                },
                {
                    "name": "-r",
                    "content": "or in the order that the system assigns them.\n",
                    "flag": "-r"
                },
                {
                    "name": "-S",
                    "content": "",
                    "flag": "-S"
                },
                {
                    "name": "-s",
                    "content": "Set the source address to send packets from, which is useful on machines with multiple\ninterfaces.  For UNIX-domain datagram sockets, specifies the local temporary socket\nfile to create and use so that datagrams can be received.  Cannot be used together with\n-x.\n",
                    "flag": "-s"
                },
                {
                    "name": "-T",
                    "content": "Change the IPv4 TOS/IPv6 traffic class value.  keyword may be one of critical,\ninetcontrol, lowcost, lowdelay, netcontrol, throughput, reliability, or one of the\nDiffServ Code Points: ef, af11 ... af43, cs0 ... cs7; or a number in either hex or dec‐\nimal.\n",
                    "flag": "-T"
                },
                {
                    "name": "-t",
                    "content": "possible to use nc to script telnet sessions.\n",
                    "flag": "-t"
                },
                {
                    "name": "-U -F -x",
                    "content": "",
                    "flag": "-x"
                },
                {
                    "name": "-u -x",
                    "content": "a datagram socket instead of a stream socket.  If a UNIX-domain socket is used, a tem‐\nporary receiving socket is created in /tmp unless the -s flag is given.\n",
                    "flag": "-x"
                },
                {
                    "name": "-V",
                    "content": "Set the routing table to be used.\n",
                    "flag": "-V"
                },
                {
                    "name": "-v",
                    "content": "",
                    "flag": "-v"
                },
                {
                    "name": "-W",
                    "content": "Terminate after receiving recvlimit packets from the network.\n",
                    "flag": "-W"
                },
                {
                    "name": "-w",
                    "content": "Connections which cannot be established or are idle timeout after timeout seconds.  The\n-w flag has no effect on the -l option, i.e. nc will listen forever for a connection,\nwith or without the -w flag.  The default is no timeout.\n",
                    "flag": "-w"
                },
                {
                    "name": "-X",
                    "content": "Use proxyprotocol when talking to the proxy server.  Supported protocols are 4 (SOCKS\nv.4), 5 (SOCKS v.5) and connect (HTTPS proxy).  If the protocol is not specified, SOCKS\nversion 5 is used.\n",
                    "flag": "-X"
                },
                {
                    "name": "-x",
                    "content": "Connect to destination using a proxy at proxyaddress and port.  If port is not speci‐\nfied, the well-known port for the proxy protocol is used (1080 for SOCKS, 3128 for\nHTTPS).  An IPv6 address can be specified unambiguously by enclosing proxyaddress in\nsquare brackets.  A proxy cannot be used with any of the options -lsuU.\n",
                    "flag": "-x"
                },
                {
                    "name": "-Z",
                    "content": "",
                    "flag": "-Z"
                },
                {
                    "name": "-z",
                    "content": "gether with -l.\n\ndestination can be a numerical IP address or a symbolic hostname (unless the -n option is\ngiven).  In general, a destination must be specified, unless the -l option is given (in which\ncase the local host is used).  For UNIX-domain sockets, a destination is required and is the\nsocket path to connect to (or listen on if the -l option is given).\n\nport can be specified as a numeric port number or as a service name.  Port ranges may be speci‐\nfied as numeric port numbers of the form nn-mm.  In general, a destination port must be speci‐\nfied, unless the -U option is given.\n",
                    "flag": "-z"
                }
            ]
        },
        "CLIENT/SERVER MODEL": {
            "content": "It is quite simple to build a very basic client/server model using nc.  On one console, start\nnc listening on a specific port for a connection.  For example:\n\n$ nc -l 1234\n\nnc is now listening on port 1234 for a connection.  On a second console (or a second machine),\nconnect to the machine and port being listened on:\n\n$ nc -N 127.0.0.1 1234\n\nThere should now be a connection between the ports.  Anything typed at the second console will\nbe concatenated to the first, and vice-versa.  After the connection has been set up, nc does\nnot really care which side is being used as a ‘server’ and which side is being used as a\n‘client’.  The connection may be terminated using an EOF (‘^D’), as the -N flag was given.\n\nThere is no -c or -e option in this netcat, but you still can execute a command after connec‐\ntion being established by redirecting file descriptors. Be cautious here because opening a port\nand let anyone connected execute arbitrary command on your site is DANGEROUS. If you really\nneed to do this, here is an example:\n\nOn ‘server’ side:\n\n$ rm -f /tmp/f; mkfifo /tmp/f\n$ cat /tmp/f | /bin/sh -i 2>&1 | nc -l 127.0.0.1 1234 > /tmp/f\n\nOn ‘client’ side:\n\n$ nc host.example.com 1234\n$ (shell prompt from host.example.com)\n\nBy doing this, you create a fifo at /tmp/f and make nc listen at port 1234 of address 127.0.0.1\non ‘server’ side, when a ‘client’ establishes a connection successfully to that port, /bin/sh\ngets executed on ‘server’ side and the shell prompt is given to ‘client’ side.\n\nWhen connection is terminated, nc quits as well. Use -k if you want it keep listening, but if\nthe command quits this option won't restart it or keep nc running. Also don't forget to remove\nthe file descriptor once you don't need it anymore:\n\n$ rm -f /tmp/f\n",
            "subsections": []
        },
        "DATA TRANSFER": {
            "content": "The example in the previous section can be expanded to build a basic data transfer model.  Any\ninformation input into one end of the connection will be output to the other end, and input and\noutput can be easily captured in order to emulate file transfer.\n\nStart by using nc to listen on a specific port, with output captured into a file:\n\n$ nc -l 1234 > filename.out\n\nUsing a second machine, connect to the listening nc process, feeding it the file which is to be\ntransferred:\n\n$ nc -N host.example.com 1234 < filename.in\n\nAfter the file has been transferred, the connection will close automatically.\n",
            "subsections": []
        },
        "TALKING TO SERVERS": {
            "content": "It is sometimes useful to talk to servers “by hand” rather than through a user interface.  It\ncan aid in troubleshooting, when it might be necessary to verify what data a server is sending\nin response to commands issued by the client.  For example, to retrieve the home page of a web\nsite:\n\n$ printf \"GET / HTTP/1.0\\r\\n\\r\\n\" | nc host.example.com 80\n\nNote that this also displays the headers sent by the web server.  They can be filtered, using a\ntool such as sed(1), if necessary.\n\nMore complicated examples can be built up when the user knows the format of requests required\nby the server.  As another example, an email may be submitted to an SMTP server using:\n\n$ nc [-C] localhost 25 << EOF\nHELO host.example.com\nMAIL FROM:<user@host.example.com>\nRCPT TO:<user2@host.example.com>\nDATA\nBody of email.\n.\nQUIT\nEOF\n",
            "subsections": []
        },
        "PORT SCANNING": {
            "content": "It may be useful to know which ports are open and running services on a target machine.  The -z\nflag can be used to tell nc to report open ports, rather than initiate a connection. Usually\nit's useful to turn on verbose output to stderr by use this option in conjunction with -v op‐\ntion.\n\nFor example:\n\n$ nc -zv host.example.com 20-30\nConnection to host.example.com 22 port [tcp/ssh] succeeded!\nConnection to host.example.com 25 port [tcp/smtp] succeeded!\n\nThe port range was specified to limit the search to ports 20 - 30, and is scanned by increasing\norder (unless the -r flag is set).\n\nYou can also specify a list of ports to scan, for example:\n\n$ nc -zv host.example.com http 20 22-23\nnc: connect to host.example.com 80 (tcp) failed: Connection refused\nnc: connect to host.example.com 20 (tcp) failed: Connection refused\nConnection to host.example.com port [tcp/ssh] succeeded!\nnc: connect to host.example.com 23 (tcp) failed: Connection refused\n\nThe ports are scanned by the order you given (unless the -r flag is set).\n\nAlternatively, it might be useful to know which server software is running, and which versions.\nThis information is often contained within the greeting banners.  In order to retrieve these,\nit is necessary to first make a connection, and then break the connection when the banner has\nbeen retrieved.  This can be accomplished by specifying a small timeout with the -w flag, or\nperhaps by issuing a \"QUIT\" command to the server:\n\n$ echo \"QUIT\" | nc host.example.com 20-30\nSSH-1.99-OpenSSH3.6.1p2\nProtocol mismatch.\n220 host.example.com IMS SMTP Receiver Version 0.84 Ready\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "Open a TCP connection to port 42 of host.example.com, using port 31337 as the source port, with\na timeout of 5 seconds:\n\n$ nc -p 31337 -w 5 host.example.com 42\n\nOpen a UDP connection to port 53 of host.example.com:\n\n$ nc -u host.example.com 53\n\nOpen a TCP connection to port 42 of host.example.com using 10.1.2.3 as the IP for the local end\nof the connection:\n\n$ nc -s 10.1.2.3 host.example.com 42\n\nCreate and listen on a UNIX-domain stream socket:\n\n$ nc -lU /var/tmp/dsocket\n\nConnect to port 42 of host.example.com via an HTTP proxy at 10.2.3.4, port 8080.  This example\ncould also be used by ssh(1); see the ProxyCommand directive in sshconfig(5) for more informa‐\ntion.\n\n$ nc -x10.2.3.4:8080 -Xconnect host.example.com 42\n\nThe same example again, this time enabling proxy authentication with username “ruser” if the\nproxy requires it:\n\n$ nc -x10.2.3.4:8080 -Xconnect -Pruser host.example.com 42\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "cat(1), ssh(1)\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "Original implementation by *Hobbit* <hobbit@avian.org>.\nRewritten with IPv6 support by\nEric Jackson <ericj@monkey.org>.\nModified for Debian port by Aron Xu ⟨aron@debian.org⟩.\n",
            "subsections": []
        },
        "CAVEATS": {
            "content": "UDP port scans using the -uz combination of flags will always report success irrespective of\nthe target machine's state.  However, in conjunction with a traffic sniffer either on the tar‐\nget machine or an intermediary device, the -uz combination could be useful for communications\ndiagnostics.  Note that the amount of UDP traffic generated may be limited either due to hard‐\nware resources and/or configuration settings.\n\nBSD                             March 31, 2021                             BSD",
            "subsections": []
        }
    },
    "summary": "nc — arbitrary TCP and UDP connections and listens",
    "flags": [
        {
            "flag": "-4",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-6",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-b",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-C",
            "long": null,
            "arg": null,
            "description": "lated into CR+LF before being written to the socket. Line feed characters that are al‐ ready preceded with a carriage return (CR) are not translated. Received data is not affected."
        },
        {
            "flag": "-D",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-d",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-F",
            "long": null,
            "arg": null,
            "description": "conjunction with -X to have nc perform connection setup with a proxy but then leave the rest of the connection to another program (e.g. ssh(1) using the sshconfig(5) ProxyUseFdpass option). Cannot be used with -U."
        },
        {
            "flag": "-h",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-I",
            "long": null,
            "arg": null,
            "description": "Specify the size of the TCP receive buffer."
        },
        {
            "flag": "-i",
            "long": null,
            "arg": null,
            "description": "Sleep for interval seconds between lines of text sent and received. Also causes a de‐ lay time between connections to multiple ports."
        },
        {
            "flag": "-l",
            "long": null,
            "arg": null,
            "description": "gether with the -u option, the server socket is not connected and it can receive UDP datagrams from multiple hosts."
        },
        {
            "flag": "-l",
            "long": null,
            "arg": null,
            "description": "The destination and port to listen on can be specified either as non-optional argu‐ ments, or with options -s and -p respectively. Cannot be used together with -x or -z. Additionally, any timeouts specified with the -w option are ignored."
        },
        {
            "flag": "-M",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-m",
            "long": null,
            "arg": null,
            "description": "Ask the kernel to drop incoming packets whose TTL / hop limit is under minttl."
        },
        {
            "flag": "-N",
            "long": null,
            "arg": null,
            "description": "finish their work."
        },
        {
            "flag": "-n",
            "long": null,
            "arg": null,
            "description": "error will be reported."
        },
        {
            "flag": "-O",
            "long": null,
            "arg": null,
            "description": "Specify the size of the TCP send buffer."
        },
        {
            "flag": "-P",
            "long": null,
            "arg": null,
            "description": "Specifies a username to present to a proxy server that requires authentication. If no username is specified then authentication will not be attempted. Proxy authentication is only supported for HTTP CONNECT proxies at present."
        },
        {
            "flag": "-p",
            "long": null,
            "arg": null,
            "description": "Specify the source port nc should use, subject to privilege restrictions and availabil‐ ity."
        },
        {
            "flag": "-q",
            "long": null,
            "arg": null,
            "description": "after EOF on stdin, wait the specified number of seconds and then quit. If seconds is negative, wait forever (default). Specifying a non-negative seconds implies -N."
        },
        {
            "flag": "-r",
            "long": null,
            "arg": null,
            "description": "or in the order that the system assigns them."
        },
        {
            "flag": "-S",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-s",
            "long": null,
            "arg": null,
            "description": "Set the source address to send packets from, which is useful on machines with multiple interfaces. For UNIX-domain datagram sockets, specifies the local temporary socket file to create and use so that datagrams can be received. Cannot be used together with -x."
        },
        {
            "flag": "-T",
            "long": null,
            "arg": null,
            "description": "Change the IPv4 TOS/IPv6 traffic class value. keyword may be one of critical, inetcontrol, lowcost, lowdelay, netcontrol, throughput, reliability, or one of the DiffServ Code Points: ef, af11 ... af43, cs0 ... cs7; or a number in either hex or dec‐ imal."
        },
        {
            "flag": "-t",
            "long": null,
            "arg": null,
            "description": "possible to use nc to script telnet sessions."
        },
        {
            "flag": "-x",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-x",
            "long": null,
            "arg": null,
            "description": "a datagram socket instead of a stream socket. If a UNIX-domain socket is used, a tem‐ porary receiving socket is created in /tmp unless the -s flag is given."
        },
        {
            "flag": "-V",
            "long": null,
            "arg": null,
            "description": "Set the routing table to be used."
        },
        {
            "flag": "-v",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-W",
            "long": null,
            "arg": null,
            "description": "Terminate after receiving recvlimit packets from the network."
        },
        {
            "flag": "-w",
            "long": null,
            "arg": null,
            "description": "Connections which cannot be established or are idle timeout after timeout seconds. The -w flag has no effect on the -l option, i.e. nc will listen forever for a connection, with or without the -w flag. The default is no timeout."
        },
        {
            "flag": "-X",
            "long": null,
            "arg": null,
            "description": "Use proxyprotocol when talking to the proxy server. Supported protocols are 4 (SOCKS v.4), 5 (SOCKS v.5) and connect (HTTPS proxy). If the protocol is not specified, SOCKS version 5 is used."
        },
        {
            "flag": "-x",
            "long": null,
            "arg": null,
            "description": "Connect to destination using a proxy at proxyaddress and port. If port is not speci‐ fied, the well-known port for the proxy protocol is used (1080 for SOCKS, 3128 for HTTPS). An IPv6 address can be specified unambiguously by enclosing proxyaddress in square brackets. A proxy cannot be used with any of the options -lsuU."
        },
        {
            "flag": "-Z",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-z",
            "long": null,
            "arg": null,
            "description": "gether with -l. destination can be a numerical IP address or a symbolic hostname (unless the -n option is given). In general, a destination must be specified, unless the -l option is given (in which case the local host is used). For UNIX-domain sockets, a destination is required and is the socket path to connect to (or listen on if the -l option is given). port can be specified as a numeric port number or as a service name. Port ranges may be speci‐ fied as numeric port numbers of the form nn-mm. In general, a destination port must be speci‐ fied, unless the -U option is given."
        }
    ],
    "examples": [
        "Open a TCP connection to port 42 of host.example.com, using port 31337 as the source port, with",
        "a timeout of 5 seconds:",
        "$ nc -p 31337 -w 5 host.example.com 42",
        "Open a UDP connection to port 53 of host.example.com:",
        "$ nc -u host.example.com 53",
        "Open a TCP connection to port 42 of host.example.com using 10.1.2.3 as the IP for the local end",
        "of the connection:",
        "$ nc -s 10.1.2.3 host.example.com 42",
        "Create and listen on a UNIX-domain stream socket:",
        "$ nc -lU /var/tmp/dsocket",
        "Connect to port 42 of host.example.com via an HTTP proxy at 10.2.3.4, port 8080.  This example",
        "could also be used by ssh(1); see the ProxyCommand directive in sshconfig(5) for more informa‐",
        "tion.",
        "$ nc -x10.2.3.4:8080 -Xconnect host.example.com 42",
        "The same example again, this time enabling proxy authentication with username “ruser” if the",
        "proxy requires it:",
        "$ nc -x10.2.3.4:8080 -Xconnect -Pruser host.example.com 42"
    ],
    "see_also": [
        {
            "name": "cat",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/cat/1/json"
        },
        {
            "name": "ssh",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/ssh/1/json"
        }
    ]
}