Use it to test a port without the application, or to stand in for a server while testing a firewall rule.
nc / netcat
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?
1. nc -vz -w 3 <host> <port> from the client.
2. Succeeded → the network path and listener are fine; look at the application.
3. Refused → reached the host, nothing listens on that port.
4. Timed out → a firewall dropped it, or the host is down.
5. To test a firewall rule without the service: nc -l on the server port, then connect.
name or address correct → route to the host → not dropped on the path → host firewall allows → something listens on the port → connection accepted
For Network Troubleshooting → nc / netcat, continue with the first unproven Topic check: Record nc implementation/version, TCP/UDP mode, source address/namespace, destination address and exact port. If that boundary is healthy, advance to the adjacent check: For TCP, correlate connect/refused/timeout with ss and packet capture; for UDP, define an expected response or capture remote receipt. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
nc invocation → local socket/bind → route/neighbor/firewall/path → remote port/listener → TCP handshake or UDP datagram → optional response → higher-layer application test
Healthy evidence: the expected TCP handshake or defined UDP request/response occurs on the intended source/destination/port and packet evidence agrees with the observed result.
Step 2 Verification and output interpretation Verify boundary
Existing fast checks for this Topic. - Record nc implementation/version, TCP/UDP mode, source address/namespace, destination address and exact port.
- For TCP, correlate connect/refused/timeout with ss and packet capture; for UDP, define an expected response or capture remote receipt.
- Use the smallest payload required and avoid sending unsafe application data to production listeners.
- After transport evidence, move to the real client/protocol and repeat the original application transaction.
Verification chain. nc invocation → local socket/bind → route/neighbor/firewall/path → remote port/listener → TCP handshake or UDP datagram → optional response → higher-layer application test
Step 3 Commands Verify boundary
nc -zv host 443
nc -l 9000 # simple listener
nc -u -zv host 53
Step 4 Failure modes and next checks Narrow the fault
Suspicious evidence: timeout/refusal differs by source or family, UDP has no defined response, NAT/firewall rewrites the path unexpectedly, or nc succeeds while the real protocol fails.
netcat shows only the explicitly tested transport behavior within its protocol/source/destination/port scope, but it does not show application, TLS, authentication or persistent service health.
Step 5 Common mistakes Narrow the fault
- Concluding UDP is open because nc did not error.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
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.
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 -ltnon the server — is anything listening?
ReferenceWhat it is1 section · depth on demand
Core model
Use netcat as a bounded transport test. Pin implementation/options, source/destination/port and TCP versus UDP, then correlate exit behavior with socket state and packet capture. TCP connect success shows a handshake to a listener/path, but it does not show TLS, authentication or higher application correctness. UDP is especially non-conclusive without an expected response.
ReferenceImportant terms & boundaries5 sections · depth on demand
What this shows and what it does not
netcat shows only the explicitly tested transport behavior within its protocol/source/destination/port scope, but it does not show application, TLS, authentication or persistent service health.
In depth
netcat (nc): testing ports and talking to services
netcat opens TCP and UDP connections, and listens for them. It works as a universal client and server for testing. The OpenBSD nc(1) manual page describes the main uses:
-zchecks whether ports are listening without sending data, including ranges.-llistens, and-kkeeps listening after a connection ends.-uswitches to UDP. The manual notes that UDP scans with-uzalways report success, so they're mainly useful together with a packet capture.-wsets a timeout, and-Ncloses the socket at end of input.-xand-Xconnect through SOCKS or HTTP proxies.
Variants
Linux distributions ship different netcat implementations: OpenBSD nc (Debian netcat-openbsd), nmap's ncat (RHEL), and the older "traditional" netcat. Options differ between them, especially for listening (nc -l 8080 versus nc -l -p 8080). nc -h shows which one is installed.
Typical tasks
| Task | Command |
|---|---|
| Is a TCP port reachable? | nc -zv -w 3 db1 5432 |
| Several ports | nc -zv -w 2 srv1 22 80 443 |
| Read a service banner | nc -w 3 mail1 25 |
| Talk HTTP by hand | printf 'GET /health HTTP/1.1\r\nHost: api\r\nConnection: close\r\n\r\n' | nc api 8080 |
| Test the firewall from the other side | Server: nc -lk 9000; client: nc -zv server 9000 |
| Send a UDP test datagram | echo test | nc -u -w1 logs1 514 |
| Copy a file without SSH (trusted networks only) | Receiver: nc -l 9000 > file; sender: nc -N host 9000 < file |
Connection results and their meaning
| Result | Meaning |
|---|---|
succeeded / open | Something listens, and the path is open |
Connection refused | The host answered with RST: nothing listens there, or a firewall rejects |
| Timeout | No answer: a firewall drops, the host is down, or routing is broken |
No route to host | ICMP unreachable, or no route |
host$ nc -zv -w 3 db1.example.net 5432
Connection to db1.example.net (10.30.0.40) 5432 port [tcp/postgresql] succeeded!
host$ nc -zv -w 2 srv1 21-25 2>&1 | grep -E "succeeded|refused"
nc: connect to srv1 port 21 (tcp) failed: Connection refused
Connection to srv1 22 port [tcp/ssh] succeeded!
host$ nc -w 3 mail1.example.net 25
220 mail1.example.net ESMTP Postfix
host$ srv2$ nc -lk 9000
host$ nc -zv srv2 9000
Testing new firewall rules
The listener on srv2 opens port 9000 temporarily, without installing the real service. A successful test from the client then proves that routing and firewalls allow the traffic. Any remaining problem is in the service itself.
Documented example, not captured output.
How it works at runtime
nc / netcat is part of Network Troubleshooting → nc / netcat. nc / netcat is a lightweight Linux transport probe for opening or listening on TCP/UDP endpoints, moving raw bytes and testing basic socket reachability without adding application-protocol semantics.
Topic-specific state model. nc / netcat is a lightweight Linux transport probe for opening or listening on TCP/UDP endpoints, moving raw bytes and testing basic socket reachability without adding application-protocol semantics.
Interpretation rule. - TCP nc connect success ≠ application protocol healthy; it shows only a transport handshake to the tested endpoint.
- UDP nc success/exit ≠ remote service received data; connectionless sends can appear successful without response.
- Connection refused ≠ route failure; it often shows an active reject or no listener at the destination.
- nc syntax/options ≠ portable across implementations such as OpenBSD netcat, traditional nc or Ncat.
Quick reference
netcat (nc, ncat) tests TCP/UDP connectivity and moves data.
nc -zv 10.20.30.40 443 # TCP port check
nc -zvu 10.0.0.53 53 # UDP (unreliable result: no answer ≠ closed)
nc -l 9000 > received.tar # listener (ncat: -l -p 9000)
tar cf - /srv/data | nc 10.0.10.22 9000
echo -e 'GET / HTTP/1.0\r\nHost: app\r\n\r\n' | nc app.example.com 80
ncat --ssl app.example.com 443
Variants differ (OpenBSD nc on Debian/Ubuntu, Nmap ncat on RHEL) — flags like -p and -q vary. For quick TCP checks without nc: timeout 3 bash -c '</dev/tcp/10.20.30.40/443' && echo open.
Limits and how it fails
Primary failure point. netcat shows only the explicitly tested transport behavior within its protocol/source/destination/port scope, but it does not show application, TLS, authentication or persistent service health.
ReferenceConfiguration & state1 section · depth on demand
Configuration, persistence and lifecycle
Distribution/platform context. nc / netcat owns lightweight socket probing. Network Troubleshooting owns end-to-end fault isolation; application and TLS Topics own higher-layer protocol verification.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Network Troubleshooting → nc / netcat. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.kernel.org/networking/index.html · confidence 94%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
nc / netcat operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for nc / netcat.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | nc / netcat is a lightweight Linux transport probe for opening or listening on TCP/UDP endpoints, moving raw bytes and testing basic socket reachability without adding application-protocol semantics. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin exact host/namespace + original name or endpoint → capture link/address/route/resolver state → reproduce original failure → localize first failed resolver/network boundary → collect bounded packet/socket or DNS evidence → change one demonstrated cause → read back effective state → repeat original application transaction and an adjacent regression check. | Use the shortest evidence path first; a fast check is a boundary test, not blanket proof. |
| Verification chain | nc invocation → local socket/bind → route/neighbor/firewall/path → remote port/listener → TCP handshake or UDP datagram → optional response → higher-layer application test | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | netcat proves only the explicitly tested transport behavior within its protocol/source/destination/port scope; it does not prove application, TLS, authentication or persistent service health. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated Linux DNS/network evidence can establish this proof path: nc invocation → local socket/bind → route/neighbor/firewall/path → remote port/listener → TCP handshake or UDP datagram → optional response → higher-layer application test | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It does not independently prove behavior outside the captured host/network namespace, resolver path or DNS view, interface/source, destination/protocol/port, capture point, time or workload scope. netcat proves only the explicitly tested transport behavior within its protocol/source/destination/port scope; it does not prove application, TLS, authentication or persistent service health. | Do not promote a local success signal into end-to-end or adjacent-dependency proof. |
| Next troubleshooting check | Continue from the first unproven DNS/network boundary: preserve the original source and failure conditions, capture the adjacent resolver/socket/packet state, change only the demonstrated cause, then repeat the original application lookup or transaction and adjacent regression checks. | Continue to the next unresolved boundary while preserving the original test condition. |
nc / netcat · operational reference
Compact Linux state, persistence, verification and boundary reference for fast lookup.
| Reference boundary | nc / netcat |
|---|---|
| Topic path | Network Troubleshooting → nc / netcat |
| Runtime state | nc / netcat is a lightweight Linux transport probe for opening or listening on TCP/UDP endpoints, moving raw bytes and testing basic socket reachability without adding application-protocol semantics. |
| Fast checks | - Record nc implementation/version, TCP/UDP mode, source address/namespace, destination address and exact port. - For TCP, correlate connect/refused/timeout with ss and packet capture; for UDP, define an expected response or capture remote receipt. - Use the smallest payload required and avoid sending unsafe application data to production listeners. - After transport proof, move to the real client/protocol and repeat the original application transaction. |
| Verification chain | nc invocation → local socket/bind → route/neighbor/firewall/path → remote port/listener → TCP handshake or UDP datagram → optional response → higher-layer application test Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary. |
| Failure boundary | netcat proves only the explicitly tested transport behavior within its protocol/source/destination/port scope; it does not prove application, TLS, authentication or persistent service health. Boundary chain: process/socket namespace → source/rule/FIB → neighbor → netfilter/eBPF/qdisc → virtual/physical device → peer → return → application. |
| Persistence rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |