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
| Flag | Meaning |
|---|---|
| -l | Listen instead of connecting. On GNU netcat you also need -p <port>. |
| -v | Say what happened, which is the whole point when testing a port. |
| -z | Scan without sending data. OpenBSD/macOS nc only; GNU netcat has no -z. |
| -w 3 | Give up after three seconds instead of hanging. |
| -u | UDP instead of TCP. |
| -4 / -6 | Force one address family. |
Examples
nc -zv example.com 443Is the port open? Works on macOS and OpenBSD netcat.
nc -l 1234 # then on the other host: nc <host> 1234A raw two-way pipe for a quick test.
nc -l 1234 > incoming.binReceive 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)