Linux nc Command: Test TCP and UDP Connections
nc (Netcat) is a versatile tool that opens or listens to TCP/UDP connections to send and receive data. It is also used to quickly check if a port on an authorized host is accessible.
What is the nc command?
Linux distributions may have different implementations, such as OpenBSD netcat or Nmap Ncat, installed under the name nc. The -z option checks whether a connection is possible without sending data, and -v displays diagnostic messages. Some options and listening mode syntax differ between implementations.
Basic syntax
nc [options] host port
The installed implementation and options may vary depending on the distribution. Check the description for your current system with man nc.
Examples
Checking local SSH port
Check if your computer's TCP port 22 is accepting connections.
nc -vz 127.0.0.1 22
Connection timeout
Limit so as not to wait too long on an unresponsive local port.
nc -w 3 -vz 127.0.0.1 80
Direct connection
Observe the data sent by services on your own computer. Exit with Ctrl+C.
nc -v 127.0.0.1 22
Interpreting Port Connection Test Results
nc -vz allows you to simply check whether a TCP port can be connected without sending or receiving data. Supported options and output messages vary depending on the netcat implementation.
nc -vz example.com 443
Example output when the connection is successful:
Connection to example.com 443 port [tcp/https] succeeded!
A successful connection only means that the port accepted a TCP connection; it does not mean that the TLS certificate or HTTP response is valid. If there is a timeout, check the firewall, route, or server waiting status; if it is immediately refused, check whether the target is not accepting connections. Only send test packets to authorized targets.
Main Options and Format
| Options/Format | Description |
|---|---|
-z |
Check connectivity without sending data. |
-v |
Display diagnostic output in detail. |
-w seconds |
Set connection and I/O timeouts. The meaning may vary depending on the implementation. |
-u |
Use in UDP mode. |
-l |
Receive mode that waits for a connection. Check the syntax according to the implementation. |
Precautions when using
A port being open does not guarantee that the application is working correctly or that authentication is secure. UDP -z results are especially difficult to interpret due to the lack of response. Only check external hosts with the owner's permission. Use nc -h to check the options available in the current implementation.
Frequently Asked Questions
Are nc and ncat the same tool?
Both are Netcat derivatives, but their implementations may differ. Check the installed package and the output of nc -h to distinguish the options.
Official Documentation
You can check the exact behavior of the options and the differences between implementations in the official documentation for nc.









