A scan is not a reconnaissance report. It is a sequence of packets that somebody's firewall, IDS or on-call engineer may notice, and the difference between a professional job and an incident is usually preparation. This guide uses Nmap 7.993, released on 23 October 2026; every option below was checked against that release's reference guide.
Permission first
Do not scan a host you do not own or have written authorization to test. Port scanning is logged, attributable and, in many jurisdictions, criminal without permission. Get the scope, the permitted window and the exclusions in writing, agree who to call when something breaks, and confirm which source addresses the client expects to see.
Three things before you type a command: the exact targets and CIDR ranges, the ports or protocols you may touch, and a rate the client's infrastructure can survive. A scan of a /24 is 256 addresses; at Nmap's default 1,000 TCP ports that is about 256,000 probes in a short window, enough to trip rate limiting on a load balancer or fill a small firewall's log disk. If the engagement lives in a harness, put those boundaries in the tool: the plugin's scope check rejects out-of-scope targets before execution, and the approval gate covers intrusive categories.
Discovery and port states
-sn is host discovery with no port scan — the old -sP. On IPv4 it sends four probes by default: an ICMP echo request, a TCP SYN to port 443, a TCP ACK to port 80 and an ICMP timestamp request, plus ARP for targets on the local Ethernet segment. Plenty of networks drop ICMP echo while happily serving HTTPS, so a ping sweep reports a healthy host as down; conversely, a firewall that answers for every address makes a dead range look alive.
-Pn removes the guesswork by skipping discovery and treating every address as up. It is the right choice when you know the host exists — a specific server in scope — and the wrong choice for a range, because the manual is explicit that a /16 becomes 65,536 addresses of full scanning. Use -sn to map a range, -Pn on hosts you care about.
Nmap has six port states: open, closed, filtered, unfiltered, open|filtered and closed|filtered. These are not properties of the port but of the path and the probe. That is what stops a report claiming "port 22 is closed" when the truth is "my scan from this vantage point received nothing".
| Scan | What it sends | Needs | Separates |
|---|---|---|---|
-sS SYN | SYN, never completes the handshake | Raw sockets (root) | open, closed, filtered — fast and clear |
-sT connect | Full TCP connection via the OS | No special privilege | The same states, but every connection is visible to the application |
-sU UDP | Protocol-specific UDP payloads | Raw sockets (root) | open, closed, open|filtered — slow and lossy |
The seductive claim is that -sS is stealthy. The manual says it is "relatively unobtrusive and stealthy since it never completes TCP connections", a reasonable description of a 1990s network. In 2026, half-open describes the TCP state, not the record: a stateful firewall logs every denied SYN, an NDR sensor sees a thousand SYNs to a thousand ports in a second as a textbook horizontal sweep, and the host itself may log the attempt. Treat -sS as fast and precise, not invisible.
Services, versions and NSE
An open port is a guess about a service. -sV turns it into a version: after the port scan, Nmap sends probes from nmap-service-probes and matches the responses, reporting the protocol, application, version, hostname where available, device type and a CPE string. The default intensity is 7 on a 0–9 scale; --version-light is intensity 2, and --version-all is 9, which tries every probe and costs time. Raise it for a handful of hosts that matter, not for a /24 you are still triaging.
Version strings lie in ordinary ways: backported patches, proxies, tarpits and services that stay quiet. Record the evidence — the banner or probe output — and treat "Apache 2.4.52" as a hypothesis to test, not a fact to report. -O is the same argument with more noise: it fingerprints the TCP/IP stack against the nmap-os-db database of more than 2,600 fingerprints, produces a useful guess only when at least one open and one closed port were found, requires raw privileges, and gets unreliable across NAT, proxies and virtualised hosts. OS detection is a supporting detail; the service version is what drives the next step.
NSE is where a scan becomes enumeration. There are 14 script categories — auth, broadcast, brute, default, discovery, dos, exploit, external, fuzzer, intrusive, malware, safe, version and vuln — and --script takes category names, script names, directories, wildcards or Boolean expressions such as "safe and not intrusive". -sC is shorthand for --script=default, and --script-args passes per-script parameters.
The distinction that matters is between default and safe. default is a curated set chosen for speed, usefulness and reliability; safe means the scripts were not designed to crash services, saturate bandwidth or exploit holes — not that they are guaranteed harmless. intrusive scripts like http-open-proxy or snmp-brute can absolutely upset production, and the manual warns that scripts are not sandboxed. Read --script-help before you run a category you have not used on that client's kit.
Timing and output
The timing templates run from -T0 (paranoid) to -T5 (insane). -T4 is the sane default on modern, reliable networks: it caps the dynamic scan delay at 10 ms and is what the Nmap book recommends for broadband or Ethernet. -T5 lowers that cap to 5 ms and, in the book's own words, is "too aggressive for my taste". On production infrastructure, the failure mode is not politeness: retransmits and bursty SYNs trip rate limits, fragile appliances drop management sessions, and the resulting filtered states make your report wrong.
Fine-grained controls beat templates when you know the environment: --min-rate N sets a floor in packets per second (and forces Nmap to keep up), --max-rate caps it, --max-retries limits retransmissions so a rate-limited host stops looking filtered, and --host-timeout 15m keeps one dead device from stalling the run. A single host tolerates -T4 and -sV; a /24 needs a rate you chose deliberately, an exclusion list for printers and appliances, and a stop condition agreed with the client.
Output is part of the deliverable. -oA basename writes the normal, XML and grepable formats at once (.nmap, .xml, .gnmap), and -oX - sends XML to stdout for a pipeline. The XML is the one to keep: it preserves ports, service and CPE data, script output and timestamps, which is what a parser or workbench needs. Normal output is for humans and grep; grepable output is a legacy convenience, not an archive format.
# one host, full detail, named output that sorts by date
nmap -Pn -sS -sV --version-all -O --script "safe and not intrusive" \
-T4 --max-retries 2 --host-timeout 15m \
-oA "acme-web-$(date +%Y%m%d-%H%M)" 10.20.30.40
Two sequences and the limits
Two sequences cover most work. The fast one answers "what is there" in minutes per host and is safe to run on a first pass. The thorough one costs more time and more packets, so it belongs on a shortlist of hosts you have already triaged.
# triage: which hosts answer, which common ports are open
nmap -sn 10.20.30.0/24 -oA "acme-sweep-$(date +%Y%m%d-%H%M)"
nmap -Pn -sS --top-ports 200 --open -T4 10.20.30.41 10.20.30.42 \
-oA "acme-triage-$(date +%Y%m%d-%H%M)"
# assessment: every TCP port, targeted UDP, versions, safe NSE, XML
nmap -Pn -sS -p- -T4 --min-rate 800 --max-retries 2 --host-timeout 30m \
10.20.30.41 -oA "acme-tcp-all-$(date +%Y%m%d-%H%M)"
nmap -Pn -sU --top-ports 200 --max-retries 1 --host-timeout 30m \
10.20.30.41 -oA "acme-udp-$(date +%Y%m%d-%H%M)"
nmap -Pn -sV --version-all --script "default and safe" \
10.20.30.41 -oA "acme-svc-$(date +%Y%m%d-%H%M)"
What Nmap will not tell you is just as important. It cannot say whether a service is patched: a version string is a claim, and backports are invisible. It cannot tell you whether an open port is intentional, whether authentication is any good, or whether a business rule can be abused. filtered is not closed, a vuln script is a check rather than an exploit, and UDP results are inherently lossy. None of that is a finding until someone validates it.
What it can do is start a workbench. The XML gives you assets (host, port, protocol, service, version, CPE) and the service version is the key that unlocks everything downstream: template scanners for known exposures, exploit mapping for the versions that are actually present, and a coverage list for the report. In dsh-redteam, pentest_exec runs Nmap inside the plugin's Kali container with the engagement scope enforced, and each run's real output becomes a fact with a tool-run id, so assets and findings inherit the evidence. The catalogue entry, including the NPSL licence note, is on the resources page; the tool contract is in TOOLS.md.
Key takeaways
- Authorisation, scope and a rate limit come before any flag; a /24 is 256 addresses and 250,000 probes at default settings.
-snmaps a range,-Pnscans specific hosts. ICMP silence does not mean a host is down.-sSis fast and precise, not stealthy: stateful firewalls and NDR sensors log and detect it.-sVat intensity 7 is the default for a reason; raise it selectively, and treat version strings as claims.- Use
safeanddefaultNSE categories, read--script-help, and keep every run's XML with-oA.
Sources
- Nmap Reference Guide — Nmap Network Scanning, chapter 15
- nmap/nmap — the Nmap repository and changelog
- Host Discovery — default probes,
-snand-Pn - Port Scanning Basics — the six port states
- Port Scanning Techniques — SYN, connect and UDP scans
- Service and Version Detection — intensity 0–9, default 7
- OS Detection — 2,600+ fingerprints and its limits
- NSE Usage and Examples — 14 categories,
--scriptexpressions - Timing and Performance —
-T4,--min-rate,--host-timeout - Output —
-oA, XML and grepable formats - Nmap changelog — 7.993 released 23 October 2026
- Nmap legal notices — NPSL terms and redistribution
- Nmap Public Source License — GPLv2-based, with additional terms