Home·Terminal commands

nc (netcat)

Networking

Usage

nc [-lv] <host> <port>

Opens a raw TCP or UDP connection to see whether a port answers, and pipes bytes between two machines; three incompatible netcats share the name (OpenBSD, GNU, Nmap ncat), so `-z` or `-p` may simply not exist on yours.

Common flags

FlagMeaning
-lListen instead of connecting. On GNU netcat you also need -p <port>.
-vSay what happened, which is the whole point when testing a port.
-zScan without sending data. OpenBSD/macOS nc only; GNU netcat has no -z.
-w 3Give up after three seconds instead of hanging.
-uUDP instead of TCP.
-4 / -6Force one address family.

Examples

nc -zv example.com 443

Is the port open? Works on macOS and OpenBSD netcat.

nc -l 1234 # then on the other host: nc <host> 1234

A raw two-way pipe for a quick test.

nc -l 1234 > incoming.bin

Receive a file that the other side sends with nc host 1234 < file.

When a connection fails, these narrow down how far it got — name not resolving, no route, or a blocked port.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does nc (netcat) do?

Opens a raw TCP or UDP connection to see whether a port answers, and pipes bytes between two machines; three incompatible netcats share the name (OpenBSD, GNU, Nmap ncat), so `-z` or `-p` may simply not exist on yours.

Q. How do I type it?

nc [-lv] <host> <port> — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

6 are listed here; the full set is in man nc. This command sits under Networking.

Related commands

man page: man nc-(netcat)