Netcat Command-Line Cheat Sheet

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 - . | nc -w 3 example.com 1234
File transfer with tar (Receiver)nc -l 1234 | tar x
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/ | nc -w 3 example.com 1234
Transfer directory with tar and netcat (Receiver)nc -l 1234 | tar xzf -
Test if the port is openecho "Hello World" | nc example.com 1234
Receive file and print on consolenc -l 1234 > /dev/stdout
Test if port is openecho -n | nc -w 1 example.com 1234
Use custom timeoutnc -w 10 example.com 1234
Proxy with Netcatnc -l 1234 | nc example.com 5678
Create a simple HTTP serverecho -e "HTTP/1.1 200 OK\r\n\r\nHello World" | nc -l 1234
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" | nc 8.8.8.8 53
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

About Anto Online

Anto, a seasoned technologist with over two decades of experience, has traversed the tech landscape from Desktop Support Engineer to enterprise application consultant, specializing in AWS serverless technologies. He guides clients in leveraging serverless solutions while passionately exploring cutting-edge cloud concepts beyond his daily work. Anto's dedication to continuous learning, experimentation, and collaboration makes him a true inspiration, igniting others' interest in the transformative power of cloud computing.

View all posts by Anto Online

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.