Ultimate Nmap Commands Cheat Sheet: Network Scanning, Discovery, and Security Auditing

Ultimate NMAP COMMANDS Cheat Sheet

Ultimate NMAP COMMANDS Cheat Sheet

I’ve used Nmap on more networks than I can count — home labs, corporate environments I was authorized to assess, CTF ranges, and troubleshooting sessions where I just needed to know what was actually alive on a subnet. It’s the one tool that never leaves my toolkit, and over the years I’ve built up a working memory of flags and syntax that I rely on constantly. This is that knowledge, organized into one place, so I stop digging through old notes every time I need a scan I haven’t run in a few months.

This guide covers host discovery, port scanning techniques, service and OS detection, the Nmap Scripting Engine (NSE), timing controls, output formats, and the troubleshooting habits that keep me out of trouble — plus the legal and ethical boundary I never cross.

A note before anything else: Nmap is a powerful tool, and scanning networks or systems you don’t own or don’t have explicit written authorization to test is illegal in most jurisdictions. Everything below assumes you’re scanning your own infrastructure, a lab environment, or a target you have documented permission to assess.

Table of Contents

  1. Installing Nmap
  2. Basic Syntax and Target Specification
  3. Host Discovery (Ping Scanning)
  4. Port Specification
  5. Port Scanning Techniques
  6. Service and Version Detection
  7. OS Detection
  8. Nmap Scripting Engine (NSE)
  9. Timing and Performance
  10. Firewall/IDS Evasion Techniques
  11. Output Formats
  12. Common Real-World Scan Combinations
  13. Security Auditing Use Cases
  14. Best Practices
  15. Common Mistakes I See
  16. Troubleshooting
  17. FAQs
  18. Interview Questions
  19. Printable Quick-Reference Summary
  20. Official Documentation Links

1. Installing Nmap

OSCommand
Debian/Ubuntusudo apt install nmap
RHEL/CentOS/Fedorasudo dnf install nmap
macOS (Homebrew)brew install nmap
WindowsDownload installer from nmap.org (includes Zenmap GUI)
Verify installnmap --version

I always confirm the version after install, since some NSE scripts and features are version-dependent, and older repo packages can lag behind the current release significantly.

2. Basic Syntax and Target Specification

The general syntax I keep in my head is:

nmap [scan type] [options] [target]
Target FormatExampleMeaning
Single IPnmap 192.168.1.10Scans one host
Hostnamenmap example.localResolves and scans
Rangenmap 192.168.1.1-50Scans a range of hosts
CIDR blocknmap 192.168.1.0/24Scans entire subnet
Multiple targetsnmap 192.168.1.10 192.168.1.20Scans specific hosts
From filenmap -iL targets.txtReads targets from a file
Exclude hostsnmap 192.168.1.0/24 --exclude 192.168.1.5Skips specific host(s)
Random targetsnmap -iR 10Scans 10 random public hosts (avoid unless testing)

3. Host Discovery (Ping Scanning)

Before I scan ports, I usually want to know what’s actually alive on the network.

CommandPurpose
nmap -sn 192.168.1.0/24Ping scan only — no port scan, just discovery
nmap -PR 192.168.1.0/24ARP ping scan (fast, reliable on local subnets)
nmap -PS22,80,443 192.168.1.0/24TCP SYN ping to specific ports
nmap -PA80 192.168.1.0/24TCP ACK ping
nmap -PU53 192.168.1.0/24UDP ping
nmap -PE 192.168.1.0/24ICMP echo ping
nmap -Pn 192.168.1.10Skips host discovery entirely, treats host as up

I reach for -Pn constantly when scanning hosts I know are alive but that have ICMP blocked by a firewall — without it, Nmap will report the host as down and skip it entirely.

Example output from a basic discovery scan:

Nmap scan report for 192.168.1.1
Host is up (0.0021s latency).
Nmap scan report for 192.168.1.15
Host is up (0.0034s latency).
Nmap done: 256 IP addresses (2 hosts up) scanned in 3.21 seconds

4. Port Specification

CommandPurpose
nmap -p 80 targetScan a single port
nmap -p 22,80,443 targetScan specific ports
nmap -p 1-1000 targetScan a port range
nmap -p- targetScan all 65535 ports
nmap -p U:53,T:80 targetMix UDP and TCP port scans
nmap -F targetFast scan — top 100 common ports only
nmap --top-ports 20 targetScan the 20 most common ports

When time is short, I lean on -F or --top-ports to get a fast read on a host before committing to a full -p- sweep, which can take a long time on a large or filtered network.

5. Port Scanning Techniques

FlagScan TypeNotes
-sSTCP SYN scan (“half-open”)Default for privileged users; fast and relatively stealthy
-sTTCP connect scanCompletes full handshake; used when raw sockets aren’t available (no root)
-sUUDP scanSlower, but necessary for services like DNS, SNMP, DHCP
-sAACK scanUsed to map firewall rule sets, not to find open ports
-sWWindow scanSimilar to ACK but examines TCP window size
-sMMaimon scanExploits BSD-derived TCP stack quirks
-sNTCP Null scanNo flags set — used for firewall/IDS evasion testing
-sFTCP FIN scanSets only the FIN flag
-sXTCP Xmas scanSets FIN, PSH, URG flags (“lit up like a Christmas tree”)

Example SYN scan:

nmap -sS 192.168.1.10

Expected output:

PORT     STATE  SERVICE
22/tcp   open   ssh
80/tcp   open   http
443/tcp  open   https
3306/tcp closed mysql

-sS is my default go-to when I have root/administrator privileges, since it’s faster than a full TCP connect scan and doesn’t complete the handshake, which historically logged less noisily on some systems (though modern IDS/IPS tools catch it just fine).

6. Service and Version Detection

nmap -sV 192.168.1.10
nmap -sV --version-intensity 5 192.168.1.10
nmap -A 192.168.1.10
FlagPurpose
-sVDetects service/version running on open ports
--version-intensity 0-9Controls how aggressively Nmap probes for version info
--version-lightFaster, less thorough version detection
--version-allTries every probe for the most accurate result
-AEnables OS detection, version detection, script scanning, and traceroute all at once

Example output:

PORT    STATE SERVICE VERSION
22/tcp  open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.6
80/tcp  open  http    Apache httpd 2.4.52

I use -sV any time I need to know exactly what’s running behind a port, since “port 80 open” tells me far less than “Apache 2.4.52” when I’m checking for known vulnerabilities.

7. OS Detection

nmap -O 192.168.1.10
nmap -O --osscan-guess 192.168.1.10
FlagPurpose
-OAttempts to fingerprint the target’s operating system
--osscan-guessMakes Nmap guess more aggressively when results are ambiguous
--osscan-limitLimits OS detection to promising targets only (at least one open and one closed port)

Example output:

Running: Linux 5.X
OS CPE: cpe:/o:linux:linux_kernel:5
OS details: Linux 5.0 - 5.14

OS detection relies on subtle TCP/IP stack behaviors and isn’t always perfectly accurate, especially against hardened or virtualized hosts, so I treat the result as a strong hint rather than ground truth.

8. Nmap Scripting Engine (NSE)

The NSE is where Nmap goes from “port scanner” to “vulnerability and enumeration platform.” Scripts live in categories like auth, default, discovery, vuln, safe, and intrusive.

CommandPurpose
nmap -sC targetRuns default safe scripts
nmap --script=default targetSame as -sC
nmap --script=vuln targetRuns vulnerability-detection scripts
nmap --script=http-title targetRuns a single named script
nmap --script=smb-os-discovery targetEnumerates SMB/OS info on Windows hosts
nmap --script-updatedbUpdates the local script database
nmap --script-help=<script>Shows help/description for a specific script

Example combining detection with scripting:

nmap -sV -sC -p 80,443 192.168.1.10

I reach for --script=vuln during authorized security assessments to get a quick read on known CVEs affecting detected service versions, but I never run it against production systems without change-control approval — some vuln scripts are intrusive enough to cause instability on fragile legacy services.

9. Timing and Performance

FlagSpeedUse Case
-T0ParanoidExtremely slow, used to evade IDS detection
-T1SneakyVery slow, evasion-focused
-T2PoliteSlower, reduces network load
-T3NormalDefault timing
-T4AggressiveFaster, assumes a reliable, fast network
-T5InsaneFastest, may sacrifice accuracy on unstable networks

Additional performance controls I use:

nmap --min-rate 500 target
nmap --max-retries 2 target
nmap --host-timeout 30m target

For internal networks with good connectivity, -T4 is my default. On WAN links or unstable connections, I drop to -T2 or -T3 to avoid false negatives from dropped probes.

10. Firewall/IDS Evasion Techniques

These are legitimate techniques for authorized penetration testing to understand how well a firewall or IDS is actually protecting a network — not something to use outside a scope-approved engagement.

FlagPurpose
-fFragments packets to slip past simple packet filters
-D RND:10Uses decoy IPs to obscure the real scan source
-S <spoofed-IP>Spoofs the source IP (requires matching routing setup)
-g 53Uses a specific source port (e.g., 53, mimicking DNS) to bypass weak filtering
--data-length 25Appends random data to packets to alter their signature
--mtu <value>Sets a custom MTU when fragmenting

I’ll only ever use decoys or spoofing in a lab or an engagement where the client has explicitly signed off — spoofed-source scans can also break things for other systems on the path if used carelessly.

11. Output Formats

CommandPurpose
nmap -oN scan.txt targetNormal text output
nmap -oX scan.xml targetXML output (good for parsing/automation)
nmap -oG scan.gnmap targetGrepable output
nmap -oA scan_results targetOutputs in all three formats at once with the same base filename
nmap -v targetVerbose output
nmap -vv targetExtra verbose output
nmap -d targetDebug output

I default to -oA on any scan I’ll want to reference later or feed into another tool — having the XML available means I can parse results programmatically instead of scraping text output.

12. Common Real-World Scan Combinations

These are the exact commands I actually type most often:

# Quick "what's alive" sweep of a subnet
nmap -sn 192.168.1.0/24

# Fast common-port scan with service detection
nmap -sV -F 192.168.1.10

# Full TCP port sweep with default scripts and OS detection
nmap -A -p- 192.168.1.10

# Stealthier SYN scan with slower timing for a sensitive network
nmap -sS -T2 192.168.1.0/24

# UDP scan of common service ports (DNS, SNMP, NTP, etc.)
nmap -sU --top-ports 20 192.168.1.10

# Vulnerability-focused scan on a specific web server
nmap -sV --script=vuln -p 80,443 192.168.1.10

# Full audit with all output formats saved
nmap -A -T4 -oA full_audit 192.168.1.0/24

13. Security Auditing Use Cases

14. Best Practices

15. Common Mistakes I See

16. Troubleshooting

Scan returns “all ports filtered” — Likely a firewall is dropping probes silently. Try -Pn to skip host discovery, or -sA to check if it’s stateful filtering versus a genuinely offline host.

Scan is taking far too long — Increase --min-rate, reduce the port range, bump the timing template up (-T4), or check if a UDP scan is the culprit (UDP is inherently slow due to how it handles non-responses).

Nmap requires root/administrator privileges — SYN scans (-sS) and OS detection (-O) require raw socket access. Run with sudo on Linux/macOS or as Administrator on Windows, or fall back to -sT if elevated privileges aren’t available.

Results look inconsistent between runs — Network congestion, IDS/IPS rate-limiting, or a target’s own rate-limiting can cause this. Try --max-retries and a slower timing template to stabilize results.

Version detection isn’t identifying a service — Increase --version-intensity up to 9, or use --version-all for the most exhaustive probe set.

17. FAQs

Is Nmap illegal to use? Nmap itself is completely legal software. Using it to scan networks or systems you don’t own or don’t have explicit permission to test can be illegal depending on your jurisdiction. Always get authorization first.

What’s the difference between a SYN scan and a connect scan? A SYN scan (-sS) sends a SYN packet and doesn’t complete the TCP handshake, making it faster and requiring raw socket privileges. A connect scan (-sT) completes the full handshake using the OS’s normal networking stack, which works without elevated privileges but is slower and more visible in logs.

Why is my UDP scan so slow? UDP is connectionless, so Nmap can’t rely on a simple SYN/ACK response to confirm a port is open. It has to wait for ICMP “port unreachable” responses (for closed ports) or time out entirely (for open|filtered ports), which is inherently slower than TCP scanning.

What does “filtered” mean in scan results, versus “closed”? “Closed” means a port responded, confirming the host is reachable but nothing is listening. “Filtered” means Nmap couldn’t determine the port’s state because a firewall or ACL is blocking the probe.

Can Nmap detect every operating system accurately? No. OS detection relies on statistical fingerprinting of TCP/IP stack behavior and works best against hosts with at least one open and one closed port. Heavily firewalled or virtualized hosts can return inaccurate or inconclusive results.

What’s the safest scan type to run against production systems? A slower-timed, default-script TCP SYN or connect scan (-sS -T2 -sC) with limited port ranges is generally the least disruptive. Vulnerability scripts and aggressive/full scans should be scheduled with change-control approval.

18. Interview Questions

19. Printable Quick-Reference Summary

TaskCommand
Ping sweep a subnetnmap -sn 192.168.1.0/24
Skip host discoverynmap -Pn target
Scan top 100 ports fastnmap -F target
Scan all portsnmap -p- target
SYN scannmap -sS target
TCP connect scannmap -sT target
UDP scannmap -sU target
Service/version detectionnmap -sV target
OS detectionnmap -O target
Aggressive all-in-one scannmap -A target
Default NSE scriptsnmap -sC target
Vulnerability scriptsnmap --script=vuln target
Set timing templatenmap -T4 target
Save all output formatsnmap -oA filename target
Fragment packets (evasion)nmap -f target

20. Official Documentation Links

I keep this cheat sheet open in a tab any time I’m running a scan I haven’t done in a while — even after years of using Nmap regularly, there’s always a flag combination I forget. Save it, print it, or fork it into your own notes, and adjust the scan combinations to match the environments you actually work in.

Exit mobile version