nc(1)
Read and write data across network connections using TCP or UDP.
Synopsis
nc [OPTION]... [hostname] [port]Description
nc (netcat) is a versatile networking utility for reading from and writing to network connections. It can operate as a server listening on a port or as a client connecting to remote hosts, supporting both TCP and UDP protocols.
Common uses include port scanning, transferring files, banner grabbing, debugging network services, and creating simple chat or remote shell applications. It reads from stdin and writes to stdout, making it highly composable with other Unix tools via pipes.
Common options
| Flag | What it does |
|---|---|
-l | Listen mode; create a listening socket (server) |
-p port | Specify local port to bind to (listen mode) or source port (client mode) |
-u | Use UDP instead of TCP (default is TCP) |
-v | Verbose output; print connection details and diagnostic info |
-n | Do not perform DNS lookups; use only numeric IP addresses |
-w timeout | Set timeout in seconds for connections and idle data |
-z | Scan mode; do not send data, only check if port is open |
-e program | Execute program after connection is established (some systems only) |
-q seconds | Exit after specified seconds of EOF on stdin |
-4 | Force IPv4 connections only |
-6 | Force IPv6 connections only |
Examples
Listen on port 8000 for incoming connections; useful for receiving data or testing clients
nc -l 8000Connect to example.com on port 80; can then type HTTP requests manually or pipe them in
nc example.com 80Scan ports 1-1000 on example.com to find open ports (port scan)
nc -zv example.com 1-1000Send a single message to a remote host on port 9000 and close connection
echo 'Hello' | nc example.com 9000Listen on port 5000 and send the contents of file.txt to any connecting client
nc -l 5000 < file.txtListen on port 5000 and extract a gzipped tar archive received from a remote sender
nc -l 5000 | tar xzf -Listen on port 5353 using UDP protocol instead of TCP
nc -u -l 5353Connect to example.com port 22 with verbose output and 5-second timeout; useful for SSH banner grabbing
nc -v -w 5 example.com 22