nc Command
Advanced Networking man(1)Networking utility for reading/writing across network connections
๐ 119 views
๐
Updated: Apr 29, 2026
SYNTAX
nc [OPTION]... [HOST] [PORT]
What Does nc Do?
nc (netcat) is a versatile networking utility that reads and writes data across network connections. It can create TCP/UDP connections, listen for connections, port scan, transfer files, and serve as a network debugging tool.
nc is often called the "Swiss Army knife" of networking. It can function as a simple client or server for any protocol, making it invaluable for testing, debugging, and ad-hoc data transfer.
nc is commonly used for port checking, quick file transfers, network chat, and as a building block in shell scripts for network operations.
nc is often called the "Swiss Army knife" of networking. It can function as a simple client or server for any protocol, making it invaluable for testing, debugging, and ad-hoc data transfer.
nc is commonly used for port checking, quick file transfers, network chat, and as a building block in shell scripts for network operations.
Options & Flags
| Option | Description | Example |
|---|---|---|
| -l | Listen mode (server) | nc -l 8080 |
| -v | Verbose output | nc -v example.com 80 |
| -z | Scan mode (zero I/O, for port scanning) | nc -zv example.com 80 |
| -w | Timeout in seconds | nc -w 3 example.com 80 |
| -u | UDP mode | nc -u example.com 53 |
| -k | Keep listening after client disconnects | nc -lk 8080 |
Practical Examples
#1 Check if port is open
Tests if port 443 is open on the remote host.
$ nc -zv example.com 443
Output:
Connection to example.com 443 port [tcp/https] succeeded!
#2 Scan port range
Scans ports 20-25 on the remote host.
$ nc -zv example.com 20-25#3 Simple chat server
Listens on port 9000 โ anything typed on the other end appears here.
$ nc -l 9000#4 Connect to chat
Connects to the listening nc and enables text exchange.
$ nc hostname 9000#5 File transfer (receiver)
Receives a file on port 9000.
$ nc -l 9000 > received_file.tar.gz#6 File transfer (sender)
Sends a file to the receiving nc.
$ nc hostname 9000 < file.tar.gz#7 HTTP request
Sends a raw HTTP request โ useful for debugging web servers.
$ echo -e "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" | nc example.com 80#8 Port check in script
Checks if PostgreSQL is reachable with a 3-second timeout.
$ nc -zw3 db-server 5432 && echo "PostgreSQL up" || echo "PostgreSQL down"Tips & Best Practices
Quick port check: nc -zv host port is the fastest way to test if a remote port is open. Faster and simpler than telnet.
ncat vs nc variants: There are several nc variants: GNU netcat, OpenBSD netcat, ncat (from nmap). Options vary. Check nc -h for your version.
Security tool: nc can create reverse shells and transfer data. It is a legitimate admin tool but can be used maliciously โ use responsibly.
Frequently Asked Questions
How do I check if a port is open?
nc -zv hostname port. It reports success or failure. Add -w 3 for a 3-second timeout.
How do I transfer a file with nc?
Receiver: nc -l 9000 > file. Sender: nc hostname 9000 < file. Simple and fast for quick transfers.
What is netcat used for?
Port checking, network debugging, file transfer, banner grabbing, and as a lightweight TCP/UDP client/server.
Related Commands
More Networking Commands
Download Networking Cheat Sheet
View all 31 Linux command cheat sheets โMaster Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books โ