Quick Answer
Nmap is the standard tool for network discovery and port auditing. Use it only with written authorization, save every scan with -oA, and learn its traffic patterns so you can also detect scans in your logs.
A firewall change goes live on Friday afternoon. By Monday, a vulnerability report lists an exposed RDP service nobody remembers approving. The fastest way to confirm what is actually listening is an Nmap scan, and the fastest way to tell whether a stranger is doing the same to you is knowing what Nmap traffic looks like on the wire. This cheat sheet covers both sides: the commands SOC analysts use for network discovery, port scanning, service detection, and evidence collection, and the log and packet patterns that reveal scanning against your own environment.
What Is Nmap and How Do SOC Teams Use It?
Nmap ("Network Mapper") is an open-source scanner that sends crafted packets to hosts and interprets the replies to report live systems, open ports, service versions, and operating system hints. SOC teams use it for asset inventory, exposure checks, firewall rule verification, and capturing scan evidence during investigations.
In MITRE ATT&CK terms, the same activity appears on the adversary side as T1046 (Network Service Discovery), T1018 (Remote System Discovery), and T1595.001/T1595.002 (Active Scanning). That is why this guide treats every command as both a tool and a detection opportunity. All examples below assume you own the target or hold written permission to scan it.
Warning: Scanning systems you do not own or have written authorization to test may violate law and acceptable-use policies. Use only authorized ranges, such as your lab or scanme.nmap.org, which the Nmap project provides for testing.
Basic target specification
nmap 192.168.1.1 # single host
nmap 192.168.1.0/24 # entire subnet
nmap 192.168.1.1 192.168.1.10 # multiple hosts
nmap 192.168.1.1-20 # address range
nmap -iL targets.txt # targets from a file
nmap scanme.nmap.org # authorized Nmap test host
Use these to define scope. Running Nmap with no options performs host discovery followed by a scan of the 1,000 most common TCP ports. The output lists each port with its state and a guessed service name based on the port number only, not on a real banner check. Always keep a scope file (-iL) so the exact target list is documented. Avoid -iR (random public targets) entirely in corporate work; it selects addresses you have no authority over.
Which Nmap Commands Discover Live Hosts?
Host discovery (-sn) determines which addresses respond without scanning ports. On a local Ethernet segment Nmap uses ARP, which is the most reliable method. Across routers it falls back to ICMP and TCP probes, which firewalls often drop, so absent responses do not prove a host is offline.
nmap -sn 192.168.1.0/24 # ping sweep, no port scan
nmap -sL 192.168.1.0/24 # list targets only, sends no probes to them
nmap -n -sn 192.168.1.0/24 # skip DNS resolution (faster, quieter)
nmap -PR 192.168.1.0/24 # ARP discovery, local network only
nmap -PE / -PP / -PM <target> # ICMP echo / timestamp / address-mask probes
nmap -PS22,80,443 <target> # TCP SYN discovery probes
nmap -PA80,443 <target> # TCP ACK discovery probes
nmap -PU53,161 <target> # UDP discovery probes
nmap -Pn 192.168.1.1 # treat host as up, skip discovery
nmap --traceroute 192.168.1.1 # map the network path
When to use: asset inventory and rogue-device checks. False-positive note: -Pn skips discovery; it does not bypass a firewall, and on a /24 it will wait on every address, including dead ones. -sL is useful for verifying scope before you send a single packet.
How Do You Scan Ports with Nmap?
Port scanning probes TCP or UDP ports and classifies each as open, closed, or filtered. The default TCP SYN scan (-sS) needs raw-socket privileges and sends SYN packets without completing the handshake. Without privileges, Nmap falls back to the TCP connect scan (-sT).
nmap -p 22,80,443 192.168.1.1 # specific ports
nmap -p 1-1000 192.168.1.1 # port range
nmap -p- 192.168.1.1 # all 65,535 TCP ports
nmap -F 192.168.1.1 # fast scan, fewer ports
nmap --top-ports 100 192.168.1.1 # 100 most common ports
nmap -p T:80,443,U:53,161 192.168.1.1 # mixed TCP and UDP
nmap -p- --open 192.168.1.1 # show only open ports
TCP scan techniques
| Flag | Technique | Defensive use / note |
|---|---|---|
-sS | SYN (half-open) | Default inventory scan; IDS/IPS can still detect it |
-sT | TCP connect | No privileges needed; completes handshakes, so apps log it |
-sA | ACK | Maps firewall rules (filtered vs. unfiltered); does not find open ports |
-sW / -sM | Window / Maimon | Niche; results depend on the target's TCP stack |
-sN / -sF / -sX | NULL / FIN / Xmas | Abnormal flag combinations; trivial to alert on (see detection section) |
-sY / -sZ | SCTP INIT / COOKIE ECHO | Only for environments that use SCTP (telecom) |
UDP scanning
nmap -sU -p 53,123,161 192.168.1.10 # DNS, NTP, SNMP
nmap -sU --top-ports 100 192.168.1.10
nmap -sU -sV 192.168.1.10 # UDP version detection
nmap -sS -sU 192.168.1.10 # TCP and UDP together
UDP scans are slow and frequently return open|filtered because many UDP services stay silent without a valid request. Limit them to ports you care about, and expect ICMP rate limiting on targets to stretch scan time.
How Do You Detect Services, Versions, and Operating Systems?
Version detection (-sV) probes open ports and compares responses against Nmap's signature database to identify the application and version. OS detection (-O) fingerprints the TCP/IP stack. Both produce best guesses, not proof.
nmap -sV -p 22,80,443,445,3389 192.168.1.10
nmap -sV --version-light 192.168.1.10 # fewer probes, faster
nmap -sV --version-intensity 5 192.168.1.10
nmap -sV --version-all 192.168.1.10 # all probes, slowest
nmap -O 192.168.1.10
nmap -O --osscan-limit 192.168.1.10 # only try promising targets
nmap -A 192.168.1.10 # OS + version + default scripts + traceroute
Caveats: service banners can be modified or misleading, and OS detection loses accuracy when only one or two ports are reachable. Treat -A as a heavy option: it generates substantial traffic and runs NSE scripts, so avoid it on fragile or production systems without a change window.
What Is the Nmap Scripting Engine (NSE)?
The Nmap Scripting Engine runs Lua scripts that extend scanning into configuration checks, protocol inspection, and vulnerability detection. Scripts are grouped into categories such as default, safe, discovery, version, auth, and vuln. Some categories are intrusive, so review a script before running it.
nmap -sC 192.168.1.10 # default scripts
nmap --script safe 192.168.1.10
nmap --script http-title,http-headers -p 80,443 192.168.1.10
nmap --script ssl-cert,ssl-enum-ciphers -p 443 192.168.1.10
nmap --script ssh2-enum-algos -p 22 192.168.1.10
nmap --script smb-protocols,smb-os-discovery -p 445 192.168.1.10
nmap --script dns-recursion -p 53 192.168.1.10
nmap --script-help vuln # read before you run
Use these for TLS hygiene, SSH algorithm review, and SMB exposure checks. --script vuln results always require manual validation, since version-based checks can produce false positives and false negatives. Run broadcast scripts (--script broadcast) only on networks you are authorized to probe.
How Should You Tune Nmap Timing?
Nmap timing templates -T0 through -T5 trade speed against network load and reliability. -T3 (normal) is the default; -T4 suits fast, reliable internal networks; -T5 risks missed ports and overloaded devices.
nmap -T2 192.168.1.0/24 # polite, lower load
nmap --max-rate 100 192.168.1.0/24 # cap packets per second
nmap --scan-delay 1s 192.168.1.10
nmap --max-retries 2 192.168.1.10
nmap --host-timeout 5m 192.168.1.0/24
For fragile OT/ICS and legacy devices, prefer -T2 or lower plus --max-rate, and coordinate with the system owner first. A rate limit is a safety control, not just a speed setting.
How Do You Save Nmap Results as Evidence?
Use -oA basename to write normal, XML, and grepable output in one run. XML is the best format for tooling and diffing, and normal output is easiest for humans. Saving every scan creates an audit trail and lets you compare exposure over time.
nmap -sn 192.168.1.0/24 -oA network-discovery
nmap -sS -p- --open 192.168.1.10 -oA tcp-inventory
nmap -sS -p- -oX evidence-scan.xml 192.168.1.10
nmap --reason --open 192.168.1.10 # why each state was assigned
nmap --packet-trace -p 80 192.168.1.1 # per-packet view for troubleshooting
nmap --append-output -oN scan.txt 192.168.1.1
nmap --resume scan.txt # resume an interrupted scan
--reason and --packet-trace are the best troubleshooting pair: they show whether a "filtered" result came from a silent drop or an ICMP rejection. Grepable output (-oG) is a legacy format; prefer XML for automation.
Common SOC and DFIR one-liners
nmap -sV -p 22,80,443,445,3389 192.168.1.10 # remote access and web services
nmap -sU -p 53,123,161 192.168.1.10 # DNS, NTP, SNMP exposure
nmap -p 445 --script smb-protocols,smb-os-discovery 192.168.1.10
nmap -p 443 --script ssl-cert,ssl-enum-ciphers 192.168.1.10
nmap -sC -sV 192.168.1.10 # default scripts + versions
What Do Nmap Port States Mean?
Nmap reports six port states describing what it could determine from the replies it received. "Filtered" means packet filtering prevented a reliable answer, not that the port is closed. Misreading these states is the most common cause of wrong exposure conclusions.
| State | Meaning |
|---|---|
| open | An application is accepting connections |
| closed | Reachable, but nothing is listening |
| filtered | Filtering prevents Nmap from determining the state |
| unfiltered | Reachable, but open/closed is unknown (seen with ACK scans) |
| open|filtered | Cannot tell open from filtered (common in UDP) |
| closed|filtered | Cannot tell closed from filtered |
How Can You Detect Nmap Scanning in Your Network?
Nmap scanning is detectable because it produces many connection attempts to many ports or hosts from one source in a short time, often with unfinished handshakes. Detection relies on firewall logs, IDS/IPS signatures, flow data, and endpoint network telemetry, not on any single packet.
Packet-level checks with tcpdump
# SYN-only packets (typical of SYN scans)
sudo tcpdump -nn 'tcp[tcpflags] & (tcp-syn|tcp-ack) = tcp-syn'
# NULL scan: no TCP flags set
sudo tcpdump -nn 'tcp[tcpflags] = 0'
# Xmas scan: FIN, PSH, URG set together
sudo tcpdump -nn 'tcp[tcpflags] & (tcp-fin|tcp-psh|tcp-urg) = (tcp-fin|tcp-psh|tcp-urg)'
The first filter is noisy on busy servers, so use it with a source-count threshold. The NULL and Xmas filters should return almost nothing on healthy networks, which makes them high-signal. Run them on a span port or sensor, not on production hosts under load.
Detection signals to correlate
| Log source | What to look for | False-positive trigger |
|---|---|---|
| Firewall / flow logs | One source hitting many destination ports or hosts within minutes, mostly denied | Authorized vulnerability scanners, monitoring tools |
| Windows Filtering Platform (Events 5152, 5157) | Bursts of blocked inbound packets from one address across sequential ports (requires the matching audit policy) | Misconfigured clients retrying a blocked service |
Zeek conn.log | Many connections with states such as S0 or REJ from the same originator | Asymmetric routing or tap placement gaps |
| IDS/IPS (Suricata, Snort) | Scan-category alerts, Nmap user-agent strings in HTTP from NSE scripts | Internal red team or scheduled scans |
| Sysmon Event ID 3 | A host process opening connections to many internal IPs/ports (scan from a compromised host) | Backup, inventory, and discovery agents |
Evasion-oriented options such as fragmentation (-f, --mtu, which requires a multiple of 8), decoys (-D), source-port spoofing (-g), and bad checksums (--badsum) exist mainly to test whether a firewall or IDS handles unusual traffic correctly. Use them only against your own sensors in a lab. As a defender, expect tiny fragments, packets with mismatched checksums, or probes from many apparent sources, and make sure your IDS reassembles fragments and normalizes traffic. Slow scans such as -T0 can evade short-window thresholds, so also alert on a source touching many distinct ports over hours.
Reduce your exposure
- Run authorized scans on a schedule and diff the XML output against the last known-good baseline.
- Close or restrict services found open that have no business owner (RDP, SMB, SNMP are frequent offenders).
- Restrict management ports to VPN or jump-host source ranges.
- Enable firewall logging for dropped traffic and forward it to your SIEM.
- Tune detection thresholds around your approved scanner IPs to cut false positives.
- Deploy an IDS/IPS with fragment reassembly and keep rule sets current.
What Are the Safe-Use Rules for Nmap?
Safe Nmap use means written authorization, a defined scope, controlled scan intensity, and saved output. Nmap is not stealthy by default, and SYN scans are detectable by IDS/IPS. Following these rules protects both the target systems and your legal position.
- Obtain written authorization that names the target ranges, timing, and contacts.
- Verify scope with
-sLbefore scanning. - Use
-T2/--max-ratefor fragile systems; high timing templates can overload them. - Review any NSE script before running it; some categories are intrusive.
- Treat
-Pnas "skip discovery," not "bypass firewall." - Validate every vulnerability finding manually before reporting.
- Store outputs with
-oAfor audit and comparison.
Related Cybersecurity Topics You Should Explore
- Linux nslookup Cheat Sheet: How SOC Analysts Investigate DNS
- Linux dig Command Cheat Sheet for SOC Analysts (2026)
- Linux rsync Command Cheat Sheet for SOC Analysts (2026)
- Linux scp Command Cheat Sheet: Secure File Transfer Made Easy
- Linux curl Command Cheat Sheet for SOC Analysts (2026)
- Linux wget Command Cheat Sheet (2026): Download Like a Pro
- Linux ss Command Cheat Sheet: Find Suspicious Connections Fast
- Linux netstat Command Cheat Sheet: Spot Suspicious Connections Fast
- Linux traceroute Command Cheat Sheet: Find Network Hops Fast (2026)
- Linux Ping Command Cheat Sheet (2026): Complete Guide
Frequently Asked Questions
Is Nmap legal to use?
Nmap itself is legal, but scanning systems without authorization may violate computer misuse laws or policies depending on jurisdiction. Get written permission first. This is general security context, not legal advice.
What is the difference between -sS and -sT?
The -sS SYN scan sends raw packets and does not complete the handshake, but needs elevated privileges. The -sT connect scan uses the operating system's connect call, needs no privileges, and is more likely to be logged by applications.
Why does Nmap show a port as filtered?
A firewall or other device is dropping or rejecting probes, so Nmap cannot determine the real state. Use --reason or --packet-trace to see what was received.
Why are UDP scans so slow?
Many UDP services do not reply to empty probes, and hosts often rate-limit ICMP unreachable messages. Nmap must wait and retransmit, so scope UDP scans to specific ports.
Can Nmap find vulnerabilities?
Partly. NSE vuln scripts and version detection can flag likely issues, but results are indicators requiring manual validation. Nmap is not a replacement for a dedicated vulnerability scanner.
Does -Pn make a scan stealthy?
No. It only skips host discovery and treats the target as online. The scan traffic is still visible to firewalls and IDS/IPS.
Conclusion
Treat Nmap as a measurement tool with a paper trail: authorize the scope, start with discovery, scan only what you need, tune timing to the environment, and save every result with -oA. Then flip the perspective: baseline your own scans, log denied traffic, and alert on one source touching many ports or hosts. Teams that do both find unmanaged exposure faster and spot hostile reconnaissance earlier.
Analysis based on public vendor advisories, official telemetry documentation, and defensive SOC review.
