Netcat Command-Line Cheat Sheet

Photo by Mikhail Nilov on Pexels
Published 22 March 2024 Last updated 15 April 2024 An older guide that hasn't been re-checked yet, so commands or versions may have moved on. How guides are made and checked

This cheat sheet is designed to briefly reference some of the most commonly used Netcat commands, along with a brief description and practical examples to illustrate their use. Whether you’re a seasoned professional looking to brush up on your command-line skills or a newcomer eager to explore the possibilities of networking through Netcat, you’ll find valuable insights and shortcuts here.

Installation:

DistributionCommand
Debian, Ubuntusudo apt-get install netcat
CentOS/Fedora/Red Hatsudo dnf install nc
NixOSnix-shell -p netcat-gnu for a temporary installation environment.

Usage:

TaskCommand
Listen on a portnc -l 1234
Connect to a portnc example.com 1234
Transfer files (Receiver)nc -l 1234 > file.txt
Transfer files (Sender)nc example.com 1234 < file.txt
Chat servernc -l 1234
Chat clientnc example.com 1234
Port scanningnc -zv example.com 20-30
File transfer with tar (Sender)`tar cf - .
File transfer with tar (Receiver)`nc -l 1234
Execute command upon connectionnc -l 1234 -e /bin/bash
Connect via UDPnc -u example.com 1234
Verbose outputnc -v example.com 1234
Listen with specific source IPnc -l 1234 -s 10.0.0.1
Send a text message to a portnc -lk 1234
Use with IPv6nc -6 example.com 1234
Bind to a specific local port (client)nc -p 8080 example.com 1234
Transfer directory with tar and netcat (Sender)`tar czf - directory/
Transfer directory with tar and netcat (Receiver)`nc -l 1234
Test if the port is open`echo “Hello World”
Receive file and print on consolenc -l 1234 > /dev/stdout
Test if port is open`echo -n
Use custom timeoutnc -w 10 example.com 1234
Proxy with Netcat`nc -l 1234
Create a simple HTTP server`echo -e “HTTP/1.1 200 OK\r\n\r\nHello World”
Send file with UDP (Sender)nc -u example.com 1234 < file.txt
Receive file with UDP (Receiver)nc -ul 1234 > file.txt
Check mail server (SMTP) interactionnc -C example.com 25
Echo service emulationnc -l 1234 -c 'xargs -n1 echo'
Listen on multiple ports (using -k for persistent listening and a loop)`echo -n “example.com”
Test if the port is openwhile true; do nc -lk 1234; done

This Netcat cheat sheet has highlighted the tool’s flexibility and power for everything from simple tasks to advanced operations. Mastering Netcat can significantly boost your networking skills. Keep practising, exploring further resources, and share your findings to deepen your understanding and contribute to the community’s collective knowledge.

You May Also Be Interested In