Linux "nc" Command Line Options and Examples
arbitrary TCP and UDP connections and listens

The nc (or netcat) utility is used for just about anything under the sun involving TCP, UDP, or UNIX-domain sockets. It can open TCP connections, send UDP packets, listen on arbitrary TCP and UDP ports, do port scanning, and deal with both IPv4 and IPv6.


Usage:

nc [-46bCDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl] [-m minttl] [-O length] [-P proxy_username] [-p source_port] [-q seconds]
[-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [-Z peercertfile]
[destination] [port]






Command Line Options:

-4
Forces nc to use IPv4 addresses only.
nc -4 ...
-6
Forces nc to use IPv6 addresses only.
nc -6 ...
-b
Allow broadcast.
nc -b ...
-D
Enable debugging on the socket.
nc -D ...
-d
Do not attempt to read from stdin.
nc -d ...
-h
Prints out nc help.
nc -h ...
-I
Specifies the size of the TCP receive buffer.
nc -I ...
-i
Specifies a delay time interval between lines of text sent and received. Also causes a delay time between connections to mul‐tiple ports.
nc -i ...
-M
ttl Set the TTL / hop limit of outgoing packets.
nc -M ...
-m
Ask the kernel to drop incoming packets whose TTL / hop limit is under minttl.
nc -m ...
-N
shutdown(2) the network socket after EOF on the input. Some servers require this to finish their work.
nc -N ...
-n
Do not do any DNS or service lookups on any specified addresses, hostnames or ports.
nc -n ...
-O
Specifies the size of the TCP send buffer.
nc -O ...
-P
Specifies a username to present to a proxy server that requires authentication. If no username is specified then authentica‐tion will not be attempted. Proxy authentication is only supported for HTTP CONNECT proxies at present.
nc -P ...
-p
Specifies the source port nc should use, subject to privilege restrictions and availability.
nc -p ...
-q
after EOF on stdin, wait the specified number of seconds and then quit. If seconds is negative, wait forever (default). Speci‐fying a non-negative seconds implies -N.
nc -q ...
-S
Enables the RFC 2385 TCP MD5 signature option.
nc -S ...
-s
Specifies the IP of the interface which is used to send the packets. For UNIX-domain datagram sockets, specifies the localtemporary socket file to create and use so that datagrams can be received.
nc -s ...
-T
Change IPv4 TOS value. keyword may be one of critical, inetcontrol, lowcost, lowdelay, netcontrol, throughput, reliability, orone of the DiffServ Code Points: ef, af11 ... af43, cs0 ... cs7; or a number in either hex or decimal.
nc -T ...
-U
Specifies to use UNIX-domain sockets.
nc -U ...
-V
Set the routing table to be used.
nc -V ...
-v
Have nc give more verbose output.
nc -v ...
-W
Terminate after receiving recvlimit packets from the network.
nc -W ...
-w
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.
nc -w ...
-X
Requests that nc should use the specified protocol 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.
nc -X ...
-x
Requests that nc should connect to destination using a proxy at proxy_address and port. If port is not specified, the well-known port for the proxy protocol is used (1080 for SOCKS, 3128 for HTTPS). An IPv6 address can be specified unambiguously byenclosing proxy_address in square brackets.
nc -x ...