Skip to main content

nmap Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for host discovery, port scanning, and service detection with nmap in Linux

The `nmap` command scans networks to find live hosts, open ports, and the services behind them. This cheatsheet covers target specification, host discovery, scan types, version and OS detection, timing, output formats, and NSE scripts. Only scan hosts and networks you own or have written permission to test.

Basic Syntax

Core nmap command forms.

CommandDescription
nmap 192.168.1.10Scan the 1000 most common TCP ports on one host
sudo nmap 192.168.1.10Same scan as root, which enables the faster SYN scan
nmap -v 192.168.1.10Increase verbosity, repeat as -vv for more detail
nmap --reason 192.168.1.10Show why each port is in its reported state
nmap --open 192.168.1.10Report only ports that are open

Target Specification

Point a scan at one host, a range, a subnet, or a list.

CommandDescription
nmap 192.168.1.10 10.0.0.5Scan several hosts in one run
nmap 192.168.1.0/24Scan a whole subnet in CIDR notation
nmap 192.168.1.1-50Scan an address range
nmap -iL targets.txtRead targets from a file, one per line
nmap --exclude 192.168.1.1 192.168.1.0/24Skip specific hosts in a larger scan
nmap -6 2001:db8::1Scan an IPv6 target

Host Discovery

Find which hosts are up before spending time on port scans.

CommandDescription
sudo nmap -sn 192.168.1.0/24Ping scan: list live hosts without scanning ports
nmap -Pn 192.168.1.10Skip discovery and treat the host as online
nmap -PS22,80,443 192.168.1.0/24Discover hosts with TCP SYN probes to those ports
nmap -PA80 192.168.1.0/24Discover hosts with TCP ACK probes
sudo nmap -PE 192.168.1.0/24Discover hosts with ICMP echo requests
nmap -n 192.168.1.0/24Skip reverse DNS lookups to speed up the scan

Port Selection

Control which ports the scan covers.

CommandDescription
nmap -p 22 192.168.1.10Scan a single port
nmap -p 22,80,443 192.168.1.10Scan a list of ports
nmap -p 1-1024 192.168.1.10Scan a port range
nmap -p- 192.168.1.10Scan all 65535 TCP ports
nmap -F 192.168.1.10Fast scan of the top 100 ports
nmap --top-ports 20 192.168.1.10Scan the 20 most common ports
sudo nmap -sU -sS -p U:53,T:80,443 192.168.1.10Mix UDP and TCP ports, which needs both scan types

Scan Types

Pick how nmap probes each port. The raw-packet scans need root.

CommandDescription
sudo nmap -sS 192.168.1.10TCP SYN scan: fast, the default when running as root
nmap -sT 192.168.1.10TCP connect scan: the fallback for an unprivileged user
sudo nmap -sU 192.168.1.10UDP scan: slow, so pair it with --top-ports
sudo nmap -sA 192.168.1.10ACK scan: map which ports a firewall filters
sudo nmap -sn 192.168.1.0/24No port scan at all, discovery only
nmap -sL 192.168.1.0/24List scan: show the targets without sending probes

Service and OS Detection

Identify what is listening and what the host is running.

CommandDescription
nmap -sV 192.168.1.10Detect service names and version numbers
nmap -sV --version-intensity 9 192.168.1.10Probe harder for versions, from 0 (light) to 9
sudo nmap -O 192.168.1.10Guess the operating system from TCP/IP fingerprints
sudo nmap -A 192.168.1.10Aggressive scan: -sV, -O, default scripts, and traceroute
sudo nmap --traceroute 192.168.1.10Trace the route to each target

Timing and Performance

Trade speed against accuracy and network load.

CommandDescription
nmap -T4 192.168.1.10Faster timing, a good default on a local network
nmap -T2 192.168.1.10Slower and gentler on fragile or busy networks
nmap --min-rate 1000 192.168.1.0/24Send at least 1000 packets per second
nmap --max-retries 1 192.168.1.0/24Give up sooner on unanswered probes
nmap --host-timeout 5m 192.168.1.0/24Abandon any host still scanning after 5 minutes

Output Formats

Save results for review, diffing, or scripting.

CommandDescription
nmap -oN scan.txt 192.168.1.10Write human readable output to a file
nmap -oX scan.xml 192.168.1.10Write XML for other tools to parse
nmap -oG scan.gnmap 192.168.1.10Write grepable output for grep and awk
nmap -oA scan 192.168.1.10Write all three formats using one base name
nmap --append-output -oN scan.txt 192.168.1.11Append to an existing output file

NSE Scripts

Run the Nmap Scripting Engine for deeper checks.

CommandDescription
nmap -sC 192.168.1.10Run the default script set
nmap --script http-title 192.168.1.10Run one named script
nmap --script "http-*" 192.168.1.10Run every script matching a pattern
nmap --script vuln 192.168.1.10Run the vulnerability script category
nmap --script ssl-enum-ciphers -p 443 example.comList the TLS ciphers a server accepts
nmap --script-help ssh-auth-methodsRead what a script does before running it

Common Use Cases

Practical scans for day-to-day network work.

CommandDescription
sudo nmap -sn 192.168.1.0/24Inventory the hosts on a local network
sudo nmap -p- -T4 192.168.1.10Find every open TCP port on one server
nmap -sV --open 192.168.1.10List running services and their versions
nmap -p 80,443 --open 192.168.1.0/24Locate the web servers on a subnet
sudo nmap -sU --top-ports 20 192.168.1.10Check the most common UDP services
sudo nmap -A -oA audit 192.168.1.10Full audit of one host, saved in every format

Troubleshooting

Quick checks for common nmap problems.

IssueCheck
You requested a scan type which requires root privilegesRun the command with sudo, or use -sT instead of -sS
Note: Host seems downAdd -Pn when ICMP is blocked but the host is reachable
Scan takes far too longAdd -T4, narrow the ports with -F or --top-ports, and add -n
Every UDP port shows open|filteredUDP has no handshake, so add -sV or scan fewer ports for a clearer answer
Results differ from a local port checkThe firewall may filter the port; compare with ss -tulpn on the host itself

Use these guides for broader port and network troubleshooting.

GuideDescription
nmap Command in LinuxFull nmap guide with detailed examples
How to Check Open Ports in LinuxCheck listening ports from the host itself
ss Command in LinuxInspect sockets and listening services
netcat cheatsheetTest single ports and move data between hosts
tcpdump cheatsheetCapture the packets behind a scan result