Nmap Cheat Sheet: Essential Scanning Commands and Flags

This Nmap cheat sheet gives you the commands you actually use during a pentest, a CTF or a network audit: target selection, host discovery, scan types, port selection, service and OS detection, NSE scripts, timing, output and firewall evasion. Copy the commands, replace the target, and only scan systems you own or are explicitly authorized to test.

Quick-Start Commands

If you only remember five commands, make it these:

# Fast scan of the 100 most common ports
nmap -F 10.10.10.5

# Default scripts + version detection on the top 1000 ports
nmap -sC -sV 10.10.10.5

# Scan all 65,535 TCP ports quickly (lab/CTF)
sudo nmap -p- --min-rate 5000 -T4 10.10.10.5

# Find live hosts on a subnet without port scanning
sudo nmap -sn 192.168.1.0/24

# Aggressive scan: OS, versions, default scripts and traceroute
sudo nmap -A 10.10.10.5

Target Specification

CommandWhat it does
nmap 10.10.10.5Scan a single IP
nmap scanme.nmap.orgScan a hostname
nmap 192.168.1.0/24Scan a CIDR range
nmap 192.168.1.1-50Scan an IP range
nmap -iL targets.txtRead targets from a file
nmap 192.168.1.0/24 --exclude 192.168.1.1Exclude a host from the scan

Host Discovery

OptionWhat it does
-snPing scan only: list live hosts, no port scan
-PnSkip host discovery and treat every host as up (useful when ICMP is blocked)
-PS22,80,443TCP SYN ping on the given ports
-PA80TCP ACK ping
-PU53UDP ping
-PEICMP echo request ping
-PRARP ping (default for local Ethernet networks when run as root)
-nNever do DNS resolution (faster)
--tracerouteTrace the network path to each host

Scan Techniques

OptionScan typeNotes
-sSTCP SYN (“half-open”)Default when run as root; fast and relatively quiet
-sTTCP connectDefault without root privileges; completes the handshake
-sUUDP scanSlow but essential (DNS, SNMP, TFTP…)
-sATCP ACKMaps firewall rules (filtered vs unfiltered)
-sN / -sF / -sXNull, FIN, XmasCan slip past some stateless filters; unreliable against Windows
-sVVersion detectionIdentifies service and version behind each port
-OOS detectionRequires root; works best with at least one open and one closed port

Port Selection

OptionWhat it does
-p 22Scan a single port
-p 22,80,443Scan a list of ports
-p 1-1000Scan a port range
-p-Scan all ports 1–65535
-p U:53,T:80Mix UDP and TCP ports (use with -sU -sS)
-FFast mode: top 100 ports
--top-ports 1000Scan the N most common ports
--openOnly show open (or possibly open) ports

Service, Version and OS Detection

OptionWhat it does
-sVProbe open ports to determine service and version
--version-intensity 0-9How many probes to try (0 = light, 9 = all)
--version-lightShortcut for intensity 2 (faster)
-OOperating system detection
--osscan-guessGuess the OS more aggressively
-AEnables OS detection, version detection, default scripts and traceroute

Nmap Scripting Engine (NSE)

NSE turns Nmap from a port scanner into an enumeration tool. Scripts are grouped into categories such as default, safe, discovery, auth, vuln, brute and intrusive.

# Run the default script set (same as --script=default)
nmap -sC 10.10.10.5

# Run specific scripts
nmap --script http-title,http-headers -p 80,443 10.10.10.5

# Run a whole category
nmap --script vuln 10.10.10.5

# Run all SMB enumeration scripts against port 445
nmap --script "smb-enum-*" -p 445 10.10.10.5

# Pass arguments to a script
nmap --script http-enum --script-args http-enum.basepath=/app/ -p 80 10.10.10.5

# Read a script's documentation
nmap --script-help ssh-auth-methods

Categories like brute, intrusive and dos can lock accounts or disrupt services, so only run them when your scope explicitly allows it.

Timing and Performance

OptionWhat it does
-T0 / -T1Paranoid / Sneaky: very slow, used for IDS evasion
-T2Polite: slows down to use less bandwidth
-T3Normal (default)
-T4Aggressive: good choice on fast, reliable networks and labs
-T5Insane: fastest, may miss ports
--min-rate 1000Send at least N packets per second
--max-retries 1Limit probe retransmissions
--host-timeout 30mGive up on a host after the given time
--scan-delay 1sWait between probes

Output Options

OptionWhat it does
-oN scan.txtNormal, human-readable output
-oX scan.xmlXML output (for tools and reports)
-oG scan.gnmapGrepable output
-oA scanSave in all three main formats at once
-v / -vvIncrease verbosity (see results as they arrive)
--reasonShow why a port is in a given state
--packet-traceShow every packet sent and received
--stats-every 30sPrint progress periodically
--resume scan.gnmapResume an interrupted scan

Firewall and IDS Evasion

These options are useful for testing how well your own firewall and IDS detect scans. Use them only within an authorized scope.

OptionWhat it does
-fFragment packets
--mtu 16Set a custom fragment size (multiple of 8)
-D RND:5Hide among 5 random decoy addresses
-g 53Use a specific source port
--data-length 25Append random data to packets
--spoof-mac 0Use a random MAC address

Understanding Port States

StateMeaning
openA service is accepting connections
closedPort is reachable but nothing is listening
filteredA firewall or filter blocks the probes, so Nmap cannot tell
unfilteredReachable, but open/closed is unknown (seen with ACK scans)
open|filteredNo response; common in UDP scans
closed|filteredNmap cannot decide between closed and filtered

Practical Workflows

CTF and Hack The Box

Find every open port first, then run detailed scans only on what you found:

# Step 1: all TCP ports, fast
sudo nmap -p- --min-rate 5000 -T4 -oN allports.txt 10.10.10.5

# Step 2: scripts and versions on the open ports only
nmap -p 22,80,8080 -sC -sV -oN targeted.txt 10.10.10.5

# Step 3: don't forget the most common UDP ports
sudo nmap -sU --top-ports 20 10.10.10.5

New to HTB? Start with our Hack The Box beginner’s guide and the first CTF methodology.

Internal Network Audit

# Discover live hosts
sudo nmap -sn 192.168.1.0/24 -oG live.gnmap

# Extract the IPs that responded
grep Up live.gnmap | cut -d " " -f 2 > hosts.txt

# Scan the top 1000 ports with versions on those hosts
sudo nmap -sS -sV -iL hosts.txt -oA internal_audit

What to Do After Nmap

Common Mistakes

  • Only scanning the top 1000 ports. Services on high ports are missed; use -p- when you can.
  • Forgetting UDP. SNMP, DNS and TFTP often hide the easiest wins.
  • Running as a normal user. Without root, Nmap falls back to slower connect scans and cannot do OS detection.
  • Not saving output. Always use -oA so you can review and report later.
  • Using -T5 or very high rates on real networks. You will miss ports and may disrupt fragile devices.

Frequently Asked Questions

Is Nmap legal to use?

Yes, on networks you own or have written permission to test. Scanning systems without authorization may be illegal depending on your country, so stick to your own lab, platforms like Hack The Box, or an agreed pentest scope.

What is the difference between -sS and -sT?

-sS sends a SYN and never completes the TCP handshake, which is faster and leaves fewer application logs, but it needs root. -sT uses the operating system’s normal connect call and completes the handshake, so it works without privileges but is slower and noisier.

How do I scan all ports with Nmap?

Use -p-, which covers ports 1 to 65535. Adding --min-rate and -T4 speeds it up in labs.

Why are my ports showing as filtered?

A firewall is dropping the probes. Try -Pn if the host looks down, scan different ports, or use an ACK scan (-sA) to map which rules are in place.

Is Nmap a vulnerability scanner?

Not primarily. It maps hosts, ports and services, but NSE scripts in the vuln category can check for some known issues. For full assessments, combine it with a dedicated scanner and manual testing.

Conclusion

Nmap is the first tool you run and the one you come back to most. Master host discovery, full port scans, -sC -sV and the output options first, then add NSE scripts and timing tweaks as you gain experience. Bookmark this cheat sheet and keep the official documentation close for the details.

References

Leave a Comment

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

Scroll to Top