nc
Linux · Network · reference only
What it does
Netcat: opens TCP and UDP connections from the command line. It is used to test ports, send data and set up simple servers.
Syntax
nc [opciones] equipo puerto nc -l [opciones] puerto
Options and parameters
-zOnly checks whether the port is open, without sending data.
-vShows detailed connection information.
-lListens for incoming connections instead of connecting.
-uUses UDP instead of TCP.
-w segundosMaximum time to wait for the connection.
-kWith -l, keeps listening after a connection closes.
-nDoes not resolve names: uses only IP addresses.
Usage examples
nc -zv localhost 22Checks whether port 22 on the machine itself is open.
nc -zv 192.168.1.10 20-25Checks a range of ports on another host.
nc -l 1234Opens a test server on port 1234.
echo "hola" | nc -w 1 localhost 1234Sends the text hola to a server listening on port 1234.
Notes and common mistakes
- There are several netcat variants and not all accept the same options; on Debian the netcat-openbsd package is recommended.
- Only test ports on hosts you own or have permission for.