Cheat sheets / Networking
Nmap Cheat Sheet
Nmap finds which hosts are up, which ports are open and what is running on them. Start simple, then add options as you need more detail.
Safe and legal use
Scanning a network you do not own can be illegal and can break fragile systems. Only scan systems you own or have written permission to test. For practice, use your own lab, or scanme.nmap.org, which the Nmap project allows people to scan lightly.
Choosing targets
| Target | Example |
|---|---|
| One IP | nmap 192.0.2.10 |
| Host name | nmap lab.example |
| Several IPs | nmap 192.0.2.10 192.0.2.11 |
| A range | nmap 192.0.2.1-50 |
| A whole subnet (CIDR) | nmap 192.0.2.0/24 |
| From a file (one per line) | nmap -iL targets.txt |
| Skip one host | nmap 192.0.2.0/24 --exclude 192.0.2.1 |
Common scans
| Command | What it does | Example |
|---|---|---|
nmap <target> |
Scan the 1,000 most common TCP ports | nmap 192.0.2.10 |
nmap -sn <range> |
Host discovery only (ping scan), no port scan | nmap -sn 192.0.2.0/24 |
sudo nmap -sS <target> |
TCP SYN scan ("half-open"). The default when run as root | sudo nmap -sS 192.0.2.10 |
nmap -sT <target> |
TCP connect scan. The default without root | nmap -sT 192.0.2.10 |
sudo nmap -sU <target> |
UDP scan (slow) | sudo nmap -sU --top-ports 20 192.0.2.10 |
nmap -Pn <target> |
Skip host discovery and treat the host as up | nmap -Pn 192.0.2.10 |
nmap -F <target> |
Fast scan: the top 100 ports | nmap -F 192.0.2.10 |
Choosing ports
| Option | What it does | Example |
|---|---|---|
-p <port> |
One port | nmap -p 22 192.0.2.10 |
-p <list> |
Several ports | nmap -p 22,80,443 192.0.2.10 |
-p <range> |
A range | nmap -p 1-1024 192.0.2.10 |
-p- |
All 65,535 TCP ports | nmap -p- 192.0.2.10 |
--top-ports <n> |
The n most common ports | nmap --top-ports 200 192.0.2.10 |
Finding out more
| Option | What it does | Example |
|---|---|---|
-sV |
Detect service names and versions on open ports | nmap -sV 192.0.2.10 |
-O |
Guess the operating system (needs root) | sudo nmap -O 192.0.2.10 |
-sC |
Run the default set of NSE scripts | nmap -sC 192.0.2.10 |
-A |
Aggressive: -O, -sV, -sC and traceroute together |
sudo nmap -A 192.0.2.10 |
--script <name> |
Run a specific NSE script | nmap --script http-title -p 80 192.0.2.10 |
--reason |
Show why nmap chose each port state | nmap --reason 192.0.2.10 |
-v / -vv |
More output while scanning | nmap -v 192.0.2.10 |
Timing
| Option | Name | When to use |
|---|---|---|
-T0 |
paranoid | Extremely slow, for avoiding detection |
-T1 |
sneaky | Very slow |
-T2 |
polite | Slow, uses less bandwidth |
-T3 |
normal | The default |
-T4 |
aggressive | Faster, good for labs and fast networks |
-T5 |
insane | Very fast, may miss ports |
Faster is not always better. On slow or busy networks, high speeds give wrong results.
Port states
| State | Meaning |
|---|---|
open |
A program is accepting connections on this port |
closed |
The host answered, but nothing is listening on this port |
filtered |
No answer or an error came back. A firewall is probably dropping packets |
unfiltered |
The port is reachable but nmap cannot tell if it is open or closed (ACK scan) |
open|filtered |
Nmap cannot tell if it is open or filtered (common with UDP) |
closed|filtered |
Nmap cannot tell if it is closed or filtered (rare) |
Output formats
| Option | Format | Example |
|---|---|---|
-oN <file> |
Normal text, like the screen | nmap -oN scan.txt 192.0.2.10 |
-oX <file> |
XML, for other tools | nmap -oX scan.xml 192.0.2.10 |
-oG <file> |
Grepable, one host per line | nmap -oG scan.gnmap 192.0.2.10 |
-oA <name> |
All three at once (.nmap, .xml, .gnmap) |
nmap -oA lab-scan 192.0.2.10 |
Always save your output. You will want to compare scans later.
Reading the results
Nmap scan report for 192.0.2.10
Host is up (0.012s latency).
Not shown: 997 closed tcp ports (reset)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.10
80/tcp open http nginx 1.18.0 (Ubuntu)
3306/tcp filtered mysql
| Line | What it tells you |
|---|---|
Host is up |
The host answered discovery probes |
Not shown: 997 closed |
Ports that were closed are hidden to keep output short |
22/tcp open ssh |
SSH is reachable. Check it uses keys and strong passwords |
VERSION column |
The software and version. Search it for known vulnerabilities |
3306 filtered |
A firewall is likely blocking MySQL. That is usually good |
Questions to ask after a scan:
- Is every open port expected? Each one is something an attacker can reach.
- Are any versions old or unsupported?
- Are admin services (SSH, RDP, databases) open to the whole internet?
- Does a second scan with
-Pnor-p-find more?
Useful combinations
# Who is up on my lab network?
nmap -sn 192.0.2.0/24
# Quick look at one host with versions
nmap -sV -T4 192.0.2.10
# Full TCP scan, then detail on what you found
sudo nmap -p- -T4 192.0.2.10 -oN all-ports.txt
sudo nmap -p 22,80,8080 -sV -sC 192.0.2.10 -oA detail
# Top UDP ports
sudo nmap -sU --top-ports 20 192.0.2.10
SECUREK Learn · learn.securek.co/cheat-sheets/nmap
Spotted a mistake or something unclear? Report a mistake