How to Use Netcat Commands_ Examples and Cheat Sheets
How to Use Netcat Commands_ Examples and Cheat Sheets
com/blog/netcat-commands#cheat-sheet
1 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
The Netcat utility program supports a wide range of commands to manage networks and
monitor the �low of tra�ic data between systems. Computer networks, including the world
wide web, are built on the backbone of the Transmission Control Protocol (TCP) and User
Datagram Protocol (UDP). Think of it as a free and easy companion tool to use alongside
Wireshark, which specializes in the analysis of network packets. The original version of Netcat
was released back in 1995 and has received a number of iterative updates in the decades
since.
Is protecting your data a priority? Our team will create a detailed, true-to-life
report based on your company data, that reveals the vulnerabilities hackers will
hunt for. Schedule your free Risk Assessment now.
2 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
Netcat Commands
3 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
Netcat functions as a back-end tool that allows for port scanning and port listening. In
addition, you can actually transfer �iles directly through Netcat or use it as a backdoor into
other networked systems. Partnered with a tool like Varonis Edge, you would receive an alert
of any unusual activity and could then use Netcat to investigate. Lastly, Netcat is a �lexible tool
because of how it can be scripted for larger tasks.
4 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
running basic commands to test its functionality. Here are a few to get started with:
nc -help – This command will print a list of all of the available commands you can use in
Netcat. It will come in handy if you run into any errors while writing a script or are unsure of
how to proceed.
nc -z -v site.com – This will run a basic port scan of the speci�ied website or server. Netcat will
return verbose results with lists of ports and statuses. Keep in mind that you can use an IP
address in place of the site domain.
nc -l – This command will instruct the local system to begin listening for TCP connections and
UDP activity on a speci�ic port number.
nc site.com 1234 (less than) �ile_name – This command will initiate the transfer of a �ile based
on the speci�ied port number.
Printf – Netcat can actually operate as a simpli�ied web host. This command will let you save
HTML code and publish it through your local server.
5 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
All Netcat commands must start with the “netcat” identi�ier or “nc” as a shorter option. By
default, the Netcat tool will assume you want to perform a port scan unless you indicate
otherwise.
Different option parameters can be used that include: “-u” for UDP tra�ic instead of TCP, “-v”
6 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
for verbose output, “-p” to specify a speci�ic port, and “-D” to turn on full debugging mode.
Individual attributes within a Netcat command must be separated with a space. The command
prompt will inform you if you have a typo or unrecognized term in your script.
A basic port scan command for an IP ncat address looks like this:
nc -v -n 8.8.8.8 1-1000
7 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
Note that the numbers at the end of the command tell Netcat to only scan for ports between
numbers 1 and 1000.
If you don’t know the IP address of a server or website, then you can look it up via a ping
terminal command or just insert the domain into the Netcat command:
nc -v -n google.com 1-1000
You should always perform port scans when connected to your local enterprise network. If
not, you can con�igure your router with a VPN service to create a secure tunnel into the
8 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
network.
To get started, you �irst need Netcat to start listening on a port number. Make sure not to
choose a port that is already in use by another application or service.
nc -l -p 1299
9 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
Then all you need to do is launch the chat session with a new TCP connection:
nc localhost 1299
This process can also be used to spin up a basic web server from your local machine. Netcat
will function as the web host and allow you to store HTML content which can then be viewed
through a web browser.
First, create a new text document on your local system and make sure to use valid HTML tags.
Then save the �ile as “index.html” and store it in the root of your Netcat directory. Now switch
back to the Netcat tool and run this command:
To see the HTML in action, simply open any web browser and navigate to your local IP address
with: 8999 at the end to specify the port of the host.
Even with this setting turned on, Netcat will not reveal any of your credentials or
10 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
authentication data.
Along with a tool like Varonis Edge, Netcat can be helpful for IT professionals who are looking
into internet tra�ic issues or proxies. Here’s an example of how to obtain the HTML content
from Google’s homepage:
Note that the port number 80 is required for this type of command since the world wide web
uses it as a default for TCP over IP connections.
Run this Netcat command on the server instance to send the �ile over port 1499:
11 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
Then run this command on the client to accept, receive, and close the connection:
Make sure to replace “server.com” with the full hostname or IP address of the sending server.
12 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
Multiple Netcat commands can be grouped together in a single script and be run through
either a Linux or Windows shell. In some cases, it may be worthwhile to have the scripts on a
regular timetable.
nc -n -v -l -p 5555 -e /bin/bash
Then from any other system on the network, you can test how to run commands on host after
successful Netcat connection in bash.
A reverse shell is a remote access approach where you run administrative commands from one
terminal while connecting to another server on the network. To get started, you need to
enable the shell tool over a Netcat command by using Netcat reverse shell:
nc -n -v -l -p 5555 -e /bin/bash
Then from any other system on the network, you can test how to run commands on the
13 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
Netcat Fundamentals
nc -6 – use IPv6
14 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
nc -l -p [port] 0 (less than) backpipe (pipe) nc [client IP] [port] (pipe) tee backpipe
Netcat Banners
15 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
echo “” | nc -zv -wl [host] [port range] – obtain the TCP banners for a range of ports
16 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
1 Schedule a demo with us to see Varonis in action. We'll personalize the session to your org's
data security needs and answer any questions.
2 See a sample of our Data Risk Assessment and learn the risks that could be lingering in your
environment. Varonis' DRA is completely free and offers a clear path to automated
remediation.
3 Follow us on LinkedIn, YouTube, and X (Twitter) for bite-sized insights on all things data
security, including DSPM, threat detection, AI security, and more.
Michael Buckbee
Michael has worked as a sysadmin and software developer for Silicon Valley
startups, the US Navy, and everything in between.
17 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
D
e
pl
o
y
s
in
m
in
u
t
e
s.
Keep reading
18 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
How to Use Nmap: Commands and Tutorial How to Create and Manage the Azure Network
Guide Watcher Resource
Nmap is a powerful, and fast network mapping tool. In The Azure Network Watcher comes with great diagnostic
this guide, we’ll explain how to install and use Nmap, and and monitoring tools. Learn more about how to create a
show you how to protect your networks. Network Watcher and manage its components.
19 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
How to Monitor Network Tra�ic: Effective Steps Update 62 - SaaS Authentication Monitoring
& Tips Evasion
In this article, you will learn how to monitor network Businesses know they need to monitor their SaaS apps,
tra�ic using different tools and methods. but it's easy to get lulled into a false sense of security if
you're relying on authentication monitoring as your onl…
20 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
SSPM
Compliance
Management
Email Security
Identity Security
Athena AI
Data Access
Governance
21 of 22 11/8/2024, 2:08 AM
How to Use Netcat Commands: Examples and Cheat Sheets https://www.varonis.com/blog/netcat-commands#cheat-sheet
22 of 22 11/8/2024, 2:08 AM