GNU netcat (nc) Cheatsheet
#
netcat
, or nc
, is a versatile networking tool used for reading from and writing to network connections using TCP or UDP.
Basic Usage
#
Command/Option | Example | Description |
---|
nc -l -p port | nc -l -p 1234 | Listen on port 1234 |
nc host port | nc example.com 80 | Connect to port 80 on example.com |
nc -u host port | nc -u example.com 1234 | Use UDP to connect to port 1234 on example.com |
Advanced Usage
#
Command/Option | Example | Description |
---|
nc -zv host port1-port2 | nc -zv example.com 20-80 | Scan ports 20 through 80 on example.com |
nc -l -p port -e /path/to/program | nc -l -p 1234 -e /bin/bash | Bind a shell to port 1234 |
nc -l -p port -c 'command' | nc -l -p 1234 -c 'ls -la' | Execute ls -la and send output over port 1234 |
Security and Monitoring
#
Command/Option | Example | Description |
---|
nc -v -w 5 host port | nc -v -w 5 example.com 80 | Connect to example.com on port 80 with a 5-second timeout |
nc -l -p port -k | nc -l -p 1234 -k | Keep listening for connections after handling one |
This cheatsheet covers essential netcat
(nc) commands and options for GNU systems.