Skip to main content

Netcat Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for using the Netcat nc command to test ports, listen for connections, transfer files, and send raw network requests

The `nc` command reads and writes data over TCP and UDP network connections. This cheatsheet covers common Netcat commands for port checks, listeners, file transfers, timeouts, and basic troubleshooting.

Basic Syntax

Core nc command forms.

CommandDescription
nc host portOpen a TCP connection
nc -u host portOpen a UDP connection
nc -l portListen on a local port
nc -hShow help and options
man ncRead the local Netcat manual

Connect and Listen

Create simple client and server connections.

CommandDescription
nc example.com 80Connect to TCP port 80
nc -l 5555Listen on port 5555
nc server.example.com 5555Connect to a listening host
nc -v host 22Connect with verbose output
nc -n 192.168.1.10 22Skip DNS lookups

Port Checks

Check whether TCP ports are open.

CommandDescription
nc -z -v host 22Check one TCP port
nc -z -v host 20-80Check a port range
nc -z -v host 80 443Check selected ports
nc -z -w 3 host 443Check with a timeout
nmap hostUse Nmap for deeper scans

UDP

Use UDP instead of TCP.

CommandDescription
nc -u host 53Connect to a UDP service
nc -u -l 5555Listen for UDP datagrams
nc -z -v -u host 53Check a UDP port
nc -u -w 3 host 123UDP check with timeout
nc -u 192.168.1.10 5555Send text to a UDP listener

File Transfers

Send files between two hosts.

CommandDescription
nc -l 5555 > fileReceive a file
nc host 5555 < fileSend a file
nc -l 5555 | tar xzvf -Receive and extract a directory
tar czvf - dir | nc host 5555Archive and send a directory
nc -w 5 host 5555 < fileSend with a timeout

HTTP and Raw Requests

Send plain text requests to network services.

CommandDescription
printf "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" | nc example.com 80Send an HTTP request
echo "QUIT" | nc mail.example.com 25Send a simple SMTP command
echo "PING" | nc host 5555Send text to a listener
nc host 80Type a request manually
curl http://example.comUse curl for HTTP work

Timeouts and Persistent Listeners

Control how long Netcat waits and whether it keeps listening.

CommandDescription
nc -w 5 host 80Timeout after 5 seconds
nc -k -l 5555Keep listening after disconnect
nc -v -w 3 host 22Verbose connection with timeout
nc -l 8080 < index.htmlServe one file on port 8080
while true; do nc -l 8080 < index.html; doneServe the file repeatedly

Troubleshooting

Quick checks for common Netcat issues.

IssueCheck
nc: command not foundInstall netcat-openbsd, netcat-traditional, or nmap-ncat
Connection refusedConfirm the remote service is running and listening on that port
Command hangsAdd -w to set a timeout
UDP result is unclearUDP has no TCP-style handshake, use Nmap for reliable scans
Option behaves differentlyRun man nc and check the Netcat implementation on that system

Use these guides for broader networking workflows.

GuideDescription
Netcat Command in LinuxFull Netcat guide with examples
Nmap Command in LinuxScan hosts and ports in more detail
curl cheatsheetWork with HTTP requests and APIs
tcpdump cheatsheetCapture and inspect network packets
ss Command in LinuxInspect sockets and listening services