Quick take: The nc (netcat) command reads and writes data across network connections. Test a port with nc -zv host 443, listen with nc -l 1234, and connect with nc host 1234. It is the “TCP/IP Swiss army knife”.
Introduction
The nc command, short for netcat, is a versatile networking utility for reading from and writing to network connections. Administrators use it to check whether a port is open, transfer files quickly between machines, and probe services by hand — all from the terminal. It is a legitimate diagnostic tool found on most systems.
This guide covers testing ports, running a listener and client, and transferring data between two machines.
Syntax
The basic syntax of the netcat (nc) command is:
nc [OPTIONS] HOST PORT
nc -l [OPTIONS] PORTCommon Options and Parameters
The most useful options and parameters for the netcat (nc) command:
| Option | Description |
|---|---|
| -z | Zero-I/O mode — scan for a listening port without sending data. |
| -v | Verbose — report connection success or failure. |
| -l | Listen mode — wait for an incoming connection. |
| -p PORT | Specify the source/local port. |
| -u | Use UDP instead of TCP. |
| -w SECS | Timeout for connects and final reads. |
| -n | Do not resolve hostnames (numeric only). |
Practical Examples
Real netcat (nc) commands you can run today:
# Test whether a port is open
nc -zv example.com 443
# Scan a small range of ports
nc -zv example.com 20-25
# Start a simple listener
nc -l 1234
# Connect to that listener from another machine
nc server-ip 1234
# Send a file (receiver listens, sender connects)
nc -l 1234 > received.tar # receiver
# ...and the sender side
nc server-ip 1234 < file.tar # senderTips and Best Practices
nc -zv host portis the fastest way to confirm a service is reachable on a port — clearer than telnet.- For file transfer, start the receiving
nc -llistener first, then connect the sender; the transfer ends when the connection closes. - Implementations differ (traditional vs OpenBSD netcat); check
man ncif a flag behaves unexpectedly on your system.
Final Thoughts
nc (netcat) is a compact, powerful tool for any task involving a raw network connection — port testing, quick file transfers, and hands-on service debugging. Learn -zv for port checks and the listener/client pattern, and it becomes an everyday companion to ss and ping for diagnosing connectivity from the command line.
FAQ: netcat (nc) Command in Linux
How do I check if a port is open with netcat?+
Use nc -zv host port, for example nc -zv example.com 443. The -z scans without sending data and -v reports whether the connection succeeded.
How do I transfer a file with netcat?+
Start a listener on the receiver (nc -l 1234 > out.file), then connect from the sender (nc receiver-ip 1234 < in.file). The transfer completes when the connection closes.
What is netcat used for?+
netcat reads and writes data over TCP or UDP connections. Common uses are testing whether ports are open, transferring files, running quick listeners, and manually probing network services for troubleshooting.
What is the difference between nc -z and a full connection?+
nc -z only checks whether the port accepts a connection and then closes it, without exchanging data. A normal nc connection stays open so you can send and receive data interactively.
Why does nc behave differently on my system?+
There are several netcat implementations (traditional GNU and OpenBSD versions) with slightly different flags. Run man nc to confirm the options available on your machine.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support