Nmap Cheatsheet

Common Recipes

Use this Nmap reference while you build software engineering projects, review code, or refresh the syntax you reach for most.

The five scans that cover most work

# 1. what is alive on this subnet
sudo nmap -sn 10.0.0.0/24

# 2. quick look at one host, top 1000 TCP ports with versions
sudo nmap -sV -T4 --open 10.0.0.5

# 3. every TCP port, fast, then version-scan only what answered
sudo nmap -p- --min-rate 1000 -oG all.gnmap 10.0.0.5
sudo nmap -sV -sC -p "$(awk -F'Ports: ' '/Ports:/{print $2}' all.gnmap \
  | tr ',' '\n' | awk -F'/' '/open/{print $1}' | paste -sd, -)" 10.0.0.5

# 4. the everything scan on one target
sudo nmap -A -T4 -p- -oA full-10.0.0.5 10.0.0.5

# 5. the common UDP services, because full UDP takes hours
sudo nmap -sU --top-ports 100 -T4 10.0.0.5

Recipe 3 is the workhorse pattern. A bare -sS -p- finishes in minutes because it only sends one packet per port, and the expensive work (-sV -sC) then runs against ten ports instead of 65,535.

Recipe table

GoalCommand
Live hosts, no port scansudo nmap -sn 10.0.0.0/24
Live hosts, skip discoverysudo nmap -Pn -p 80,443 10.0.0.0/24
Fast top-100 sweepsudo nmap -F --open 10.0.0.0/24
All TCP ports on one hostsudo nmap -p- 10.0.0.5
Service and version detailsudo nmap -sV 10.0.0.5
Aggressive, everything onsudo nmap -A 10.0.0.5
OS guesssudo nmap -O --osscan-guess 10.0.0.5
Default safe scriptssudo nmap -sC 10.0.0.5
Web app surfacesudo nmap -p 80,443,8080,8443 --script http-enum,http-title 10.0.0.5
TLS configurationsudo nmap -p 443 --script ssl-enum-ciphers,ssl-cert 10.0.0.5
SMB detailsudo nmap -p 139,445 --script smb-os-discovery,smb-protocols 10.0.0.5
Known-vuln checksudo nmap -sV --script vuln 10.0.0.5
Common UDPsudo nmap -sU --top-ports 100 10.0.0.5
IPv6 targetsudo nmap -6 -sV 2001:db8::5
From a target listsudo nmap -iL hosts.txt -oA batch
Scan without rootnmap -sT -Pn --top-ports 200 10.0.0.5
Firewall rule mappingsudo nmap -sA -p 1-1000 10.0.0.5
Quiet and slowsudo nmap -sS -T2 -f --top-ports 50 10.0.0.5
Change detectionsudo nmap -sV -oX now.xml 10.0.0.0/24 && ndiff prev.xml now.xml

Discovery on a network you just joined

ip -br addr                                   # find your subnet first
sudo nmap -sn -n 10.0.0.0/24 -oG hosts.gnmap  # ARP sweep, seconds on a LAN
awk '/Up$/{print $2}' hosts.gnmap > live.txt

sudo nmap -iL live.txt -F --open -oA quick    # top 100 ports across live hosts
sudo nmap -iL live.txt -sV -sC --top-ports 200 --open -oA detail
StepWhy
ip -br addrscan the right range, not a guess
-sn -nARP is fast and skips reverse DNS latency
Build live.txtlater scans hit 12 hosts, not 254
-F --openone screen of signal per host
-sV -sC lastthe slow work runs on a short list

Single-host deep dive

T=10.0.0.5
sudo nmap -Pn -p- --min-rate 1000 -oA "$T-ports" "$T"
PORTS=$(awk -F'Ports: ' '/Ports:/{print $2}' "$T-ports.gnmap" \
  | tr ',' '\n' | awk -F'/' '/open/{print $1}' | paste -sd, -)
sudo nmap -Pn -sV -sC -O -p "$PORTS" -oA "$T-deep" "$T"
sudo nmap -Pn -sU --top-ports 50 -oA "$T-udp" "$T"

Three passes, in the right order: find the ports, interrogate the ports, then check the handful of UDP services that matter. Each pass writes its own -oA set, so nothing gets re-run when you come back to the notes.

Web and TLS specifics

# what is served, and where
sudo nmap -p 80,443,8000,8080,8443 --script http-title,http-headers,http-methods 10.0.0.5

# hidden paths and known app fingerprints
sudo nmap -p 443 --script http-enum --script-args http.useragent='Mozilla/5.0' 10.0.0.5

# certificate and cipher posture, the two questions auditors ask
sudo nmap -p 443 --script ssl-cert,ssl-enum-ciphers 10.0.0.5

# name-based virtual hosts on shared IPs
sudo nmap -p 443 --script ssl-cert 10.0.0.5 | grep -E 'Subject|DNS:'
ScriptAnswers
http-titleis this a login page, an API, or a default install
http-headersserver software, framework hints, missing security headers
http-methodsis PUT or TRACE still enabled
http-enumcommon admin paths and known app signatures
ssl-certissuer, expiry, and every name on the certificate
ssl-enum-ciphersprotocol versions and a per-suite letter grade

Defensive and inventory use

Nmap earns most of its hours on the blue side, answering "what is actually listening" rather than "how do I get in".

# weekly inventory, diffed against last week
sudo nmap -sV -O --top-ports 1000 --noninteractive \
  -oX /var/lib/scans/$(date +%F).xml 10.0.0.0/16
ndiff /var/lib/scans/last.xml /var/lib/scans/$(date +%F).xml

# verify a firewall change did what the ticket said
sudo nmap -Pn -p 22,80,443,3306 --reason 10.0.0.5

# confirm a service is bound where you think it is
sudo nmap -p 5432 --open 10.0.0.0/24        # any stray Postgres on the LAN

# find hosts still speaking old TLS
sudo nmap -p 443 --script ssl-enum-ciphers 10.0.0.0/24 \
  | grep -B5 -E 'TLSv1\.0|SSLv3'
QuestionRecipe
Did the firewall change land-Pn --reason on the exact ports
What changed since last weektwo -oX runs plus ndiff
Is a database exposed to the LAN-p 5432,3306,27017,6379 --open on the subnet
Which hosts allow weak TLS--script ssl-enum-ciphers across the range
Is anything unexpected listening-p- on your own hosts, compared to a baseline

Habits worth keeping

HabitReason
-oA <dated-basename> on every real scanXML for tooling, normal for --resume, grepable for shell work
--open on anything wider than one hostclosed ports drown the findings
-n when you do not need namesreverse DNS is often the slowest part of a sweep
-Pn when discovery is filteredotherwise nmap declares live hosts down and skips them
Two-stage scanscheap sweep first, expensive detection on the survivors
Sanity-check the rangea typo in a CIDR mask is how people scan someone else's network
Keep scope in writingpermission is the difference between an audit and an offence