When to use nc
Use nc for a focused TCP connection check when a service appears unreachable. A successful connection proves only that a TCP endpoint accepted a connection, not that SSH authentication or the application protocol works.
Syntax
nc [PARAMETERS] NODE PORTSquare brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.
Common options and arguments
Usage examples
Check your SSH port
nc -vz -w 3 server.example.com 22A bounded TCP connection attempt checks the server's SSH port without starting an authenticated SSH session.
Check your HTTPS port
nc -vz -w 3 server.example.com 443The same style of check targets HTTPS connectivity.
View local help
nc -hThe local implementation's help is displayed; nc variants have different options.
Notes and limitations
- The examples are designed for the common Linux versions of netcat; OpenBSD nc, traditional nc and Ncat are different.
- A successful TCP connect verifies the port, but not the correctness of the application protocol. Check only allowed nodes.
Common questions and troubleshooting
Why is the port reachable but SSH still fails?
Authentication, host-key verification, protocol negotiation or server policy can fail after TCP connects. Inspect the actual SSH error next.
Can these flags be copied to every nc version?
No. OpenBSD, traditional and other variants differ. Confirm the local help before scripting timeouts or listening behaviour.
Further help
Options vary by version and distribution. Check the installed documentation with this command: man nc.