Netcat Cheatsheet
Basic Syntax
Core nc command forms.
| Command | Description |
|---|---|
nc host port |
Open a TCP connection |
nc -u host port |
Open a UDP connection |
nc -l port |
Listen on a local port |
nc -h |
Show help and options |
man nc |
Read the local Netcat manual |
Connect and Listen
Create simple client and server connections.
| Command | Description |
|---|---|
nc example.com 80
|
Connect to TCP port 80 |
nc -l 5555 |
Listen on port 5555 |
nc server.example.com 5555 |
Connect to a listening host |
nc -v host 22 |
Connect with verbose output |
nc -n 192.168.1.10 22 |
Skip DNS lookups |
Port Checks
Check whether TCP ports are open.
| Command | Description |
|---|---|
nc -z -v host 22 |
Check one TCP port |
nc -z -v host 20-80 |
Check a port range |
nc -z -v host 80 443 |
Check selected ports |
nc -z -w 3 host 443 |
Check with a timeout |
nmap host
|
Use Nmap for deeper scans |
UDP
Use UDP instead of TCP.
| Command | Description |
|---|---|
nc -u host 53 |
Connect to a UDP service |
nc -u -l 5555 |
Listen for UDP datagrams |
nc -z -v -u host 53 |
Check a UDP port |
nc -u -w 3 host 123 |
UDP check with timeout |
nc -u 192.168.1.10 5555 |
Send text to a UDP listener |
File Transfers
Send files between two hosts.
| Command | Description |
|---|---|
nc -l 5555 > file |
Receive a file |
nc host 5555 < file |
Send a file |
nc -l 5555 | tar xzvf - |
Receive and extract a directory |
tar czvf - dir | nc host 5555 |
Archive and send a directory |
nc -w 5 host 5555 < file |
Send with a timeout |
HTTP and Raw Requests
Send plain text requests to network services.
| Command | Description |
|---|---|
printf "GET / HTTP/1.1rnHost: example.comrnrn" | nc example.com 80 |
Send an HTTP request |
echo "QUIT" | nc mail.example.com 25 |
Send a simple SMTP command |
echo "PING" | nc host 5555 |
Send text to a listener |
nc host 80 |
Type a request manually |
curl http://example.com
|
Use curl for HTTP work |
Timeouts and Persistent Listeners
Control how long Netcat waits and whether it keeps listening.
| Command | Description |
|---|---|
nc -w 5 host 80 |
Timeout after 5 seconds |
nc -k -l 5555 |
Keep listening after disconnect |
nc -v -w 3 host 22 |
Verbose connection with timeout |
nc -l 8080 < index.html |
Serve one file on port 8080 |
while true; do nc -l 8080 < index.html; done |
Serve the file repeatedly |
Troubleshooting
Quick checks for common Netcat issues.
| Issue | Check |
|---|---|
nc: command not found |
Install netcat-openbsd, netcat-traditional, or nmap-ncat |
| Connection refused | Confirm the remote service is running and listening on that port |
| Command hangs | Add -w to set a timeout |
| UDP result is unclear | UDP has no TCP-style handshake, use Nmap for reliable scans |
| Option behaves differently | Run man nc and check the Netcat implementation on that system |
Related Guides
Use these guides for broader networking workflows.
| Guide | Description |
|---|---|
| Netcat Command in Linux | Full Netcat guide with examples |
| Nmap Command in Linux | Scan hosts and ports in more detail |
| curl cheatsheet | Work with HTTP requests and APIs |
| tcpdump cheatsheet | Capture and inspect network packets |
| ss Command in Linux | Inspect sockets and listening services |




