nc -vz -w 2 host 443Check whether a TCP port is open.
When to use it
Use nc to check reachability of a port, to stand in for a server or client while debugging, or to move data between two machines on a trusted network without setting up anything else.
Steps
Test a port
The most common use.nc -vz -w 2 192.168.1.10 22Scan a small range
Ranges work in macOS nc.nc -vz -w 1 192.168.1.10 20-25Listen on a port
On one Mac, listen; on another, connect to it. Whatever you type appears on the other side.nc -l 9000Transfer a file on a trusted network
Receiver:nc -l 9000 > file.zip. Sender:nc receiver-ip 9000 < file.zip. Data isn't encrypted, so use scp outside your own network.Check a UDP service
UDP has no handshake, so results are less certain.nc -vzu 1.1.1.1 53
Output explained
Connection to 127.0.0.1 port 4321 [tcp/rwhois] succeeded!
nc: connectx to 127.0.0.1 port 4322 (tcp) failed: Connection refused
The name in brackets is the port's registered service, not necessarily what's running: here a web dev server happens to use 4321.
Options and variations
| Flag | Meaning | Example |
|---|---|---|
| -z | Scan without sending data | nc -z host 80 |
| -v | Verbose | nc -vz host 80 |
| -w N | Timeout | nc -w 2 host 80 |
| -l | Listen mode | nc -l 9000 |
| -u | UDP | nc -u host 53 |
| -k | Keep listening after a client disconnects | nc -lk 9000 |
| -G N | TCP connection timeout (macOS) | nc -G 3 -vz host 443 |
Common errors
| Error | Cause | Fix |
|---|---|---|
| nc: Address already in use | Another process holds the port | Pick another port, or find the process with lsof. |
| Listener unreachable from another machine | macOS firewall blocks nc | Allow it when prompted, or test on loopback first. |
Do it in the app
While nc listens, LightAtom's Ports view shows it as an open port, owned by nc, reachable from the network.
Frequently asked questions
Is netcat installed on a Mac?
Yes, as nc. macOS's version is based on OpenBSD netcat with Apple additions such as -G for the connection timeout.
How do I check if a port is open with nc?
nc -vz -w 2 host port. It prints “succeeded” for open ports and “Connection refused” for closed ones.
Can nc transfer files securely?
No, nc sends data unencrypted. It's fine on your own network for testing; use scp or rsync over SSH otherwise.