Nmap in depth
Nmap is the reference network scanner: it discovers hosts, ports, services, versions and operating systems, and with its scripting engine (NSE) it goes as far as checking for specific vulnerabilities. The difference between a scan that takes hours, trips every alarm and misses ports, and one that is fast and accurate lies in understanding which packet each option sends and which reply it expects. That is what this page is about; basic usage and installation live in the tool page.
flowchart LR
H["1. Discovery<br/>is it up?"] --> P["2. Ports<br/>what listens?"]
P --> V["3. Service and version<br/>which software?"]
V --> N["4. NSE<br/>what can I get?"]
N --> O["5. Output -oA<br/>report and next<br/>tools"]
Threat model
Section titled “Threat model”Scanning is the first thing that touches the target and defines the attack surface. On an authorized engagement three constraints override any option:
- Scope: only the IPs and ranges in the contract. Nmap does not care;
-iLwith the agreed list and--excludewith what must not be touched prevent expensive mistakes. - Impact:
-T5, a very high--min-rateorintrusive/dosscripts can knock over industrial equipment, printers and legacy systems. In production,-T3or-T4and a bounded--max-rate. - Noise: a full scan is visible to any IDS. If the engagement measures detection (red team) that matters; on a pentest with the defenders informed, it does not.
Anatomy
Section titled “Anatomy”The five phases
Section titled “The five phases”Nmap always runs the same flow: host discovery → port scan → service/version detection →
OS detection → NSE scripts. Each option enables or tweaks a phase, and any of them can be
skipped (-Pn skips the first, -sn keeps only the first).
What host discovery sends
Section titled “What host discovery sends”With no discovery options, a privileged user sends four probes: ICMP echo, SYN to 443, ACK
to 80 and ICMP timestamp (equivalent to -PE -PS443 -PA80 -PP). Unprivileged, only SYN via
connect() to 80 and 443. On a local Ethernet network Nmap uses ARP (or Neighbor Discovery
on IPv6) even when other probes are requested, because it is faster and more reliable.
nmap -sn 10.0.0.0/24 # discovery only (formerly -sP)nmap -Pn 10.0.0.5 # skip discovery: everything is treated as upnmap -sn -PS22,80,443 -PA80 10.0.0.0/24 # specific TCP probesnmap -sn -PU53 10.0.0.0/24 # UDP: useful where only TCP is filterednmap -sn --disable-arp-ping 10.0.0.0/24 # proxy-ARP networks, where everything looks upnmap -n -sn 10.0.0.0/24 # no reverse DNS: faster and less DNS noise-Pn is the option that recovers the most ports on the Internet (many hosts block ICMP),
but on a /16 it multiplies the time: it port-scans every address even when nobody is there.
Port states and what produces them
Section titled “Port states and what produces them”| State | What Nmap saw |
|---|---|
open |
SYN/ACK (TCP) or a UDP reply |
closed |
RST (TCP) or ICMP port unreachable type 3 code 3 (UDP) |
filtered |
nothing after retransmissions, or another ICMP unreachable |
unfiltered |
only in -sA: an RST arrives, but open or closed is unknown |
open|filtered |
UDP or NULL/FIN/Xmas scans with no reply: cannot be told apart |
Scan types
Section titled “Scan types”Only -sT works without privileges; the rest need root on Unix or administrator on Windows
to send raw packets.
| Type | Packet | When |
|---|---|---|
-sS SYN |
SYN without completing the handshake | default as root: fast and less logged by the application |
-sT connect |
the OS connect(), full handshake |
without root, or through a SOCKS proxy/pivot |
-sU UDP |
datagram (empty or with a known payload) | DNS, SNMP, NTP, TFTP; slow because closed depends on rate-limited ICMP |
-sA ACK |
ACK only | map firewall rules: unfiltered versus filtered |
-sN/-sF/-sX |
no flags / FIN / FIN+PSH+URG | evade stateless filters; Windows and many Cisco devices reply RST to everything and invalidate it |
-sW Window |
like ACK, reads the window size of the RST | few systems |
-sM Maimon |
FIN/ACK | old BSD systems |
-sI idle |
nothing from your IP: uses a zombie’s IP ID | sourceless scan; needs a zombie with incremental IP ID |
-sO |
one packet per IP protocol number | which protocols the host accepts (ICMP, GRE, ESP…) |
Variants
Section titled “Variants”Port selection
Section titled “Port selection”nmap -p- 10.0.0.5 # all 65535 TCPnmap -p 22,80,443,8000-8100 10.0.0.5nmap -p U:53,161,T:22,80 10.0.0.5 # UDP and TCP in one command (with -sU -sS)nmap --top-ports 1000 10.0.0.5 # by frequency (nmap-services); -F is the top 100nmap -p- --exclude-ports 9100 10.0.0.5 # leave the printing port aloneSpeed and reliability
Section titled “Speed and reliability”The -T0…-T5 templates adjust timeouts, retries and parallelism. -T3 is the default;
-T4 assumes a fast, reliable network (max RTT 1250 ms, 6 retries, max delay 10 ms) and is
the one recommended on Ethernet and broadband; -T5 drops to 300 ms and 2 retries and the
manual itself warns it loses results on networks that are not very fast. -T0 and -T1 wait
5 minutes and 15 seconds between probes and only make sense to evade IDS thresholds on very
small scans.
nmap -p- --min-rate 1000 --max-retries 3 10.0.0.5 # fast port sweepnmap -p- --min-rate 1000 --max-retries 3 --host-timeout 20m 10.0.0.0/24nmap --scan-delay 1s -sU --top-ports 50 10.0.0.5 # targets that rate-limit ICMPnmap --min-hostgroup 256 -p 445 10.0.0.0/16 # large groups: more efficient, results when each group finishes--min-rate sets global packets per second; above what the network can handle, Nmap
retransmits and the scan can end up taking longer. --max-retries defaults to 10; on
reliable networks 2 or 3 is enough. Explicit options take precedence over the template.
Service, version and OS
Section titled “Service, version and OS”nmap -sV 10.0.0.5 # nmap-service-probes + bannernmap -sV --version-intensity 9 10.0.0.5 # every probe (slow); 0 = only the most likelynmap -sV --version-light 10.0.0.5 # intensity 2nmap -O --osscan-guess 10.0.0.5 # TCP/IP fingerprint; needs one open and one closed portnmap -A 10.0.0.5 # -sV -O -sC --traceroute: noisy, for the lab-sV is what turns 8088/tcp open radan-http (the nmap-services name by port number)
into http SimpleHTTPServer 0.6 (Python 3.13); without it, the service name is a guess by
port.
Categories matter because they define the risk: safe is not designed to crash anything;
intrusive has a “high risk of crashing the target or being seen as malicious”; dos may
cause denial of service as a side effect; exploit exploits; brute guesses credentials;
external sends data to third-party services. default (-sC) was chosen for speed,
usefulness, low intrusiveness and privacy. version runs only with -sV and cannot be
selected by hand.
nmap -sC -sV -p 22,80,445 10.0.0.5nmap --script "default and safe" 10.0.0.5 # boolean expressionsnmap --script "smb-* and not brute" -p 445 10.0.0.5nmap --script vuln -p 80,443 10.0.0.5 # only reports when it finds somethingnmap --script http-title,http-headers -p 8080 10.0.0.5nmap --script ssh-auth-methods --script-args ssh.user=admin -p 22 10.0.0.5nmap --script-help "smb-enum-*" # name, categories and descriptionnmap --script-trace --script banner -p 21 10.0.0.5 # see every byte the script sendsnmap --script-updatedb # after adding scripts to scripts/Output
Section titled “Output”nmap -oA target-tcp -p- 10.0.0.5 # .nmap (readable) + .gnmap (grep) + .xml (tools)nmap -v --open --reason -p- 10.0.0.5 # open only, with the packet that justifies each stategrep -oP '\d+/open' target-tcp.gnmap | cut -d/ -f1 | paste -sd, # port list for the second passxsltproc target-tcp.xml -o target-tcp.html # HTML report with Nmap's stylesheetThe XML is the input for Metasploit (db_import), for Markdown/CSV converters and for any
script of your own; the .gnmap is for grep and awk on the spot.
Red Team
Section titled “Red Team”Efficient two-pass flow
Section titled “Efficient two-pass flow”# 1. What is open? Fast, no versionssudo nmap -sS -p- --min-rate 1000 --max-retries 3 -n -Pn -oA tcp-all 10.0.0.5# 2. What is it? Only on what is openPORTS=$(grep -oP '\d+/open' tcp-all.gnmap | cut -d/ -f1 | paste -sd,)sudo nmap -sS -sV -sC -O -p "$PORTS" -oA tcp-detail 10.0.0.5# 3. UDP, boundedsudo nmap -sU --top-ports 100 --open -oA udp-top 10.0.0.5Version scanning across 65,535 ports is what turns a minutes-long scan into an hours-long one; splitting it into two passes is the most profitable optimization.
Scanning through a pivot
Section titled “Scanning through a pivot”From a compromised host, raw packets do not travel: use -sT with proxychains or a TUN
interface (see pivoting). With tunnels that turn SYN into
connect() on the agent, -Pn and --unprivileged avoid false positives.
proxychains -q nmap -sT -Pn -n --top-ports 100 10.10.10.5Evasion (when the engagement measures detection)
Section titled “Evasion (when the engagement measures detection)”The manual’s evasion options, with their real limits:
-f/--mtu 16: splits the TCP header across several IP fragments. Raw scans only; firewalls that reassemble fragments defeat it, and some old software crashes on tiny fragments.-D RND:5,ME: decoys; the IDS sees several sources. Decoys should be up (otherwise the target may end up SYN-flooded) and too many slow the scan and degrade accuracy.-g 53/--source-port 53: source from a port some stateless filters trust. No effect on-sT, DNS,-sV, NSE or-O.--data-length 25: appends random bytes so probes are not identical to Nmap signatures. Does not affect-Opackets.--ttl,--spoof-mac 0: change headers;--spoof-maconly on raw packets.-S IP -e eth0 -Pn: spoof the source. Replies never come back: it confuses, it does not produce results.--badsum: invalid checksum; if something replies, there is a firewall or IDS that does not verify.--proxies socks4://…: NSE and-sVonly; no ping, no ports, no OS; no authentication or TLS.-T1/-T2and--scan-delay: what actually evades rate thresholds; at the cost of hours.
What does not evade anything: -sS versus -sT (the IDS sees the SYN either way),
-sV (its probes have signatures, including the Nmap Scripting Engine User-Agent), and
-A. More in firewall and IDS evasion.
Researcher workflow
Section titled “Researcher workflow”- Confirm scope in a file (
-iL) and exclusions (--exclude,--exclude-ports). - Discovery (
-sn) or-Pnif the target filters ICMP and the range is small. - Pass 1: full TCP ports, fast, no versions.
- Pass 2:
-sV -sCon the open ones; bounded UDP. - NSE driven by service;
vulnonly if the engagement covers it. - Save everything with
-oAand a date; the XML feeds the other tools. - Move on to service enumeration.
nmap(7.993 as of Oct 2026): scanning, versions, NSE.masscan,rustscan: very fast port discovery; thennmap -sVon the result. RustScan is officially distributed only viacargo install rustscan.ncat/nc: banners by hand;xsltproc: HTML report from the XML.- Metasploit
db_nmap/db_import: results into the framework’s database.
Impact and chaining
Section titled “Impact and chaining”The scan is not a finding in itself: it is the map. Findings come from what follows: enumeration of each service, common ports and services, and from a shell, the same scan repeated from the inside through a pivot to discover the internal network.
Blue Team
Section titled “Blue Team”Detection
Section titled “Detection”- Pattern: one source touching many ports of one destination (port scan) or one port of
many destinations (sweep) in a short time; SYN with no later ACK;
connect()calls closed with no data. - Signatures: Suricata’s ET Open ruleset has the ET SCAN category (for instance
ET SCAN Possible Nmap User-Agent Observed when
-sVor NSE touch HTTP). “Normal” SYN scans generate many low-value alerts, and slow ones (-T1/-T2) pass under the default thresholds. - Thresholds: rules with
thresholdper source (N ports in M seconds) in Suricata/Snort, and SIEM correlation of firewall deny events per source. - On the host: application logs (
-sTleaves full connections), Windows EID 5156 (filtering platform) andauditdfor rejected inbound connections.
Telemetry and sources
Section titled “Telemetry and sources”NetFlow/Zeek (conn.log with many S0/REJ connections), firewall logs with denials, IDS at
the perimeter and on internal segments, honeypots with ports nobody legitimate should touch.
Hardening
Section titled “Hardening”- Expose only what is needed: every closed service is a port nobody has to watch.
- Default-deny inbound and segmentation: a scan from a compromised host should not see the whole network.
- Rate limiting of new connections per source on the firewall.
- Banners without version where the software allows it; it does not stop
-sV, but it reduces what is handed out for free.
Response
Section titled “Response”An internal scan from a host that is not a security asset is an indicator of compromise: isolate the source and review what came before (phishing, credentials). A massive external scan is Internet background noise and is handled by thresholds, not by alert.
CVEs and real cases
Section titled “CVEs and real cases”- Log4Shell (CVE-2021-44228, Dec 2021): within days, community NSE scripts appeared
(Diverto
nse-log4shell, giterlizzinmap-log4shell) that injected the JNDI payload over HTTP, SSH and IMAP with a callback server; Nmap was one of the mass-triage routes, and the same pattern repeats with every critical network-exposed CVE. - Nmap 7.993 (Oct 23, 2026): fixes a regression that prevented most
version-category scripts from running. A reminder that the Nmap version influences results: note which one you used in the report.
Testing checklist
Section titled “Testing checklist”- Scope in a file and exclusions applied; Nmap version noted.
- Discovery done or
-Pnjustified. - Pass 1 full TCP ports (
-p-) with reasonable--min-rateand--max-retries. - Pass 2
-sV -sC -Oonly on open ports. - Bounded UDP (
--top-ports) with--open. - NSE by service; intrusive categories only with authorization.
- Everything saved with
-oA; port list extracted from the.gnmap.
References
Section titled “References”- Nmap Reference Guide — Port Scanning Techniques: https://nmap.org/book/man-port-scanning-techniques.html
- Nmap Reference Guide — Host Discovery: https://nmap.org/book/man-host-discovery.html
- Nmap Reference Guide — Timing and Performance: https://nmap.org/book/man-performance.html
- Nmap Reference Guide — Firewall/IDS Evasion and Spoofing: https://nmap.org/book/man-bypass-firewalls-ids.html
- Nmap Network Scanning — NSE Usage (categories): https://nmap.org/book/nse-usage.html
- Nmap Changelog (7.993, Oct 23, 2026): https://nmap.org/changelog.html
- NSEDoc: https://nmap.org/nsedoc/
- RustScan: https://github.com/RustScan/RustScan
- MITRE ATT&CK T1046 Network Service Discovery: https://attack.mitre.org/techniques/T1046/