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

  • -z

    Only checks whether the port is open, without sending data.

  • -v

    Shows detailed connection information.

  • -l

    Listens for incoming connections instead of connecting.

  • -u

    Uses UDP instead of TCP.

  • -w segundos

    Maximum time to wait for the connection.

  • -k

    With -l, keeps listening after a connection closes.

  • -n

    Does not resolve names: uses only IP addresses.

Usage examples

  • nc -zv localhost 22

    Checks whether port 22 on the machine itself is open.

  • nc -zv 192.168.1.10 20-25

    Checks a range of ports on another host.

  • nc -l 1234

    Opens a test server on port 1234.

  • echo "hola" | nc -w 1 localhost 1234

    Sends 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.

Related commands