netcat Cheatsheet - Network Debugging
The most common netcat workflow is confirming reachability without any listening service — `nc -zv host port` returns cleanly per port and `-w` stops it hanging on a black-hole drop. Pair that with `-l` to build a one-shot listener and the -z/-v/-w flags to bound each probe, and most "is it open / does it respond" questions settle in one line.
Connectivity Test & Port Scan 6
nc -zv host 80Check if port 80 is open (most common)
nc -zv host 80 443 8080Check multiple specified ports
nc -zv host 1-1000Scan ports 1-1000
nc -vz -w 2 host 80Port check with a 2-second timeout
nc -uz host 8080UDP mode port check
nc -4 host 80Force IPv4 connection
File & Data Transfer 6
nc -l 9999 > received.txtReceiver: listen and save to a file
nc host 9999 < file.txtSender: send a file
tar czf - dir | nc host 9999Sender: package and send a directory
nc -l 9999 | tar xzf -Receiver: receive and extract
dd if=/dev/sda | nc host 9999Sender: transfer a disk image
nc host 9999 | pv > disk.imgReceiver: receive image with a progress bar (needs pv)
Port Listening 5
nc -l 8080Listen on local port 8080 for connections
nc -l -p 8080Listen (old nc syntax, needs -p)
nc -l -k 8080Keep listening, accept multiple connections (BSD)
nc -lk 8080Same as above, combined form
nc -lu 9090Listen on a UDP port
Proxy & Forwarding 3
nc -l 1234 | nc target 80Simple TCP proxy/forward
mkfifo pipe; nc -lk 8080 < pipe | nc target 80 > pipeBidirectional port forward (pipe method)
nc -l 1234 -e /bin/bashBind a shell to a port (GNU nc; authorized testing only)
Banner Grab & Protocol Debug 5
echo "" | nc host 22Grab the SSH service version
echo "" | nc host 25Grab the SMTP service banner
printf "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" | nc example.com 80Send a raw HTTP request
echo -e "GET / HTTP/1.0\r\n\r\n" | nc example.com 80View HTTP response headers
nc host 3306Grab the MySQL service banner
Advanced Options & Flags 7
-v / -vvVerbose / more verbose output
-zZero-I/O mode: scan only, send no data
-w 22-second connection timeout
-kKeep listening, accept multiple connections (BSD)
-s 192.168.1.1Specify the source IP address
-p 12345Specify the local source port
-uUse the UDP protocol
Alternatives & Comparison 4
ncat host 80Nmap's ncat; supports SSL and access control
ncat --ssl host 443ncat encrypted connection, replaces plain nc
socat - TCP:host:80socat: a more powerful alternative, more protocols
nc --versionCheck nc version (BSD/GNU/OpenBSD)
Tips
- macOS ships BSD nc, whose flags differ from GNU ncat — take care when troubleshooting.
- Port scanning is only for authorized network checks; unauthorized scanning is a violation.
- nc transfers are unencrypted; don't send sensitive data directly — use SSH or TLS.
- OpenBSD nc lacks -e; use ncat or socat when you need to bind a shell.
- For large files, show progress on the sender with pv file.txt | nc host 9999.
- For port forwarding, prefer socat or ncat — more complete and with persistent connections.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us