Pcornel
Linux · Network Troubleshooting

nc / netcat

Cheat sheet · https://pcornel.dk/topic.php?topic=2794

Back to the Topic

Answer

nc (netcat) opens or listens on a TCP or UDP port and moves raw bytes. It answers one question quickly: can a connection to this address and port be made from here?

Remember

TCP gives a clear answer: succeeded, refused (nothing listening) or timed out (dropped on the way). UDP gives none — no reply can mean open or filtered. Option names differ between the OpenBSD and GNU/traditional versions; check nc -h.

First checks

  • nc -vz <host> <port> — TCP connect test.
  • nc -vz -w 3 <host> <port> — with a 3-second timeout.
  • nc -vzu <host> <port> — UDP probe (inconclusive without an answer).
  • nc -l <port> (OpenBSD) / nc -l -p <port> (traditional) — listen, to test from the other side.
  • ss -ltn on the server — is anything listening?

Verify in this order

name or address correct → route to the host → not dropped on the path → host firewall allows → something listens on the port → connection accepted

Where it usually breaks

First mismatch in link/interface → address/namespace → route/neighbor → firewall/policy → socket/daemon → DNS/TLS/SSH/application peer path; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2794

Confirmation

Confirm action

Continue?