Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Nmap Cheat Sheet

Quick: A concise, practical reference for common Nmap workflows — target selection, scan types, discovery, NSE usage, output handling, evasion tricks, and useful one-liners. Designed like a consultant's quick-reference: organized by category so you can scan and apply fast.


Table of contents

  1. Overview & Usage Tips
  2. Target Specification
  3. Scan Techniques
  4. Host Discovery
  5. Port Specification
  6. Service & Version Detection
  7. OS Detection
  8. Timing & Performance
  9. Timing Tunables
  10. NSE (Nmap Scripting Engine)
  11. Useful NSE Examples
  12. Firewall / IDS Evasion & Spoofing
  13. Output Formats & Options
  14. Helpful Output Examples & Pipelines
  15. Miscellaneous Flags & Other Commands
  16. Practical Tips & Etiquette

Overview & Usage Tips

  • Run Nmap as root (or with sudo) for the most feature-complete scans (e.g., SYN -sS, raw packets, OS detection).
  • Start with discovery (-sn) and light scans (-T3 -F -sV) to find live hosts before aggressive options.
  • Log results (-oA) so you can re-analyze and resume scans later.
  • Respect scope & permissions — scanning networks you don't own can be illegal.

Target Specification

Define which IPs/ranges/subnets Nmap should scan.

Switch / SyntaxExampleDescription
Single IPnmap 192.168.1.1Scan a single host
Multiple IPsnmap 192.168.1.1 192.168.2.1Scan specific hosts
Rangenmap 192.168.1.1-254Scan an IP range
Domainnmap scanme.nmap.orgScan a hostname
CIDRnmap 192.168.1.0/24CIDR subnet scan
-iLnmap -iL targets.txtRead targets from file
-iRnmap -iR 100Scan 100 random hosts
--excludenmap --exclude 192.168.1.1Exclude host(s) from scan

Nmap Scan Techniques

Pick based on stealth, permissions, and speed.

SwitchExampleDescription
-sSnmap 192.168.1.1 -sSTCP SYN scan (stealthy; default with privileges)
-sTnmap 192.168.1.1 -sTTCP connect() scan (no raw socket required)
-sUnmap 192.168.1.1 -sUUDP scan
-sAnmap 192.168.1.1 -sAACK scan (firewall mapping)
-sWnmap 192.168.1.1 -sWWindow scan
-sMnmap 192.168.1.1 -sMMaimon scan
-Anmap 192.168.1.1 -AAggressive — OS, version, scripts, traceroute

Host Discovery

Find out which hosts are up before scanning ports or when skipping port scans.

SwitchExampleDescription
-sLnmap 192.168.1.1-3 -sLList scan — do not send probes (target listing only)
-snnmap 192.168.1.1/24 -snPing / host discovery only (no port scan)
-Pnnmap 192.168.1.1-5 -PnSkip host discovery (treat all hosts as up)
-PSnmap 192.168.1.1-5 -PS22-25,80TCP SYN discovery on specified ports (80 default)
-PAnmap 192.168.1.1-5 -PA22-25,80TCP ACK discovery on specified ports (80 default)
-PUnmap 192.168.1.1-5 -PU53UDP discovery on specified ports (40125 default)
-PRnmap 192.168.1.0/24 -PRARP discovery (local nets only)
-nnmap 192.168.1.1 -nNever perform DNS resolution

Port Specification

Target specific ports, ranges, or mixed TCP/UDP sets.

SwitchExampleDescription
-pnmap 192.168.1.1 -p 21Scan single port
-pnmap 192.168.1.1 -p 21-100Scan port range
-pnmap 192.168.1.1 -p U:53,T:21-25,80Mix UDP and TCP ports
-p-nmap 192.168.1.1 -p-Scan all TCP ports (1–65535)
Service namesnmap 192.168.1.1 -p http,httpsUse service names instead of numbers
-Fnmap 192.168.1.1 -FFast scan — top 100 ports
--top-portsnmap 192.168.1.1 --top-ports 2000Scan top N ports by frequency
-p0- / -p-65535nmap 192.168.1.1 -p0-Open-ended ranges; -p0- will scan from 0 to 65535

Service & Version Detection

Try to identify the service and its version running on discovered ports.

SwitchExampleDescription
-sVnmap 192.168.1.1 -sVService/version detection
-sV --version-intensitynmap 192.168.1.1 -sV --version-intensity 8Intensity 0–9. Higher = more probing
--version-lightnmap 192.168.1.1 -sV --version-lightLighter/faster detection (less reliable)
--version-allnmap 192.168.1.1 -sV --version-allFull (intensity 9) detection
-Anmap 192.168.1.1 -AIncludes -sV, OS detection, NSE scripts, traceroute

OS Detection

Fingerprint the target TCP/IP stack to guess the OS.

SwitchExampleDescription
-Onmap 192.168.1.1 -ORemote OS detection (TCP/IP fingerprinting)
--osscan-limitnmap 192.168.1.1 -O --osscan-limitSkip OS detection unless ports show open/closed pattern
--osscan-guessnmap 192.168.1.1 -O --osscan-guessBe more aggressive about guesses
--max-os-triesnmap 192.168.1.1 -O --max-os-tries 1Limit how many OS probe attempts are made
-Anmap 192.168.1.1 -AOS detection included with -A

Timing & Performance

Built-in timing templates trade off speed vs stealth.

SwitchExampleDescription
-T0nmap 192.168.1.1 -T0Paranoid — max IDS evasion (very slow)
-T1nmap 192.168.1.1 -T1Sneaky — IDS evasion
-T2nmap 192.168.1.1 -T2Polite — reduce bandwidth/CPU usage
-T3nmap 192.168.1.1 -T3Normal (default)
-T4nmap 192.168.1.1 -T4Aggressive — faster but noisier
-T5nmap 192.168.1.1 -T5Insane — assumes very fast, reliable network

Timing Tunables (Fine Control)

Adjust timeouts, parallelism, rates and retries.

  • --host-timeout <time> — give up on a host after this time (e.g., --host-timeout 2m).
  • --min-rtt-timeout, --max-rtt-timeout, --initial-rtt-timeout <time> — control probe RTT timeouts.
  • --min-hostgroup, --max-hostgroup <size> — group size for parallel host scanning.
  • --min-parallelism, --max-parallelism <num> — probe parallelization controls.
  • --max-retries <tries> — maximum retransmissions.
  • --min-rate <n> / --max-rate <n> — packet send rate bounds.

Examples:

nmap --host-timeout 4m --max-retries 2 192.168.1.1
nmap --min-rate 100 --max-rate 1000 -p- 192.168.1.0/24

NSE (Nmap Scripting Engine)

Use scripts to automate checks, fingerprinting, vulnerability discovery and enumeration.

SwitchExampleNotes
-sCnmap 192.168.1.1 -sCRun default safe scripts (convenient discovery)
--scriptnmap 192.168.1.1 --script http*Run scripts by name or wildcard
--script <script1>,<script2>nmap --script banner,http-titleRun specific scripts
--script-argsnmap --script snmp-sysdescr --script-args snmpcommunity=publicProvide args to scripts
--script "not intrusive"nmap --script "default and not intrusive"Compose script sets (example)

Useful NSE Examples

A few practical one-liners to keep handy.

# Generate sitemap from web server (HTTP):
nmap -Pn --script=http-sitemap-generator scanme.nmap.org

# Fast random search for web servers:
nmap -n -Pn -p 80 --open -sV -vvv --script banner,http-title -iR 1000

# Brute-force DNS hostnames (subdomain guessing):
nmap -Pn --script=dns-brute domain.com

# Safe SMB enumeration (useful on internal networks):
nmap -n -Pn -vv -O -sV --script smb-enum*,smb-ls,smb-mbenum,smb-os-discovery,smb-vuln* 192.168.1.1

# Whois queries via scripts:
nmap --script whois* domain.com

# Detect XSS-style unsafe output escaping on HTTP port 80:
nmap -p80 --script http-unsafe-output-escaping scanme.nmap.org

# Check for SQL injection (scripted):
nmap -p80 --script http-sql-injection scanme.nmap.org

Firewall / IDS Evasion & Spoofing

Techniques to make traffic less obvious. Use responsibly.

SwitchExampleDescription
-fnmap 192.168.1.1 -fFragment packets (can evade some filters)
--mtunmap 192.168.1.1 --mtu 32Set MTU/fragment size
-Dnmap -D decoy1,decoy2,ME,decoy3 targetDecoy IP addresses to confuse observers
-Snmap -S 1.2.3.4 targetSpoof source IP (may require raw sockets)
-gnmap -g 53 targetSet source port (useful to bypass simple filters)
--proxiesnmap --proxies http://192.168.1.1:8080 targetRelay scans through HTTP/SOCKS proxies
--data-lengthnmap --data-length 200 targetAppend random data to packets

Example IDS evasion command

nmap -f -T0 -n -Pn --data-length 200 -D 192.168.1.101,192.168.1.102,192.168.1.103,192.168.1.23 192.168.1.1

Output Formats & Options

Save scans so you can analyze later or process programmatically.

SwitchExampleDescription
-oNnmap 192.168.1.1 -oN normal.fileNormal human-readable output file
-oXnmap 192.168.1.1 -oX xml.fileXML output (good for parsing)
-oGnmap 192.168.1.1 -oG grep.fileGrepable output (legacy)
-oAnmap 192.168.1.1 -oA resultsWrite results.nmap, results.xml, results.gnmap
-oG -nmap 192.168.1.1 -oG -Print grepable to stdout
--append-outputnmap -oN file -append-outputAppend to an existing file
-v / -vvnmap -vIncrease verbosity
-d / -ddnmap -dIncrease debugging info
--reasonnmap --reasonShow reason a port state was classified
--opennmap --openShow only open or possibly-open ports
--packet-tracenmap --packet-traceShow raw packet send/receive detail
--iflistnmap --iflistList interfaces and routes
--resumenmap --resume results.fileResume an interrupted scan (requires prior save)

Helpful Output Examples & Pipelines

Combine Nmap with standard UNIX tools to extract actionable info.

# Find web servers (HTTP):
nmap -p80 -sV -oG - --open 192.168.1.0/24 | grep open

# Generate list of live hosts from random scan (XML -> grep -> cut):
nmap -iR 10 -n -oX out.xml | grep "Nmap" | cut -d " " -f5 > live-hosts.txt

# Append hosts from second scan:
nmap -iR 10 -n -oX out2.xml | grep "Nmap" | cut -d " " -f5 >> live-hosts.txt

# Compare two scans:
ndiff scan1.xml scan2.xml

# Convert XML to HTML:
xsltproc nmap.xml -o nmap.html

# Frequency of open ports (clean and aggregate):
grep " open " results.nmap | sed -r 's/ +/ /g' | sort | uniq -c | sort -rn | less

Miscellaneous Flags

SwitchExampleDescription
-6nmap -6 2607:f0d0:1002:51::4Enable IPv6 scanning
-hnmap -hShow help screen

Other Useful Commands (Mixed Examples)

# Discovery only on specific TCP ports, no port scan:
nmap -iR 10 -PS22-25,80,113,1050,35000 -v -sn

# ARP-only discovery on local net, verbose, no port scan:
nmap 192.168.1.0/24 -PR -sn -vv

# Traceroute to random targets (no ports):
nmap -iR 10 -sn --traceroute

# List targets only but use internal DNS server:
nmap 192.168.1.1-50 -sL --dns-server 192.168.1.1

# Show packet details during scan:
nmap 192.168.1.1 --packet-trace

Practical Tips & Etiquette

  • Always have written permission to scan networks you do not own.
  • Start small: discovery -> targeted port scan -> version detection -> scripts.
  • Use --script carefully; some scripts are intrusive.
  • Keep a log of what you scanned and when (timestamps help with audits).
  • For large networks, break scans into chunks and use --min-rate/--max-rate to control load.

Appendix — Quick Command Generator (Examples)

  • nmap -sS -p 1-100 -T4 -oA quick-scan 192.168.1.0/24 — fast SYN scan of top 100 ports, save outputs.
  • nmap -Pn -sV --script=vuln -oX vuln-check.xml 10.0.0.5 — skip host discovery, version & vulnerability scripts.