The netcat Command: Test TCP and UDP Ports Like a Network Multitool

Run a Speed Test

netcat is the pocketknife of networking tools. It can connect to ports, listen on ports, send text, and quickly prove whether a firewall or service is reachable.

Installation and Variants

OS / DistributionCommandDefault VariantInstall If Missing
macOSncBSD netcat (built-in)Pre-installed
Ubuntu / Debiannc or netcatOpenBSD netcatapt install netcat-openbsd
CentOS / RHELncncat (from nmap)yum install nmap-ncat
Arch LinuxncOpenBSD netcatpacman -S openbsd-netcat
Windowsncat.exeNot built-inInstall nmap (includes ncat)

Flag Reference

FlagMeaningExample
-vVerbose output — shows connection statusnc -v host 443
-zZero-I/O mode — scan without sending datanc -vz host 22
-uUDP mode instead of TCPnc -u host 53
-lListen mode — accept incoming connectionsnc -l 9000
-wTimeout in secondsnc -w 3 host 443
-nNo DNS resolution — use numeric addresses onlync -vn 1.1.1.1 80
-pSpecify source portnc -p 12345 host 80
-kKeep listening after client disconnects (ncat)ncat -lk 9000

Common TCP Port Tests

# Test HTTPS reachability
nc -vz example.com 443

# Test SSH on a remote server
nc -vz 192.168.1.10 22

# Test SMTP with a 5-second timeout
nc -w 5 mail.example.com 25

# Test a local service without DNS
nc -vn 127.0.0.1 8080

-v prints the connection result. -z closes immediately without sending data — useful for port scanning without triggering application behavior.

Two-Machine LAN / VPN Connectivity Test

To verify two machines can reach each other on a specific port — useful for testing VPN tunnels, port forwards, and firewall rules:

# On the server machine (listen on port 9000):
nc -l 9000

# On the client machine (connect):
nc server-ip 9000

# Type in either terminal — text appears on the other side.
# If the connection fails, a firewall or routing rule is blocking it.

Rough Throughput Test

Netcat can measure raw TCP throughput between two hosts — useful when you need a quick LAN bandwidth check without installing iperf:

# Server side:
nc -l 9000 > /dev/null

# Client side (send 100MB of zeros, time it):
dd if=/dev/zero bs=1M count=100 | nc server-ip 9000

Divide 100 MB by elapsed seconds to estimate throughput. This is a rough measure — iperf is more accurate for real measurements.

UDP Testing Caveat

UDP has no connection handshake. nc -uz host 53 sends a packet and waits for a response, but no response does not prove the port is closed — the host may simply not send a UDP reply to empty probes. Interpret UDP test results with application logs or packet capture when the answer matters.

Common Port Reference

PortServiceProtocolTest Command
22SSHTCPnc -vz host 22
25SMTPTCPnc -w 5 host 25
80HTTPTCPnc -vz host 80
443HTTPSTCPnc -vz host 443
3389RDPTCPnc -vz host 3389
5900VNCTCPnc -vz host 5900
53DNSUDPnc -uz host 53

Security Note

Do not leave netcat listeners running after testing. A listening nc accepts connections from any source that can reach the port. Some netcat variants support -e (execute) which can expose a shell — never use -e on a production system. Treat netcat as a temporary diagnostic tool: open it, test, close it.

Frequently Asked Questions

Is netcat installed by default?

On macOS and most Linux distributions, yes — though the variant differs. The command is usually nc. On Windows, it is not built-in; install nmap which includes ncat, or download a standalone binary. Check with nc --version or which nc.

Can netcat test UDP ports?

Yes with -u, but UDP test results are harder to interpret than TCP because there is no connection handshake. A successful UDP probe only means a packet was sent — no response can mean the port is closed, the host dropped the probe, or the service does not reply to empty UDP packets. Use protocol-specific tools (like dig for DNS) when UDP confirmation matters.

Is netcat dangerous?

In diagnostic use, no. The risk is leaving listeners open — they accept any connection on that port. Some versions also support -e to execute a program on connect, which is how netcat is abused. Use it for testing, close it when done, and avoid -e entirely.

What is the difference between nc, netcat, and ncat?

They are different implementations with similar but not identical flag sets. BSD netcat (macOS default) and OpenBSD netcat (common on Ubuntu) are close but differ on some flags. Ncat (from nmap) adds SSL support and more options. Most basic diagnostic use works the same across all three.

Related Guides

More From This Section