Nmap (“Network Mapper”) is a free, open-source utility for network discovery and security auditing. It sends specially crafted packets to target hosts and analyzes the responses to determine which hosts are reachable, which ports are open, which services and versions are running, and — with varying reliability — which operating system a host is running.
Nmap was originally released in 1997 by Gordon Lyon (known in the security community by the handle “Fyodor”), initially published as an article and tool in Phrack magazine. Over more than two decades it has grown from a simple port scanner into a full scanning platform that includes the Nmap Scripting Engine (NSE), an OS/service fingerprinting database, and both a command-line interface and a graphical front end (Zenmap).
Authorization Notice: Every command, technique, and scenario in this guide assumes you own the target systems/network or have explicit written authorization to test them. Scanning systems you do not have permission to test can violate computer-crime laws (e.g., the U.S. Computer Fraud and Abuse Act, the UK Computer Misuse Act, and equivalents elsewhere) even when no damage occurs. All example targets below are private/lab addresses (127.0.0.1, 192.168.56.0/24, 10.10.10.0/24, documentation IPv6 ranges) or clearly fictional lab hostnames.
1. Problems Nmap solves:
- Discovering what is actually alive and reachable on a network, as opposed to what documentation claims should be there.
- Enumerating open ports and the services bound to them.
- Identifying software versions for vulnerability triage and asset inventory.
- Providing a scriptable framework (NSE) for deeper service-specific checks.
- Supplying machine-readable output for integration into larger security tooling.
Who uses Nmap:
Penetration testers, red teams, SOC analysts, incident responders, network engineers, sysadmins, DevOps/security engineers doing asset inventory, students learning networking and security, and bug-bounty researchers operating within scope.
Legitimate use cases: authorized penetration testing, internal asset inventory, firewall rule verification, change management validation, incident investigation, network segmentation testing, and pre/post-remediation verification.
Nmap vs. vulnerability scanners:
Tools like Nessus, OpenVAS, or Qualys are built to identify known vulnerabilities (CVEs) against services, often using authenticated checks and vulnerability databases. Nmap’s core purpose is discovery and enumeration — determining what exists on the network and how it responds. NSE’s vuln category scripts add some vulnerability-detection capability, but Nmap is not a substitute for a dedicated vulnerability management platform.
Nmap vs. simple port scanners:
Basic port scanners (e.g., a raw TCP connect loop) only report open/closed. Nmap adds host discovery, multiple scan techniques with different packet semantics, service/version detection, OS fingerprinting, NSE scripting, and structured output formats.
Limitations:
Nmap cannot guarantee 100% accurate OS or service identification, cannot bypass a properly configured stateful firewall by “stealth” alone, cannot see into encrypted payloads to identify application-layer vulnerabilities, and its results reflect the network path and its filtering devices at the time of the scan, not a permanent state.
2. Nmap Fundamentals
| Term | Definition |
|---|---|
| Host | Any addressable device on a network (server, workstation, router, IoT device). |
| IP address | A numeric address (IPv4: e.g., 192.168.1.10; IPv6: e.g., fe80::1) identifying a host on a network. |
| MAC address | A hardware address burned into a network interface, used at Layer 2 (Ethernet). Nmap can usually only see MAC addresses on the local Ethernet segment. |
| Port | A 16-bit number (0–65535) identifying a specific communication endpoint on a host for a given protocol. |
| TCP | Transmission Control Protocol — connection-oriented, reliable, ordered delivery. |
| UDP | User Datagram Protocol — connectionless, no delivery guarantee, lower overhead. |
| TCP three-way handshake | SYN → SYN/ACK → ACK. Used to establish a full TCP connection. Nmap’s SYN scan exploits this without completing it. |
| Service | The application bound to a port (e.g., SSH on 22, HTTP on 80). |
| Protocol | The rules governing communication (TCP, UDP, ICMP, ARP, etc.). |
| Open | A service is actively accepting connections on that port. |
| Closed | The port is reachable, but no service is listening (host responds with RST for TCP). |
| Filtered | Nmap cannot determine open/closed because packets are being dropped or blocked, usually by a firewall. |
| Open|filtered | Nmap cannot tell whether the port is open or filtered — common with UDP scans and scans that get no response at all. |
| Closed|filtered | Rare state (mainly seen in IP ID idle scans) where Nmap can’t distinguish closed from filtered. |
| Host discovery | Determining which hosts are online before/instead of port scanning. |
| Port scanning | Probing ports to determine their state. |
| Service detection | Probing an open port further to identify the specific application and version. |
| OS detection | Analyzing TCP/IP stack behavior to guess the target’s operating system. |
| NSE | Nmap Scripting Engine — a Lua-based framework for extending Nmap’s functionality. |
| Fingerprinting | Comparing observed behavior (packet structure, response timing, banners) against a reference database to identify software or OS. |
3. How Nmap Works
A typical Nmap scan proceeds through these conceptual stages:
- Target resolution — Hostnames are resolved to IP addresses (unless
-nis used); target expressions (CIDR, ranges, lists) are expanded into individual IPs. - Host discovery — Unless
-Pnis set, Nmap tries to determine which hosts are up, using ARP (on local networks), ICMP echo, and/or TCP/UDP probes to common ports. - Port selection — Based on
-p,-F,--top-ports, or the default port list, Nmap decides which ports to probe on each live host. - Probe transmission — Nmap sends crafted packets, varying by scan type (SYN packets, full connect attempts, UDP datagrams, FIN/NULL/Xmas flag combinations).
- Response analysis — Nmap classifies each port based on the response (or lack of one): SYN/ACK, RST, ICMP unreachable, no response, etc.
- Port-state classification — Ports are labeled open, closed, filtered, or one of the ambiguous states.
- Service detection (
-sV) — If requested, Nmap sends protocol-specific probes to open ports and compares responses against its service-probes database. - OS fingerprinting (
-O) — If requested, Nmap sends a sequence of TCP/UDP/ICMP probes designed to reveal stack-implementation quirks, then compares the fingerprint to its OS database. - NSE processing — If scripts are requested (
--script), they run against hosts/ports matching their category and rule requirements. - Result generation — Nmap assembles console output and/or the requested output files (
-oN,-oX,-oG,-oA).
ARP is used for discovery on local Ethernet segments (fast and reliable, since it operates below IP filtering). ICMP echo/timestamp/netmask requests may be used off-segment for discovery, though many networks filter ICMP. DNS is used for hostname resolution and (optionally) reverse lookups. TCP and UDP probes are the basis of port scanning itself.
4. Nmap Installation
| Platform | Command | Verify |
|---|---|---|
| Kali Linux | Usually preinstalled. sudo apt update && sudo apt install nmap | nmap --version |
| Debian/Ubuntu | sudo apt update && sudo apt install nmap | nmap --version |
| Fedora/RHEL-based | sudo dnf install nmap | nmap --version |
| Arch Linux | sudo pacman -S nmap | nmap --version |
| Windows | Download the official installer (.exe) from nmap.org, which also installs Npcap for raw packet capture | nmap --version in Command Prompt/PowerShell |
| macOS | brew install nmap (Homebrew) or the official .dmg installer from nmap.org | nmap --version |
| From source | ./configure && make && sudo make install from the extracted nmap source tarball | nmap --version |
Common installation problems:
- Missing raw-socket privileges (
-sS,-O, and most raw-packet features require root/Administrator or, on Linux, theCAP_NET_RAWcapability). - On Windows, missing or outdated Npcap causes raw scanning to fail — reinstall Npcap from the official Nmap distribution.
- Outdated distro packages ship old Nmap versions with older NSE script sets; building from source or using the official packages gets you current scripts and probes.
- On Linux,
sudo nmap --versionvsnmap --versioncan differ if two Nmap binaries exist on the PATH — check withwhich nmap.
5. Basic Syntax of Nmap
nmap [Scan Type(s)] [Options] {target specification}- Scan Type(s) — e.g.,
-sS,-sT,-sU— determines the packet-level technique used. - Options — modify behavior: port selection, timing, output, detection features, NSE, etc.
- Target specification — one or more hosts, ranges, CIDR blocks, or an input file.
Examples using safe lab targets:
nmap 127.0.0.1
nmap -sS 192.168.56.10
nmap -sV -p 22,80,443 10.10.10.206. Target Specification of Nmap
| Form | Example | Notes |
|---|---|---|
| Single IP | nmap 192.168.56.10 | Direct address, no resolution needed. |
| Hostname | nmap lab-server.local | Requires DNS resolution unless -n is set. |
| Multiple IPs | nmap 192.168.56.10 192.168.56.11 | Space-separated. |
| IP range | nmap 192.168.56.10-20 | Last octet range shorthand. |
| CIDR notation | nmap 192.168.56.0/24 | Scans the whole subnet (254 usable hosts for /24). |
| Multiple targets mixed | nmap 192.168.56.10 10.10.10.0/28 | Any combination of the above forms. |
| Input file | nmap -iL targets.txt | One target per line; supports hostnames, IPs, ranges, CIDR. |
| Exclusion | nmap 192.168.56.0/24 --exclude 192.168.56.1 | Excludes specific hosts from an otherwise larger scan. |
| Exclusion file | nmap 192.168.56.0/24 --excludefile exclude.txt | Same idea, from a file. |
| IPv6 | nmap -6 fe80::1 | Requires -6 explicitly; see Section 27. |
| Random targets (caution) | nmap -iR 10 | Picks random public IPs — not appropriate outside dedicated research infrastructure with authorization; do not use against the general internet. |
DNS resolution behavior: By default Nmap resolves hostnames to IPs and performs reverse DNS (PTR) lookups on discovered live hosts unless -n (no DNS) is used. -R forces reverse DNS resolution for all targets, even ones that don’t appear to be up. DNS lookups add latency; for large scans, -n is common in professional workflows once target IPs are already known.
Wildcard/CIDR caveat: A /24 scan targets every address in that block, including network/broadcast addresses in some contexts — always confirm scope boundaries before scanning shared or third-party-adjacent ranges.
7. Host Discovery
| Option | What it sends | Protocol | When to use |
|---|---|---|---|
-Pn | Nothing — skips discovery, treats all targets as up | N/A | Host blocks ping/ICMP but you know it’s up; avoids false “host down” results. |
-sn | Discovery probes only, no port scan | ARP/ICMP/TCP/UDP | Quick “what’s alive” sweep of a subnet. |
-PE | ICMP echo request | ICMP | Classic ping-based discovery; often blocked by firewalls. |
-PP | ICMP timestamp request | ICMP | Alternative when echo is blocked but timestamp isn’t. |
-PS<ports> | TCP SYN to specified ports | TCP | Discovery through firewalls that block ICMP but allow certain TCP ports (e.g., 80, 443). |
-PA<ports> | TCP ACK to specified ports | TCP | Useful against stateless filters that only block inbound SYN. |
-PU<ports> | UDP probes | UDP | Discovery via UDP responses (ICMP port-unreachable = host up). |
-PR | ARP requests | ARP | Default and most reliable method for local Ethernet segments. |
-n | (no probe) | — | Disables DNS resolution entirely (also affects discovery speed). |
-R | (no probe) | — | Forces reverse-DNS resolution for all targets. |
--dns-servers <servers> | — | — | Use specific DNS servers instead of system defaults. |
--system-dns | — | — | Use the OS’s own resolver instead of Nmap’s built-in resolver. |
Example:
nmap -sn 192.168.56.0/24This performs discovery only (no ports scanned), useful for quickly mapping which lab hosts are online.
Why a host may appear “down” when it’s actually online: many hosts and intermediate firewalls silently drop ICMP echo requests, so a default ping-based discovery probe gets no reply even though the host is fully reachable on TCP/UDP. This is why professionals often combine -Pn with targeted TCP/UDP discovery probes, or skip discovery entirely on known-live hosts.
Safety note: Host discovery still generates network traffic and log entries; even a light -sn sweep should be within authorized scope.
8. Port Specification and Scanning
| Option | Meaning | Example |
|---|---|---|
-p <ports> | Specific ports | -p 22,80,443 |
-p- | All 65535 TCP ports | -p- 192.168.56.10 |
-F | Fast mode — scans the 100 most common ports | -F 192.168.56.10 |
--top-ports <n> | Scans the n most common ports per Nmap’s frequency database | --top-ports 20 |
-r | Scan ports in sequential order rather than randomized | -r |
--exclude-ports <ports> | Excludes specific ports from an otherwise larger scan | --exclude-ports 25 |
Port ranges use hyphens (-p 1-1024), and UDP/TCP can be mixed with prefixes: -p U:53,T:21-25. Choosing the right port set is a balance: -F or --top-ports is fast and often sufficient for triage, while -p- is thorough but slow, especially combined with -sV/-O/NSE.
9. TCP Scan Techniques
| Flag | Technique | How it works | Privilege | Typical use |
|---|---|---|---|---|
-sS | SYN scan (“half-open”) | Sends SYN; open = SYN/ACK (Nmap sends RST to tear down, never completing handshake); closed = RST | Requires raw-socket privileges (root/Admin) | Default, fastest, most common professional scan |
-sT | Connect scan | Uses the OS’s full connect() call — completes the handshake | No special privileges needed | Used when raw sockets aren’t available (unprivileged users, some containers) |
-sA | ACK scan | Sends ACK only; used to map firewall rule sets (stateful vs stateless), not to determine open/closed | Requires raw sockets | Firewall-rule mapping, not general port scanning |
-sW | Window scan | Like ACK scan, but examines TCP window size in the RST response to sometimes infer open ports on certain stacks | Requires raw sockets | Niche; unreliable on modern stacks |
-sM | Maimon scan | Sends FIN/ACK; some BSD-derived stacks respond in ways that reveal open ports | Requires raw sockets | Rare/legacy use |
-sN | NULL scan | No flags set | Requires raw sockets | Firewall/IDS evasion research on compliant (mostly older/Unix-like) stacks; unreliable against modern stateful firewalls and Windows |
-sF | FIN scan | FIN flag only | Requires raw sockets | Same caveats as NULL scan |
-sX | Xmas scan | FIN, PSH, URG flags set | Requires raw sockets | Same caveats as NULL/FIN |
Interpretation basics: For -sS/-sT, an open port typically shows open; a closed port responding with RST shows closed; no response (dropped by a filter) shows filtered. NULL/FIN/Xmas scans rely on RFC 793 behavior where closed ports should send RST and open ports send nothing — many modern stacks (notably Windows) do not follow this behavior reliably, so these scans mostly show open|filtered against them and should not be treated as dependable techniques on modern networks.
Example:
sudo nmap -sS 192.168.56.10Note on “stealth”: None of these techniques guarantee evasion of a modern IDS/IPS or a well-configured stateful firewall. Historic “stealth scan” terminology for -sS refers only to not completing the TCP handshake at the application layer — it is still visible at the packet-capture/IDS level.
10. UDP Scanning
sudo nmap -sU -p 53,67,123,161 192.168.56.10UDP scanning is inherently slower and less precise than TCP scanning because UDP has no handshake and many services don’t respond to empty probes. Nmap’s logic:
- If it gets a UDP response back from the service: open.
- If it gets an ICMP “port unreachable” (Type 3, Code 3): closed.
- If it gets no response at all (extremely common — many hosts rate-limit or don’t send ICMP unreachables): open|filtered — Nmap genuinely cannot distinguish “open, but the service doesn’t respond to an empty/generic probe” from “filtered by a firewall.”
Because of rate-limiting on ICMP unreachable messages by many OSes, large UDP scans (-sU -p-) can take a very long time. Best practice is to scan a curated set of UDP ports relevant to expected services (DNS/53, SNMP/161, NTP/123, DHCP/67-68) rather than all 65535.
Combining with TCP for full coverage:
sudo nmap -sS -sU -p T:22,80,443,U:53,161 192.168.56.1011. Combining Scan Types
| Combination | Purpose |
|---|---|
-sS -sU | Full TCP+UDP port-state assessment in one run |
-sS -sV | Port state plus service/version identification |
-sS -O | Port state plus OS fingerprint |
-sS -sV -O | Comprehensive single-pass enumeration |
-sS -sV --script=default | Adds default NSE checks to standard enumeration |
Combining is useful when you want a single comprehensive pass and can tolerate the added scan time; it creates unnecessary traffic/time when you only need a quick “is anything listening” answer (in which case -sS -F or -sn alone is more appropriate).
12. Service and Version Detection using Nmap
sudo nmap -sV --version-intensity 7 192.168.56.10| Option | Effect |
|---|---|
-sV | Enables version detection |
--version-intensity <0-9> | Controls how many probes are tried (0 = lightest/fastest, 9 = most thorough) |
--version-light | Shortcut for low intensity (fast, less accurate) |
--version-all | Shortcut for maximum intensity |
--version-trace | Prints detailed debugging of the version-detection process |
Methodology: After a port is found open, Nmap sends a series of protocol-specific probes from its nmap-service-probes database and compares the response against known regex signatures to identify product, version, and sometimes extra info (hostname, OS hints).
Why it can be inaccurate: custom banners, proxying/load balancers, non-standard ports, rate-limiting, or services that don’t match any known signature can cause misidentification or an “unknown” result. Version detection should inform, not replace, manual verification for critical findings.
Administrators can use version output for asset inventory (tracking which software versions are actually deployed) and to flag unexpectedly old or unauthorized software versions.
13. Nmap – Operating System Detection
sudo nmap -O --osscan-guess 192.168.56.10| Option | Effect |
|---|---|
-O | Enables OS detection |
--osscan-limit | Only attempts OS detection on hosts meeting certain criteria (at least one open and one closed port) — saves time on large scans |
--osscan-guess | Makes Nmap guess more aggressively when there’s no exact fingerprint match |
--max-os-tries <n> | Limits retry attempts, trading accuracy for speed |
--osscan-verbose | Prints more detail about the fingerprinting process |
How it works:
Nmap sends a sequence of TCP, UDP, and ICMP probes designed to expose subtle stack-implementation differences (initial window size, TCP options ordering, ISN generation, TTL, etc.), then compares the resulting fingerprint against nmap-os-db.
Why it can fail:
Insufficient open/closed ports to fingerprint against, network middleboxes normalizing packets, virtualization/NAT altering behavior, or simply no matching signature in the database (common for newer or heavily customized OS builds). Nmap reports a best-guess with a percentage confidence, or “No exact OS matches” when uncertain — treat both as probabilistic, not authoritative.
14. Nmap Scripting Engine (NSE)
NSE is a Lua-based framework that lets Nmap run modular scripts for discovery, deeper auditing, vulnerability checks, and more, extending far beyond basic port/service detection.
Script categories:
| Category | Purpose | Caution level |
|---|---|---|
auth | Authentication-related checks (e.g., default credentials) | Use only in authorized environments |
broadcast | Discovers hosts via broadcast/multicast protocols | Generates network-wide traffic |
brute | Brute-force credential guessing | Intrusive — authorized labs only |
default | Curated safe-and-useful scripts run by -sC/-A | Safe |
discovery | Gathers additional info about hosts/services | Generally safe |
dos | Denial-of-service testing scripts | Disruptive — controlled lab only, never production |
exploit | Attempts active exploitation | High risk — authorized penetration test only |
external | Sends data to third-party services (e.g., WHOIS) | May leak target info externally |
fuzzer | Sends malformed/random data to find crashes | Disruptive — lab only |
intrusive | Scripts that may crash services or be noisy | Authorized testing only |
malware | Checks for signs of malware/backdoors | Generally safe |
safe | Designed not to crash or disrupt services | Safe |
version | Extends service/version detection | Safe |
vuln | Checks for specific known vulnerabilities | Can be intrusive depending on script; lab/authorized use |
Key options:
| Option | Purpose |
|---|---|
--script <name/category> | Selects which script(s) to run |
--script-help <name> | Displays help text for a script |
--script-args <args> | Passes arguments to scripts |
--script-args-file <file> | Loads script arguments from a file |
--script-trace | Shows raw data sent/received by scripts (debugging) |
--script-updatedb | Rebuilds the script database after adding/removing scripts |
Safe example:
sudo nmap -sV --script=default,safe 192.168.56.10WARNING:
brute,dos,exploit,fuzzer, and manyintrusive/vulnscripts can crash services or trigger account lockouts. Only run these against systems you own or are explicitly authorized to test aggressively, ideally in an isolated lab.
15. Important NSE Scripts for Nmap
| Script | Category | Purpose | Example |
|---|---|---|---|
http-title | discovery | Grabs the <title> of a web page | --script http-title -p80 |
http-headers | safe | Retrieves HTTP response headers | --script http-headers -p80 |
ssl-cert | safe | Retrieves and parses TLS certificate details | --script ssl-cert -p443 |
ssh-hostkey | safe/discovery | Retrieves SSH host key fingerprints | --script ssh-hostkey -p22 |
dns-brute | intrusive/discovery | Brute-forces subdomains via DNS (authorized domains only) | --script dns-brute |
smb-os-discovery | discovery/safe | Gathers OS info via SMB | --script smb-os-discovery -p445 |
banner | discovery/safe | Grabs raw service banners | --script banner |
vulners | vuln | Cross-references detected versions against known CVEs (requires internet access) | --script vulners --script-args mincvss=7.0 |
ftp-anon | auth/safe | Checks for anonymous FTP login | --script ftp-anon -p21 |
All output should be interpreted as a starting point for manual verification, not a definitive vulnerability report. Scripts that reach out externally (e.g., vulners) transmit version data off-host — be mindful of data-handling policy in sensitive environments.
16. The Default Nmap Scan
nmap 192.168.56.10With no scan-type flag, an unprivileged user gets a connect scan (-sT); a privileged (root/Administrator) user gets a SYN scan (-sS). By default Nmap:
- Performs host discovery (ARP if on the local segment, otherwise ICMP/TCP probes) unless
-Pnis given. - Scans the default top 1000 TCP ports, not all 65535.
- Performs a normal (forward and reverse) DNS resolution pass on live hosts.
- Prints a human-readable table of port/state/service to the console.
Results differ by environment because privilege level changes the default scan technique, and network path (local Ethernet vs. routed) changes which discovery method is used.
17. Common Practical Scans using Nmap
| # | Command | What it does | Notes |
|---|---|---|---|
| 1 | nmap 192.168.56.10 | Basic default scan | Top 1000 TCP ports |
| 2 | nmap -sn 192.168.56.0/24 | Ping-style discovery only | No port scan |
| 3 | sudo nmap -sS 192.168.56.10 | TCP SYN scan | Requires privileges |
| 4 | nmap -sT 192.168.56.10 | TCP connect scan | No privileges needed |
| 5 | sudo nmap -p- 192.168.56.10 | Full 65535 TCP port scan | Slow but thorough |
| 6 | nmap --top-ports 50 192.168.56.10 | Top 50 common ports | Fast triage |
| 7 | nmap -F 192.168.56.10 | Fast scan, top 100 ports | Quick overview |
| 8 | sudo nmap -sU --top-ports 20 192.168.56.10 | UDP scan of top 20 ports | Slower than TCP |
| 9 | sudo nmap -sS -sU -p T:22,80,U:53,161 192.168.56.10 | Combined TCP+UDP assessment | Targeted ports |
| 10 | sudo nmap -sV 192.168.56.10 | Service/version detection | Adds banner/probe time |
| 11 | sudo nmap -O 192.168.56.10 | OS detection | Probabilistic result |
| 12 | sudo nmap -A 192.168.56.10 | Aggressive scan (OS, version, default scripts, traceroute) | Noisy, thorough, not for stealth |
| 13 | nmap -p 443 192.168.56.10 | Specific port scan | Single port |
| 14 | nmap -p 22,80,443 192.168.56.10 | Multiple ports | Comma-separated |
| 15 | nmap -p 1-1024 192.168.56.10 | Port range scan | Well-known port range |
| 16 | nmap -sn 10.10.10.0/24 | Network range discovery | Subnet sweep |
| 17 | nmap -iL targets.txt | Input file scanning | Batch targets |
| 18 | nmap 192.168.56.0/24 --exclude 192.168.56.1 | Excluding hosts | Skip gateway/router |
| 19 | nmap -6 fe80::1%eth0 | IPv6 scanning | Link-local needs zone/interface |
| 20 | nmap -R 192.168.56.10 | Force reverse DNS | Even if host looks down |
| 21 | nmap -oN scan.txt 192.168.56.10 | Normal text output | Human-readable file |
| 22 | nmap -oX scan.xml 192.168.56.10 | XML output | For automation/parsing |
| 23 | nmap -oG scan.gnmap 192.168.56.10 | Grepable output | Legacy, still used in quick shell pipelines |
| 24 | nmap -oA scan_results 192.168.56.10 | All formats at once | Writes .nmap, .xml, .gnmap |
| 25 | nmap -v 192.168.56.10 | Verbose mode | More progress detail |
| 26 | nmap -d 192.168.56.10 | Debug mode | Deep internal detail |
| 27 | nmap --packet-trace 192.168.56.10 | Packet tracing | Shows raw packets sent/received |
| 28 | nmap -T4 192.168.56.10 | Faster timing template | Balances speed/reliability |
Each command should be validated against the actual response — e.g., confirm filtered results aren’t simply due to an overly aggressive timing template dropping legitimate probes, especially on congested or rate-limited lab networks.
18. Timing and Performance
| Template | Description |
|---|---|
-T0 (Paranoid) | Extremely slow, for maximum evasion/stealth logging avoidance |
-T1 (Sneaky) | Very slow |
-T2 (Polite) | Slower, reduces load on target/network |
-T3 (Normal) | Default |
-T4 (Aggressive) | Faster, assumes a reliable, low-latency network |
-T5 (Insane) | Fastest, sacrifices accuracy for speed |
Additional fine-grained controls: --min-hostgroup/--max-hostgroup (parallel host batch size), --min-parallelism/--max-parallelism (concurrent probes), --min-rtt-timeout/--max-rtt-timeout/--initial-rtt-timeout (round-trip timeout tuning), --max-retries (probe retransmission limit), --host-timeout (give up on a slow host after N time), --scan-delay/--max-scan-delay (forced delay between probes, useful against rate-limiting targets), --defeat-rst-ratelimit (tells Nmap to proceed despite detecting RST rate-limiting, at some accuracy cost).
Aggressive timing (-T4/-T5) on unreliable networks or rate-limited targets increases false “filtered”/”closed” results because legitimate responses get dropped or delayed past the timeout window. On a lab or trusted internal network, -T4 is a common professional default; -T5 is rarely worth the accuracy tradeoff.
19. Firewalls, IDS, and IPS
Firewalls and other filtering devices materially change what Nmap sees:
- Stateful firewalls track connection state and typically drop unsolicited SYN/ACK-less packets — this is why SYN scans often show
filteredfor protected ports. - Stateless filters (simple ACLs) may only block specific flag combinations, which is why ACK scans (
-sA) are sometimes used to map rule sets rather than determine open/closed state. - IDS/IPS systems may detect scan patterns (many SYNs to sequential ports in a short window) regardless of which scan flag is used, and may respond by rate-limiting, resetting connections, or alerting security teams.
- Rate limiting on ICMP or TCP RST responses (common on modern OSes and firewalls) is a frequent cause of “false” open|filtered/filtered results, especially in UDP scans.
- False positives/negatives occur when filtering devices inject responses (a firewall sending RST on behalf of a blocked host) or silently drop everything (making an open port look identical to a filtered one).
From a security-auditing perspective, understanding this behavior helps administrators validate that firewall rules are actually doing what’s intended (e.g., confirming that only 443 is reachable from outside, and 22 is properly restricted). This guide does not provide techniques for defeating a real organization’s production security controls without authorization.
20. Output and Result Interpretation
Example output (fictional lab host):
Nmap scan report for lab-web01.internal (192.168.56.10)
Host is up (0.0012s latency).
Not shown: 996 closed tcp ports (reset)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 9.6 (protocol 2.0)
80/tcp open http Apache httpd 2.4.58
443/tcp open ssl/http Apache httpd 2.4.58
3306/tcp filtered mysql
MAC Address: 08:00:27:AA:BB:CC (Oracle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 5.X
OS details: Linux 5.0 - 5.14
Network Distance: 1 hop
(Labeled here explicitly as example output — actual results vary by environment.)
- Host is up / latency — Confirms reachability and round-trip time.
- PORT — Port number and protocol.
- STATE — open / closed / filtered / open|filtered / closed|filtered / unfiltered.
- SERVICE — Nmap’s best guess of the running service, from the port-to-service mapping or
-sVprobing. - VERSION — Product/version string from
-sV, when identifiable. - MAC Address — Only shown for local-segment targets (ARP-visible), includes vendor lookup.
- Device type / Running / OS details — From
-OOS fingerprinting, shown with varying confidence. - Network distance — Estimated hop count (from TTL analysis / traceroute).
Port states in full:
open— an application is actively listening.closed— reachable but nothing is listening (TCP RST received).filtered— Nmap can’t tell if open or closed; something is blocking probes.unfiltered— reachable and responsive, but state (open/closed) can’t be determined (mainly from ACK scans).open|filtered— no response received; could be an open UDP port or a filtered one.closed|filtered— ambiguous state seen mainly with idle/zombie scans.
21. Output Formats
| Flag | Format | Best for |
|---|---|---|
-oN <file> | Normal (human-readable) | Manual review, reports |
-oX <file> | XML | Automation, SIEM ingestion, parsing scripts |
-oG <file> | Grepable (legacy) | Quick shell one-liners (grep/awk) |
-oA <basename> | All three formats at once | General best practice — keep everything |
Verbosity/debug: -v / -vv (more progress info), -d / -dd (deep internal debugging output), --reason (shows why a state was assigned, e.g., “syn-ack” vs “no-response”), --open (only show open ports), --packet-trace (dump raw packets sent/received).
For human review, -oN or console output is sufficient. For automation and SIEM/security workflows, -oX is strongly preferred since it’s structured and stable to parse. For reporting, combine -oA with --reason to preserve the evidentiary basis for each finding.
22. XML and Automation
Python (using the standard library xml.etree):
import xml.etree.ElementTree as ET
tree = ET.parse("scan.xml")
for host in tree.findall("host"):
addr = host.find("address").get("addr")
for port in host.findall(".//port"):
state = port.find("state").get("state")
portid = port.get("portid")
print(addr, portid, state)Bash (grepable output, legacy but quick):
nmap -oG - 192.168.56.10 | grep "/open/"Basic command-line XML inspection:
xmllint --format scan.xml | lessThese patterns are meant for parsing your own authorized-scan results into dashboards, tickets, or diffing tools — not for building unauthorized scanning infrastructure.
23. Nmap Diagnostics and Troubleshooting
| Symptom | Likely cause | Diagnostic step |
|---|---|---|
| “Note: Host seems down” | ICMP blocked, host actually up | Retry with -Pn |
| Permission/”requires root” errors | Raw-socket features need elevated privileges | Run with sudo (Linux/macOS) or as Administrator (Windows) |
| Raw packet send errors | Npcap/libpcap missing or misconfigured | Reinstall Npcap (Windows) or check libpcap install (Linux) |
| DNS resolution failures | Bad resolver/network config | Try -n to bypass DNS, or --dns-servers |
| Slow UDP scans | ICMP rate limiting on target | Reduce port count, add --defeat-rst-ratelimit if RST-related, increase --host-timeout patience |
| No open ports found | Firewall dropping everything, or wrong port range | Try -p-, confirm with -Pn, check --reason |
| Incorrect service detection | Non-standard port, custom banner | Increase --version-intensity, manually verify with a raw connection (e.g., nc) |
| OS detection failure | Insufficient fingerprint match | Use --osscan-guess, ensure at least one open and one closed port exist |
| Firewall interference | Mid-path filtering device | Compare results from different network vantage points if authorized |
| IPv6 issues | Missing -6 flag, link-local zone ID missing | Add -6, specify %interface for link-local addresses |
| Interface selection problems | Multiple NICs, wrong route | Use -e <interface> to force |
| VM networking issues | NAT vs bridged mode affecting visibility | Switch VM network mode to bridged for realistic scans |
| Wireless interface issues | Some wireless drivers limit raw packet injection | Test scan from a wired interface if raw scanning fails |
| Script/database issues | Corrupted or outdated NSE db | Run --script-updatedb, reinstall Nmap |
24. Network Interfaces and Routing
| Option | Purpose |
|---|---|
-e <iface> | Force a specific network interface |
-S <ip> | Spoof/set the source IP (legitimate uses: multi-homed hosts, routing tests) |
-g <port> / --source-port <port> | Set a fixed source port (useful for testing firewall rules that trust specific source ports) |
--send-eth | Send raw Ethernet frames |
--send-ip | Send raw IP packets (skip Ethernet-layer framing) |
--route | (informational) review your OS-level routing table when diagnosing why traffic isn’t reaching a target |
These are primarily for legitimate network-configuration testing (verifying multi-homed routing, confirming a firewall rule that trusts a specific source port) — not for spoofing identity to evade attribution.
25. MAC Address and ARP
On a local Ethernet segment, Nmap uses ARP to discover hosts (fast, reliable, and not blockable by IP-layer firewalls). Discovered hosts show a MAC address and, via Nmap’s vendor database, the NIC manufacturer. MAC visibility requires:
- you’re on the same broadcast domain, and
- sufficient privileges to read raw frames.
Off-segment (routed) targets never show a real MAC address — you’ll only ever see the MAC of your default gateway, if anything. Virtual machines commonly show vendor strings like “Oracle VirtualBox” or “VMware.” Wireless networks may show inconsistent MAC visibility depending on driver/monitor-mode support. A MAC never being “spoofed” by Nmap’s own logic — if a MAC looks unusual, it reflects the actual NIC or its configured override, not a scan artifact.
26. DNS with Nmap
-ndisables all DNS resolution (fastest, useful when you already have IPs).-Rforces reverse-DNS lookups even for hosts that don’t appear to respond to discovery.--dns-servers <ip1,ip2>directs lookups to specific resolvers (useful in internal-only DNS environments).--system-dnsuses the OS resolver instead of Nmap’s parallel internal resolver (slower but sometimes more accurate in restrictive environments).
DNS resolution adds latency to large scans; disabling it (-n) is standard practice once target IPs are confirmed. Reverse DNS names in output can aid identification but should not be assumed accurate — PTR records are sometimes stale or misconfigured.
27. IPv6
nmap -6 2001:db8::10-6 must be explicitly specified — Nmap does not scan IPv6 by default. Host discovery over IPv6 relies more heavily on ICMPv6 (neighbor discovery on-link, echo requests off-link) since ARP doesn’t exist in IPv6. Port scanning syntax is otherwise identical to IPv4 (-p, -sS, -sV, etc. all apply). Key differences from IPv4: address space is vastly larger (making blind sweeps impractical — target lists/DNS become more important), link-local addresses (fe80::/10) require a zone/interface identifier (e.g., fe80::1%eth0), and NAT is far less common, so hosts are often more directly reachable.
28. Nmap Databases and Fingerprinting
nmap-service-probes— probe strings and regex signatures used by-sVto identify services/versions.nmap-os-db— reference fingerprints used by-Ofor OS matching.nmap-mac-prefixes— maps MAC address OUI prefixes to hardware vendors.
When a service or OS doesn’t match any known signature, Nmap reports “unknown” or a best-effort guess and — with user consent — can prompt to submit the new fingerprint back to the Nmap project to improve future databases. Because software and OS releases constantly change subtle behaviors, these databases are inherently a step behind the newest releases, which is a normal and expected limitation.
29. Performance Engineering
Recommended scan design for efficiency:
- Start with discovery (
-sn) to avoid wasting time on dead hosts. - Scan a relevant port set first (
-F/--top-ports) before committing to-p-. - Add
-sVonly once you know which ports matter. - Add
-Oselectively — it’s relatively cheap once you already have open/closed ports. - Use
-sUselectively on a curated port list, not blindly across all 65535. - Use NSE selectively (
--script=default,safefirst; targeted vuln scripts second). - Avoid
-T5on production-adjacent or rate-limited networks. - Segment large
/16-scale networks into smaller batches for manageability and lower blast radius. - Always save output (
-oA) so results can be diffed/compared later without re-scanning. - Compare scans over time to detect drift (new services, closed ports reopening, etc.).
30. Professional Scanning Workflow
| Phase | Goal | Example Command | Decision Point |
|---|---|---|---|
| 1. Scope definition | Confirm authorized IP ranges/hosts in writing | (no command — paperwork/rules of engagement) | Do not proceed without signed authorization |
| 2. Host discovery | Identify live hosts | nmap -sn 10.10.10.0/24 | Which hosts warrant further scanning? |
| 3. Initial TCP scan | Fast overview of common ports | sudo nmap -sS -F 10.10.10.20 | Any unexpected exposed services? |
| 4. Full port validation | Confirm nothing was missed | sudo nmap -sS -p- 10.10.10.20 | Reconcile against Phase 3 |
| 5. UDP assessment | Check relevant UDP services | sudo nmap -sU --top-ports 50 10.10.10.20 | Any exposed DNS/SNMP/NTP? |
| 6. Service/version enumeration | Identify exact software | sudo nmap -sV 10.10.10.20 | Flag outdated/unexpected versions |
| 7. OS fingerprinting | Contextualize findings | sudo nmap -O 10.10.10.20 | Cross-check against asset inventory |
| 8. NSE-based assessment | Deeper, safe checks first | sudo nmap --script=default,safe -sV 10.10.10.20 | Escalate to targeted vuln scripts only if in scope |
| 9. Result validation | Manually confirm high-value findings | e.g., manual banner grab via nc/openssl s_client | Avoid false positives in the report |
| 10. Documentation/reporting | Produce clear, evidence-backed findings | -oA output attached as evidence | Map findings to risk/impact |
| 11. Remediation verification | Re-scan after fixes | Repeat relevant phase commands | Confirm the finding is actually resolved |
Common mistakes at this stage: skipping Phase 1 authorization, jumping straight to -A/vuln scripts without a baseline, and not re-validating after remediation.
31. Realistic Lab Scenarios
Scenario A — Single Linux server
- Situation: Lab host 192.168.56.10 runs SSH and a web app.
- Objective: Confirm exposed services match expectations.
- Commands:
sudo nmap -sS -sV -p- 192.168.56.10 - Expected observation: 22/tcp open (OpenSSH), 80/tcp or 443/tcp open (web server).
- Interpretation: Matches expected exposure — no action needed, or flags unexpected extra ports.
- Defensive takeaway: Periodic re-scans catch configuration drift (e.g., a debug port left open).
Scenario B — Windows server
- Situation: Lab host 192.168.56.11 is a domain-joined Windows server.
- Objective: Identify SMB/RDP exposure.
- Commands:
sudo nmap -sS -sV --script smb-os-discovery -p 135,139,445,3389 192.168.56.11 - Expected observation: 445/tcp open (SMB), 3389/tcp open (RDP) if enabled.
- Interpretation: RDP exposed beyond intended segment is a common finding requiring firewall review.
- Defensive takeaway: Verify RDP is restricted to management VLANs only.
Scenario C — Small office network
- Situation: 192.168.1.0/24 office subnet.
- Objective: Inventory all connected devices.
- Commands:
nmap -sn 192.168.1.0/24 - Expected observation: List of live hosts with MAC vendor info.
- Interpretation: Compare against known asset list; investigate unrecognized devices.
- Defensive takeaway: Regular sweeps support rogue-device detection.
Scenario D — Web server
- Situation: 10.10.10.30 hosts a web application.
- Objective: Enumerate web-relevant ports and TLS config.
- Commands:
sudo nmap -sV --script ssl-cert,http-headers -p80,443 10.10.10.30 - Expected observation: Certificate details, server header, HTTP response headers.
- Interpretation: Check certificate expiry, header hardening (e.g., missing security headers).
- Defensive takeaway: Feed findings into a web-hardening checklist, not a full pentest by itself.
Scenario E — DNS server
- Situation: 10.10.10.40 runs authoritative DNS.
- Objective: Confirm only expected UDP/TCP 53 exposure.
- Commands:
sudo nmap -sS -sU -p 53 10.10.10.40 - Expected observation: 53/tcp and 53/udp open.
- Defensive takeaway: Confirm zone transfer (AXFR) is restricted — verify manually/with
dig, not by brute force.
Scenario F — SSH server
- Situation: 10.10.10.50 hosts SSH for management access.
- Commands:
sudo nmap -sV --script ssh-hostkey -p22 10.10.10.50 - Interpretation: Confirm SSH version is current and key algorithms are modern.
- Defensive takeaway: Flag legacy protocol/algorithm support for hardening.
Scenario G — Mixed TCP/UDP environment
- Situation: 10.10.10.60 runs a mix of web, DNS caching, and NTP.
- Commands:
sudo nmap -sS -sU -p T:80,443,U:53,123 10.10.10.60 - Defensive takeaway: Cross-protocol inventories catch services easy to miss with TCP-only scans.
Scenario H — Host behind a firewall
- Situation: 10.10.10.70 is behind a lab firewall permitting only 443 inbound.
- Commands:
sudo nmap -sS -p1-1000 --reason 10.10.10.70 - Expected observation: 443/tcp open; remaining ports filtered.
- Defensive takeaway: Confirms the firewall rule set matches the documented policy.
32. Nmap for Network Administrators
Administrators use Nmap for: asset inventory (what’s actually running vs. what’s documented), spotting unexpected services (a database port accidentally exposed), change-management validation (confirming a maintenance window didn’t open unintended ports), firewall verification, network segmentation verification (confirming VLANs can’t cross-communicate where they shouldn’t), service exposure review, incident investigation support, and configuration validation after deployments.
33. Nmap for Penetration Testing
Within an authorized engagement, Nmap typically supports: reconnaissance (mapping the live attack surface), enumeration (identifying services/versions for further targeted testing), attack-surface mapping (documenting all reachable entry points), service identification (feeding into manual or tool-assisted vulnerability analysis), validation (confirming findings before reporting), and reporting (structured evidence via -oX/-oN). Nmap itself is a reconnaissance/enumeration tool — it is not, and should not be treated as, an exploitation framework.
34. Nmap for SOC and Incident Response
Defenders use Nmap knowledge to: understand what services are actually exposed on an asset under investigation, validate whether a suspicious host matches its expected baseline, investigate unexpected network exposure flagged by monitoring tools, compare before/after states during an incident, and verify that remediation (e.g., disabling a compromised service) actually took effect.
35. Common Mistakes
- Scanning without documented authorization.
- Assuming “filtered” means “secure” — it may just mean “undetermined,” not “safe.”
- Assuming “closed” means “not vulnerable” — a closed port today can open tomorrow; it says nothing about the host’s overall posture.
- Trusting version detection blindly without manual confirmation for high-impact findings.
- Ignoring UDP entirely and missing exposed DNS/SNMP/NTP services.
- Reflexively using
-A(which bundles OS detection, version detection, script scanning, and traceroute) on every target, generating unnecessary noise and time cost. - Using unnecessarily aggressive timing (
-T5) and getting unreliable results. - Misinterpreting probabilistic OS guesses as certain fact.
- Forgetting DNS resolution can slow scans or leak targeting info via external resolvers.
- Not saving output (
-oA) and having no record for later comparison or reporting. - Not validating important findings manually before including them in a report.
36. Security and Legal/Ethical Considerations
- Authorization — Written permission, scoped explicitly, is the baseline requirement before any scan.
- Scope — Only scan what’s explicitly included; treat adjacent/out-of-scope systems as off-limits even if reachable.
- Rules of engagement — Agree in advance on timing windows, contact escalation paths, and prohibited techniques (e.g., no
dos/exploitscripts against production). - Rate limits — Respect agreed-upon scan intensity to avoid disrupting production systems.
- Production impact — Some scan types (aggressive timing, certain NSE scripts) can degrade service performance or trigger unwanted alerts/lockouts.
- Logging — Expect your scan activity to be logged by the target and any intermediate security devices; this is expected and appropriate.
- Data handling — Treat scan output (which can reveal internal topology and software versions) as sensitive; store and share it accordingly.
- Responsible testing — Prefer the least invasive technique that answers your question.
- Why scanning random public systems is inappropriate — Even “harmless” scanning without authorization can violate computer-crime laws, terms of service, and basic professional ethics, and can trigger real incident-response costs for the target organization.
37. Command Cheat Sheet
| Command | Purpose | Key Options | Example | Result/Use Case |
|---|---|---|---|---|
nmap <target> | Default scan | none | nmap 192.168.56.10 | Top 1000 TCP ports |
nmap -sn <net> | Discovery only | -sn | nmap -sn 192.168.56.0/24 | Find live hosts |
sudo nmap -sS <target> | SYN scan | -sS | sudo nmap -sS 192.168.56.10 | Fast, standard scan |
nmap -sT <target> | Connect scan | -sT | nmap -sT 192.168.56.10 | No privileges needed |
sudo nmap -sU <target> | UDP scan | -sU | sudo nmap -sU -p53,161 192.168.56.10 | UDP service check |
sudo nmap -p- <target> | Full port scan | -p- | sudo nmap -p- 192.168.56.10 | Thorough coverage |
sudo nmap -sV <target> | Version detection | -sV | sudo nmap -sV 192.168.56.10 | Software inventory |
sudo nmap -O <target> | OS detection | -O | sudo nmap -O 192.168.56.10 | OS fingerprint |
sudo nmap -A <target> | Aggressive scan | -A | sudo nmap -A 192.168.56.10 | OS+version+scripts+traceroute |
nmap --script=default <target> | Default NSE | --script | nmap --script=default 192.168.56.10 | Safe extra checks |
nmap -oA <base> <target> | All output formats | -oA | nmap -oA scan 192.168.56.10 | Save results |
nmap -iL <file> | Batch targets | -iL | nmap -iL targets.txt | Multiple hosts |
nmap -6 <target> | IPv6 scan | -6 | nmap -6 2001:db8::10 | IPv6 host |
38. Option Reference
- Target specification:
-iL,-iR,--exclude,--excludefile - Host discovery:
-sn,-Pn,-PE,-PP,-PS,-PA,-PU,-PR,-n,-R - Port specification:
-p,-p-,-F,--top-ports,-r,--exclude-ports - Scan techniques:
-sS,-sT,-sA,-sW,-sM,-sN,-sF,-sX,-sU - Service detection:
-sV,--version-intensity,--version-light,--version-all,--version-trace - OS detection:
-O,--osscan-limit,--osscan-guess,--max-os-tries,--osscan-verbose - NSE:
--script,--script-help,--script-args,--script-args-file,--script-trace,--script-updatedb - Timing:
-T0–-T5,--min-hostgroup,--max-hostgroup,--min-parallelism,--max-parallelism,--min-rtt-timeout,--max-rtt-timeout,--initial-rtt-timeout,--max-retries,--host-timeout,--scan-delay,--max-scan-delay,--defeat-rst-ratelimit - Firewall/network behavior:
-f,--mtu,-D,-S,-e,-g/--source-port,--data-length - Output:
-oN,-oX,-oG,-oA,--open,--reason - Verbosity/debugging:
-v,-vv,-d,-dd,--packet-trace - IPv6:
-6 - DNS:
-n,-R,--dns-servers,--system-dns - Performance: see Timing section
- Miscellaneous:
-A(enables OS detection, version detection, script scanning, traceroute),--version(Nmap’s own version),-h/--help
39. “Which Nmap Command Should I Use?” Decision Guide
- Need to know if a host is alive? →
nmap -sn <target> - Need common ports quickly? →
nmap -F <target>or--top-ports <n> - Need all TCP ports? →
sudo nmap -sS -p- <target> - Need UDP visibility? →
sudo nmap -sU -p <relevant-ports> <target> - Need service versions? → add
-sV - Need OS information? → add
-O - Need deeper safe checks? → add
--script=default,safe - Need machine-readable output? → add
-oX <file>(or-oAfor all formats) - Need a fast assessment? →
-For--top-portswith-T4 - Need a low-impact scan? →
-T2, limit ports, avoid-A/intrusive scripts - Need to troubleshoot a scan? → add
-v/-d/--packet-trace/--reason
FAQ for Nmap
Q1. Is Nmap legal to use?
Answer: Yes, on systems you own or are authorized to test. Unauthorized scanning can be illegal.
Q2: Does Nmap require root/Administrator?
Answer: For raw-packet features (-sS, -O, most stealth-style scans) yes; -sT works unprivileged.
Q3: What’s the difference between -sS and -sT?
Answer: -sS never completes the TCP handshake (needs privileges); -sT uses a full OS-level connect.
Q4: Why do I get “filtered” instead of “open”/”closed”?
Answer: Something (a firewall/ACL) is dropping probes without responding.
Q5: Why is UDP scanning so slow?
Answer: Lack of guaranteed responses and ICMP rate-limiting force Nmap to wait/retry more.
Q6: What does open|filtered mean?
Answer: Nmap couldn’t distinguish between an open port with no response and a filtered one.
Q7: Does -A make the scan stealthier?
Answer: No — it adds more probing (OS/version/scripts/traceroute), which is louder, not stealthier.
Q8: Is -sS truly “stealth”?
Answer: Only in the sense of not completing an application-level connection; it’s still visible to packet captures and most IDS.
Q9: Why does OS detection say “no exact match”?
Answer: No fingerprint in the database matches closely enough; Nmap reports its closest guesses instead.
Q10: Can Nmap detect a service behind a reverse proxy accurately?
Answer: Not always — the proxy’s banner may be seen instead of the backend’s.
Q11: What’s the default port count Nmap scans?
Answer: The top 1000 TCP ports, unless changed with -p, -F, --top-ports, or -p-.
Q12: Does Nmap resolve hostnames by default?
Answer: Yes, and performs reverse DNS on live hosts, unless -n is set.
Q13: What’s the difference between -PE and -PS?
Answer: -PE sends ICMP echo; -PS sends TCP SYN to specified ports — useful when ICMP is blocked.
Q14: How do I scan only UDP DNS and SNMP?
Answer: sudo nmap -sU -p 53,161 <target>.
Q15: What does --reason show?
Answer: The specific packet/response (e.g., “syn-ack”, “no-response”) that led to a state classification.
Q16: Can Nmap identify a host’s exact patch level?
Answer: No — version detection identifies product/version strings, not patch-level granularity in most cases.
Q17: What is NSE default category used for?
Answer: A curated, generally safe set of scripts triggered by -sC or as part of -A.
Q18: Is --script vuln safe to run in production?
Answer: Not automatically — individual vuln scripts vary in intrusiveness; review before running against production.
Q19: How do I see all NSE categories a script belongs to?
Answer: nmap --script-help <script-name>.
Q20: What’s the difference between -oN and -oX?
Answer: -oN is human-readable text; -oX is structured XML for automation.
Q21: Why would I use -oG when it’s “legacy”?
Answer: It’s still convenient for quick grep/awk pipelines in shell scripts.
Q22: Does Nmap scan IPv6 automatically?
Answer: No — you must explicitly add -6.
Q23: What does “Network Distance” mean in output?
Answer: Nmap’s estimate of hop count to the target, derived from TTL/traceroute-style analysis.
Q24: Can I spoof my source IP with Nmap?
Answer: The -S option sets a source IP, but in most network setups you won’t receive replies unless you control routing back to yourself — legitimate uses involve multi-homed/lab testing, not anonymizing attacks.
Q25: What does -D (decoy) do?
Answer: Not detailed in this guide’s core sections; if used, it makes a scan appear to originate from multiple decoy IPs alongside the real one — for authorized red-team exercises only, not real anonymization since correlation is often still possible.
Q26: How do I scan a list of targets from a file?
Answer: nmap -iL targets.txt.
Q27: Why does my scan take much longer with -p-?
Answer: You’re probing 65,535 ports per host instead of ~1000, multiplying total probe count significantly.
Q28: What causes inconsistent results between scans?
Answer: Network conditions, rate-limiting, firewall state changes, and timing template differences.
Q29: Should I always run -sV and -O together?
Answer: Only when you need both; each adds scan time, so decide based on what the engagement actually requires.
Q30: How can I verify Nmap’s NSE script database is current?
Answer: Run nmap --script-updatedb, and keep Nmap itself updated via your package manager or the official site.
Q31: What’s the safest way to learn Nmap hands-on?
Answer: Use a dedicated, intentionally vulnerable lab environment (e.g., a local VM lab) that you fully own and control.
41. Glossary
- ARP — Address Resolution Protocol; maps IP addresses to MAC addresses on a local network.
- CIDR — Classless Inter-Domain Routing notation (e.g., /24) describing network size.
- DNS — Domain Name System; resolves hostnames to IP addresses.
- FIN — TCP flag indicating “finish”/connection termination.
- ICMP — Internet Control Message Protocol; used for diagnostics like ping and error reporting.
- IDS — Intrusion Detection System; monitors and alerts on suspicious traffic.
- IPS — Intrusion Prevention System; actively blocks suspicious traffic.
- NSE — Nmap Scripting Engine; Lua-based extensibility framework.
- OS fingerprinting — Identifying an operating system via observed network-stack behavior.
- Port — A numbered endpoint (0–65535) for network communication on a host.
- RST — TCP flag indicating an abrupt connection reset.
- SYN — TCP flag used to initiate a connection (first step of the three-way handshake).
- TCP — Transmission Control Protocol; reliable, connection-oriented.
- UDP — User Datagram Protocol; connectionless, no delivery guarantee.
- TTL — Time To Live; a packet field limiting hop count, used in distance/OS estimation.
- Zombie/idle scan — An advanced technique using a third “zombie” host’s IP ID sequence to indirectly scan a target (not covered in depth in this guide; requires specific conditions and advanced understanding).
42. Final Best-Practices Checklist
- Written authorization obtained and scope confirmed before any scan.
- Rules of engagement agreed (timing, escalation contacts, prohibited techniques).
- Start with discovery (
-sn) before full port scans. - Choose port scope deliberately (
-F/--top-portsvs.-p-) based on actual need. - Cover both TCP and UDP where relevant to the assessment.
- Apply
-sVonly where service identification adds value. - Apply
-Oselectively; treat results as probabilistic. - Use NSE conservatively —
default/safefirst, intrusive/vuln scripts only with explicit authorization. - Choose timing templates appropriate to the network (avoid
-T5by default). - Always save output (
-oA) for records and later comparison. - Manually validate high-impact findings before reporting.
- Document results clearly, mapped to risk/impact.
- Re-scan after remediation to verify fixes actually took effect.
Also, Learn:
- Best Kali-Linux Tools
- Raspberry Pi for Cyber Security
- Signs Your WordPress Website Has Been Hacked (Even If It Looks Normal)
- Why Hacked WordPress Websites Lose Google Rankings in 2026
Discover more from Jahid Shah
Subscribe to get the latest posts sent to your email.





