Table of Contents
ToggleThe Ultimate Guide to Nmap
Network mapping, port scanning, OS detection, and security auditing β complete reference for cybersecurity professionals and ethical hackers
π Table of Contents
π What is Nmap?
Nmap (Network Mapper) is a free, open-source network discovery and security auditing tool. Created by Gordon Lyon (“Fyodor”) in September 1997, it has become the industry-standard utility for network exploration. Nmap sends specially crafted packets to target hosts and analyzes the responses to determine:
- Live hosts β which devices are active on the network
- Open ports β which network services are accessible
- Running services β including precise version information
- Operating systems β OS fingerprinting via TCP/IP stack analysis
- Firewall behavior β filtering rules and network defenses
π‘ Quick Start: One command β nmap <target> β performs host discovery and scans the 1,000 most common TCP ports. Run with sudo for a stealthier SYN scan.
Why Nmap matters: Whether you’re a network administrator auditing your infrastructure, a penetration tester conducting authorized assessments, or a CTF player mapping attack surfaces, Nmap provides the foundational reconnaissance layer that every security assessment requires.
β‘ What are Nmap Commands?
Nmap commands are command-line instructions used to control the Network Mapper tool. A typical Nmap command combines a target specification (IP, range, CIDR, or hostname) with flags that modify scan behavior:
# Basic Nmap command structure
nmap [flags] [target]
# Examples:
sudo nmap -sS -sV 192.168.1.10
nmap -p 80,443 -sC scanme.nmap.org
Key Nmap command categories:
- Host Discovery β
-sn,-Pn,-PS,-PE - Port Scanning β
-sS,-sT,-sU,-p- - Service & Version Detection β
-sV,--version-intensity - OS Detection β
-O,-A - NSE Scripts β
-sC,--script - Output Control β
-oA,-oX,-oG
π Key Takeaways
- 1 Nmap is the industry-standard network mapper β host discovery, port scanning, service/version detection, OS fingerprinting, and scripting (NSE) in one tool.
-
2
Default command is enough for quick checks β
nmap <target>; layered flags (-sV,-sC,-O,-p-) unlock full enumeration depth. - 3 Port states matter β open, closed, filtered, and open|filtered each tell you something different about the host and its firewall.
-
4
Timing templates (
-T0to-T5) control scan speed and stealth β they trade accuracy for speed. - 5 NSE scripts turn Nmap into a mini vulnerability scanner β vulners, smb-vuln-ms17-010, http-enum, and hundreds more.
- β Always define scope and get written authorization before scanning anything you don’t own. Unauthorized scanning is illegal in most jurisdictions.
π Port Scanning Basics
What is a Port?
A port is a numbered endpoint (0β65535) on a host that a service listens on β HTTP on 80/443, SSH on 22, DNS on 53. Port scanning is the process of sending packets to each port and reading the response to determine the port state.
TCP vs UDP
π TCP
Connection-oriented: establishes a session via the three-way handshake, guarantees delivery. Used by web, mail, SSH, and most enterprise services.
π€ UDP
Connectionless: no handshake, no delivery guarantees β just datagrams. Used by DNS, DHCP, SNMP, NTP. UDP scanning is slower and less reliable.
The Three-Way Handshake
- Client sends a SYN packet with a random sequence number
- Server replies with SYN-ACK, acknowledging the client’s sequence number and offering its own
- Client sends ACK, and the connection is established
π Why this matters for Nmap: -sS (SYN scan) sends SYN and on SYN-ACK sends RST to tear down β connection never completes, faster and stealthier. -sT (Connect scan) completes the full handshake through the OS socket API β visible to service logs.
π¦ Installation Guide
Current stable release: Nmap 7.99 (March 2026). Always verify at nmap.org/download.
π§ Linux (Debian/Ubuntu/Kali)
sudo apt update && sudo apt install -y nmap
Fedora/RHEL: sudo dnf install nmap
Arch: sudo pacman -S nmap
πͺ Windows
Download installer from nmap.org/download
Run installer β includes Nmap, Zenmap (GUI), Ncat, Ndiff, and Nping
Important: Accept Npcap installation (required for raw-packet SYN scans)
π macOS
brew install nmap
Or download the official .dmg from nmap.org
Note: Zenmap is no longer bundled in official macOS builds
Verification
# Verify installation
nmap –version # Shows version and build info
nmap -h # Full option summary
sudo nmap -sS -p 22 127.0.0.1 # Smoke test against localhost
π§ Troubleshooting Common Issues
| Symptom | Cause | Fix |
|---|---|---|
| “You requested a scan type which requires root privileges” | -sS, -sU, -O need raw packets |
Re-run with sudo (Linux/macOS) or elevated prompt (Windows) |
| Windows: SYN scans don’t work / “Failed to open device” | Npcap missing or outdated | Reinstall Npcap from the Nmap installer |
| Scan is extremely slow | Default timing, or UDP scan without port limits | Use -T4 on trusted networks, --top-ports with -sU |
| “Failed to resolve given hostname/IP” | DNS or syntax issue | Check target syntax: IP, CIDR, or use -n to skip DNS |
βοΈ Complete Command Reference
π‘ Host Discovery
nmap -sL <targets> β List scan (DNS only)
Resolves reverse DNS without sending packets. Best practice: validate target lists before scanning.
sudo nmap -sn <targets> β Ping sweep (host discovery only)
Default probes: ICMP echo, TCP SYN to 443, TCP ACK to 80, ICMP timestamp; local subnet uses ARP. No port scan.
nmap -Pn <target> β Skip host discovery (treat all as up)
Essential when ICMP is blocked. Warning: scanning large ranges wastes time on dead IPs.
nmap -PS80,443 <target> β TCP SYN ping
Sends SYN to listed ports; any response marks host up. Good for hosts that block ICMP.
π Port Scanning
nmap <target> β Default scan
Baseline: host discovery + top 1000 TCP ports. As root: SYN scan; non-root: connect scan.
sudo nmap -sS <target> β SYN (half-open) scan
Sends SYN; SYN-ACK β open (then RST to abort), RST β closed, no reply β filtered. Requires root. Faster and stealthier than connect scan.
nmap -sT <target> β TCP connect scan
Full handshake via OS sockets; works without root; visible in service logs.
sudo nmap -sU <target> β UDP scan
Sends UDP probes; ICMP port-unreachable β closed, data reply β open, silence β open|filtered. Slow by nature β use --top-ports 50.
nmap -p- <target> β All 65535 ports
Scans every TCP port. Critical for thorough assessments β many services run on non-standard high ports.
nmap --top-ports 100 <target> β Top-N ports
Scans the most frequently used ports. Balances speed and coverage.
π¬ Service & OS Detection
nmap -sV <target> β Version detection
Probes open ports with protocol-specific payloads β e.g., 80/tcp open http nginx 1.24.0. Critical for vulnerability research.
sudo nmap -O <target> β OS fingerprinting
Analyzes TCP/IP stack quirks against a database of 6,000+ fingerprints. Best with one open and one closed port.
sudo nmap -A <target> β Aggressive all-in-one
Combines -O + -sV + -sC + --traceroute. The go-to for thorough scanning of a single authorized host.
π§© NSE Scripts (Nmap Scripting Engine)
The Nmap Scripting Engine (NSE) extends Nmap’s capabilities with hundreds of Lua scripts organized by category. NSE scripts can perform everything from banner grabbing to vulnerability detection.
sudo nmap -sC <target> β Default scripts
Runs the “safe” script category β non-intrusive checks (banner grabs, common misconfigurations).
nmap --script=http-title -p 80 <target> β Run specific scripts
By name or comma-separated: --script=http-title,http-headers
nmap --script=vulners <target> β CVE lookup
Queries Vulners API for CVEs matching detected services/versions. Requires internet. Always verify findings manually.
nmap --script=smb-vuln-ms17-010 -p 445 <target> β EternalBlue checker
Specific vulnerability script. Never run on production without authorization.
NSE Script Categories: auth, broadcast, brute, default, discovery, dos, exploit, external, fuzzer, intrusive, malware, safe, version, vuln.
π‘οΈ Firewall Evasion & Stealth
sudo nmap -f <target> β Fragment packets
Splits packets into 8-byte fragments to slip past simple filters that don’t reassemble.
sudo nmap -D RND:10 <target> β Decoy scan
Spoofs random decoy source IPs to bury the real scan. Does not guarantee anonymity.
sudo nmap -g 53 <target> β Source port spoofing
Sets source port to 53 (DNS) β some legacy firewalls trust DNS source ports.
sudo nmap --badsum <target> β Bad checksum
Sends packets with wrong TCP checksums; most stacks drop them, but some firewalls respond β revealing their presence.
β±οΈ Timing & Performance
Timing Templates -T0 to -T5
-T0 ParanoidSerial scan, 5-min gaps β evasion-oriented, impractically slow
-T1 SneakySlow but less likely to trigger IDS
-T2 PoliteReduces load β considerate to shared networks
-T3 Normal (default)Balanced speed and stealth
-T4 AggressiveRecommended for labs β doubles default rates
-T5 InsaneMax speed β drops packets, can crash devices. Only on isolated targets.
Performance Flags
--min-rate 1000 / --max-rate 200 β Explicit packet rates
--host-timeout 30m β Abort slow hosts; essential for mixed-response networks
--max-retries 2 β Reduces retries; speeds scans but increases false “filtered” results
-n β Skip DNS resolution (speeds up large scans)
π Output Options
-oN file.txt β Normal output (human-readable)
-oX file.xml β XML output (canonical for tools)
-oG file.gnmap β Grepable output (scripting/automation)
-oA basename β All formats (.nmap, .xml, .gnmap) β the professional default
-v / -vv β Verbosity (adds progress and port states)
--reason β Show state rationale (indispensable for firewall analysis)
π§ͺ Lab Tutorials
Prerequisite: Use only systems you own β a lab VM, a router you administer, or a private test subnet (e.g., VirtualBox/VMware host-only network).
Lab 1 β Discover live hosts
sudo nmap -sn 192.168.56.0/24
Expected: list of up-hosts with MAC addresses and vendors. Compare with your known inventory.
Lab 2 β Identify open services
sudo nmap -sV -p- 192.168.56.10
Expected: every TCP port with service + version. Cross-check one result manually (e.g., curl -I against the web port).
Lab 3 β Detect operating systems
sudo nmap -O 192.168.56.10
Ensure at least one open and one closed port. Compare the guess with the VM’s actual OS.
Lab 4 β Safe NSE scripts
sudo nmap -sC -sV -p 80,443,22 192.168.56.10
Review each script result and verify one finding manually.
π Real Use Cases
1. Auditing a small office network
Goal: inventory every device. Approach: -sn sweep, then -sV on live hosts. Interpretation: unexpected hosts/ports = investigation trigger.
2. Verifying exposed services before deployment
Goal: confirm only intended ports listen externally. Approach: external -Pn -p- scan of the public IP; compare with the allowed list.
3. Checking firewall rules after changes
Goal: prove a rule blocks/permits as designed. Approach: -sS + --reason from both sides of the firewall; verify states match intent.
βοΈ Nmap vs Alternatives
| Feature | Nmap | Masscan | RustScan |
|---|---|---|---|
| Speed | High | Very High | Very High |
| Service Detection | β Yes | Limited | No (feeds Nmap) |
| NSE Scripts | β Yes | No | No |
| OS Detection | β Yes | No | No |
| Best For | General-purpose scanning | Large-scale port discovery | Fast initial discovery |
Workflow pattern: masscan -p0-65535 <range> --rate=10000 -oL open.txt β nmap -sV -sC -p<ports> <targets> (depth after breadth).
β Frequently Asked Questions
What is Nmap?
A free, open-source network mapper for host discovery, port scanning, service/version detection, OS fingerprinting, and scripting.
Is Nmap free?
Yes β Nmap Public Source License (GPLv2-compatible), from nmap.org.
Is Nmap legal?
The tool is legal; scanning without authorization is not. Always scan only what you own or have written permission to test.
Does Nmap work on Windows?
Yes β official installer with Npcap and Zenmap GUI.
Most common Nmap command?
nmap <target> β SYN scan (root) of the top 1000 TCP ports with host discovery.
What does -sS do?
SYN half-open scan: sends SYN, marks open on SYN-ACK, then RST β no full handshake. Needs root.
What’s the difference between -sS and -sT?
-sS aborts after SYN-ACK (stealthier, needs root); -sT completes the full three-way handshake via the OS (visible to services, no root needed).
What does -sV do?
Version detection β identifies the service and its version (e.g., nginx 1.24.0).
What does -O do?
OS fingerprinting β guesses the operating system from TCP/IP stack behavior.
What does -A do?
Aggressive mode: OS detection + version detection + default scripts + traceroute in one flag.
What does -Pn mean?
“No ping” β skip host discovery and treat all targets as up; for hosts that block ICMP.
What does -sn do?
Ping sweep β host discovery only, no port scan.
How do I scan all 65535 ports?
nmap -p- <target> (equivalent to -p 1-65535).
Can Nmap detect vulnerabilities?
Not as a full scanner β but NSE vuln scripts flag version-based CVE matches; always verify manually.
Is Nmap safe to use?
Against authorized systems, yes. Avoid -T5 and intrusive/dos scripts on production networks.
β οΈ Common Mistakes
- Scanning without authorization β the single most serious error; a signed scope document is non-negotiable.
- Misinterpreting filtered ports β filtered β closed; it means “firewall in the path.” Verify with
--reasonand-sA. - Ignoring firewall behavior β assuming “no response” means the host is down; use
-Pnand understand stateful filtering. - Using aggressive timing on production β
-T5/--min-ratecauses packet loss and can disrupt services. - Forgetting to save results β no
-oA, no evidence, no report. Always -oA. - Trusting the default 1000 ports β critical services on high ports are invisible without
-p-. - Skipping version detection β reporting “port 80 open” without “nginx 1.24.0” is incomplete enumeration.
- Running intrusive NSE scripts blindly β
--script=vulnorintrusiveagainst production can crash services. - No verification β reporting NSE or vulners output as fact without manual confirmation.
- Ignoring UDP entirely β DNS, SNMP, NTP, DHCP live on UDP; a TCP-only scan misses them.
π Advanced Tips
- Timing templates as a scale:
-T0β-T2for stealth,-T3default,-T4for labs,-T5only for isolated targets. - NSE category strategy: default β safe for audits; targeted scripts (
http-enum,smb-os-discovery,ssl-enum-ciphers) for depth;vulnersfor CVE triage; verify everything. - Automation pattern:
nmap -sn -oG - <range> | awk '/Up/{print $2}' > hosts.txtthen feed-iL hosts.txtinto detailed scans. - Recurring audits: run scans on schedule, save with
-oA, andndiffagainst the previous baseline. - Output formats for tooling: XML (
-oX) is the integration format β import into Metasploit, parse with Python, or usexsltprocto render HTML reports. - Know your lab: use a disposable VM network (VirtualBox host-only/VMware) so timing and evasion tests never touch real infrastructure.
π Master Network Reconnaissance with Nmap
Nmap is the foundation of every security assessment. Combine these commands, scripts, and best practices to map, audit, and secure your networks β always with proper authorization.
π Reference: Nmap Network Scanning by Gordon Lyon (Fyodor)


