Nmap commands

Nmap 7.991 command-line options and scan types, taken from the project's own reference guide at nmap.org and grouped by task. One Command column covers Windows, macOS and Linux, which share the same flags. Rows are bare options or scan-type flags; words in capitals are placeholders you replace. A target is always required, most raw-packet scans need root or an administrator account, and the last group lists keys you press while a scan is running.

104 commands in 11 sections. Checked row by row against Nmap Reference Guide: Runtime Interaction (nmap.org, Nmap 7.991) on . Edited by Jay.

Target specification 14

CommandWhat it does
nmap TARGETBasic scanAny argument that is not an option counts as a target; a hostname is scanned at its first DNS address only.
192.168.10.0/24Scan a CIDR blockAppending /NUMBITS keeps that many leading bits fixed; /24 covers 256 addresses, and /0 would target the whole Internet.
192.168.0-255.1-254Scan octet rangesEach octet takes numbers, lists or ranges, so network and broadcast addresses can be left out; IPv6 has no octet ranges.
nmap scanme.nmap.org 192.168.0.0/8 10.0.0,1,3-7.-Mix several target typesHostnames, CIDR blocks and octet ranges can be given together on one command line, separated by spaces.
-iL FILEInput from fileEntries may be addresses, hostnames, CIDR blocks or octet ranges separated by spaces or newlines; a hyphen as the name reads standard input.
-iR NUMScan random targetsPrivate, multicast and unallocated ranges are skipped automatically, and 0 keeps generating targets without end.
--exclude HOSTSExclude hosts from a scanTakes normal target syntax, so single hosts, CIDR blocks or octet ranges can be cut out of a larger range.
--excludefile FILEExclude hosts listed in a fileEntries are separated by newlines, spaces or tabs, and the file may carry comments that start with #.
-6Enable IPv6 scanningPing, port and version scans and NSE work over IPv6; give targets as IPv6 addresses or hostnames.
--resolve-allScan every resolved addressStill limited to one address family: IPv4 addresses unless -6 is given, then IPv6.
-nSkip reverse DNSLeaving out the name lookups can shorten a scan a lot, because DNS is often the slow step.
-RReverse-resolve every targetBy default only hosts found to be up get a reverse DNS lookup.
--dns-servers SERVERSUse specific DNS serversReplaces the servers from resolv.conf or the Windows registry; ignored with --system-dns, and several servers are often faster.
--system-dnsUse the system resolverResolves one address at a time through the operating system instead of Nmap's parallel queries, so it is slower.

Host discovery 13

CommandWhat it does
-snPing sweepPrints only the hosts that answered; traceroute and NSE host scripts can still be added to the run.
-sLList targets onlyReverse DNS still runs, so host names appear, and the total number of addresses is printed at the end.
-PnSkip host discoveryEvery address given is then scanned as if it were up, so a /16 range means all 65,536 addresses.
-PSTCP SYN pingProbes port 80 unless a port list follows with no space, as in -PS22-25,80.
-PATCP ACK pingA live host answers the unexpected ACK with a RST; pairing it with -PS helps past firewalls that only block incoming SYN.
-PUUDP pingWithout a port list it uses port 40125, an unusual port chosen because probing open ports is undesirable here.
-PEICMP echo pingFirewalls and hosts often drop echo requests today, so discovery by ICMP alone seldom finds everything.
-PPICMP timestamp pingUseful where administrators block echo requests but forget that other ICMP queries also reveal a host.
-PMICMP address mask pingAnother ICMP query type that can find hosts when only echo requests are filtered.
--disable-arp-pingTurn off ARP discoveryOn a local Ethernet segment ARP or Neighbor Discovery runs even with -Pn; this stops it, which helps behind proxy ARP.
--tracerouteTrace the path to hostsRuns after the scan, using its results to pick a port and protocol; it does not work with -sT or -sI.
-PYSCTP INIT pingSends an SCTP packet with an INIT chunk; a port list may follow with no space, otherwise port 80 is used.
-POIP protocol pingSends packets with the given protocol numbers in the IP header; ICMP, IGMP and IP-in-IP get correct headers, others just the IP header.

Scan techniques 15

Most scan types send raw packets and so need root on Unix; without those rights nmap falls back to the TCP connect scan.

CommandWhat it does
-sSTCP SYN scanNever completes a connection, so it is quick and fairly stealthy; it needs raw-packet privileges, and without them -sT is the default.
-sTTCP connect scanAsks the operating system to open each connection, so it works without raw-packet privileges.
-sUUDP scanCan be combined with a TCP scan such as -sS in the same run; slow because hosts rate-limit ICMP port-unreachable replies.
-sATCP ACK scanNever finds open ports; it maps firewall rules, showing which ports are filtered and whether the filter is stateful.
-sWTCP Window scanLike the ACK scan, but reads the window size of RST replies to tell open from closed on some systems.
-sMTCP Maimon scanSends FIN/ACK probes and otherwise works like the NULL, FIN and Xmas scans.
-sNTCP NULL scanSends packets with no flags set; RFC-compliant stacks reply only from closed ports.
-sFTCP FIN scanSends a lone FIN flag; one of three scans that exploit a loophole in the TCP RFC.
-sXTCP Xmas scanSets FIN, PSH and URG together; reads port states the same way as the NULL and FIN scans.
--scanflags FLAGSCustom TCP flags scanTakes a number or any mix of URG, ACK, PSH, RST, SYN and FIN, such as URGACKPSHRSTSYNFIN.
-sI ZOMBIEIdle scan through a zombieNo probe reaches the target from your own address; the zombie host's IP ID sequence reveals the open ports.
-sYSCTP INIT scanThe SCTP counterpart of a SYN scan, mostly relevant to SS7/SIGTRAN services.
-sZSCTP COOKIE ECHO scanLess obvious than an INIT scan: open ports drop the chunk silently while closed ones answer with ABORT.
-sOIP protocol scanCycles through IP protocol numbers instead of ports, and still uses -p to choose which numbers to try.
-b HOSTFTP bounce scanUses an FTP server that allows proxy connections to scan other hosts; most servers no longer support it.

Port specification 9

CommandWhat it does
-p PORTSSpecific portsTakes single numbers and hyphen ranges such as 1-1023; a range with an open end defaults to 1 or 65535.
-p-All portsAn open-ended range runs from 1 to 65535; port 0 is scanned only when named explicitly.
-p U:53,111,137,T:21-25,80,139,8080Mix UDP and TCP portsT:, U:, S: and P: prefixes assign ports to TCP, UDP, SCTP or IP protocol; add -sU and a TCP scan type to cover both.
-p ftp,http*Ports by service nameNames come from nmap-services; quote the argument so the shell does not expand the wildcard.
--exclude-ports PORTSExclude ports from a scanUses the same syntax as -p; with -sO it excludes protocol numbers instead.
-FFast scanCuts the default list of 1,000 most common ports per protocol down to 100.
-rDon't randomize portsPorts are scanned in sorted order instead of the default shuffled order.
--top-ports NScan the most common portsPicks the N highest-ratio ports in nmap-services, after any --exclude-ports; N must be at least 1.
--port-ratio RATIOScan ports above a frequencyThe ratio is a decimal from 0.0 to 1.0 compared with the frequencies in nmap-services.

Service and version detection 6

CommandWhat it does
-sVService versionProbes the open ports found by a port scan to name the application and read its version.
-AAggressive scanTurns on OS and version detection, the default scripts and a traceroute in one flag; it is intrusive and slow.
--version-intensity LEVELSet probe intensityA number from 0 to 9 chooses how many probes to try; higher is more accurate but slower, and 7 is the default.
--version-lightLight version scanShortcut for intensity 2: much faster, but a few less common services go unidentified.
--version-allExhaustive version scanShortcut for intensity 9, so every probe is tried against each port.
--allportsVersion-scan every portOverrides the Exclude rule that normally skips TCP 9100, where some printers dump pages of junk.

OS detection 3

CommandWhat it does
-OOS detectionGuesses the operating system from TCP/IP stack fingerprints; works best with one open and one closed port.
--osscan-limitSkip unlikely OS targetsDoes not attempt OS detection unless a host has an open and a closed TCP port, saving time on big scans.
--osscan-guessGuess the OS harderPrints near-matches when no exact fingerprint is found, with a confidence percentage for each guess; --fuzzy is the same.

Timing and performance 8

The -T templates run from 0 to 5; 3 is the default, so -T3 changes nothing on its own.

CommandWhat it does
-T4Fast timing templateRecommended for a quick, reliable LAN; it caps the per-probe delay and bounds the round-trip timeouts and retries.
-T5Fastest timing templatePushes the scan hard and drops results on unreliable links; the most aggressive of the six -T levels.
-T0Slowest timing templateSerializes the scan to one port at a time with a five-minute wait between probes, which helps slip past an IDS.
--min-rate NUMBERSet a minimum packet rateKeeps nmap sending at least this many packets per second, useful when a scan must finish by a deadline.
--max-rate NUMBERCap the packet rateLimits sending to this many packets per second across the whole scan; fractional values such as 0.1 slow it right down.
--host-timeout TIMEGive up on slow hostsSkips any host that is not finished within the given time; no results are printed for a host that times out.
--max-retries NUMBERLimit probe retransmissionsCaps how often a port-scan probe is resent; a low value speeds up rate-limited hosts, and 0 stops all retries.
--scan-delay TIMEWait between probesForces at least this gap between probes to one host, which copes with rate limiting and can slip under an IDS threshold.

Script scanning 7

CommandWhat it does
-sCRun default scriptsRuns the default set of NSE scripts, the same as --script=default; -A includes it.
--script CATEGORYRun chosen scriptsTakes a comma list of categories (default, safe, vuln and others), script names or directories, or a Boolean expression.
--script-args ARGSPass arguments to scriptsA comma-separated list of name=value pairs; qualify a name with its script, as in xmpp-info.server_name.
--script-args-file FILERead script arguments from a fileThe file may separate arguments by commas or newlines and needs no shell quoting; command-line args override it.
--script-help SCRIPTShow help for scriptsPrints each matching script name, its categories and description, so it also previews what a selection would run.
--script-traceTrace script trafficPrints the data each script sends and receives, one ISO layer above what --packet-trace shows.
--script-updatedbRebuild the script databaseRefreshes scripts/script.db after NSE scripts are added, removed or recategorised; run on its own.

Output and verbosity 13

CommandWhat it does
-oN FILESave normal outputWrites the plain-text report to a file while interactive output still goes to the screen.
-oX FILESave XML outputWrites a parser-friendly XML file that GUIs, databases and other tools import.
-oG FILESave grepable outputOne line per host for grep and awk; it is deprecated in favour of XML but still widely used.
-oA BASENAMESave all three formatsWrites BASENAME.nmap, BASENAME.xml and BASENAME.gnmap together, the habit worth forming before a long scan.
-vVerbose outputPrints open ports and progress as they are found; repeat as -vv for more detail.
-dDebug outputFloods the terminal with internal detail; raise the level with -dd up to -d9.
--reasonShow why a port has its stateNames the packet that decided each port or host state, such as a RST from a closed port.
--openShow open ports onlyHides closed and filtered ports, and any host with no open or possibly-open port.
--packet-traceTrace every packetSummarises each packet sent or received; limit the ports with -p to keep the output readable.
--stats-every TIMEPrint periodic statusPrints a timing update to the screen and XML output after each interval, as with --stats-every 10s.
--append-outputAppend instead of overwriteAdds results to the named output files rather than clobbering them; XML files then need fixing up to parse.
--resume FILEResume an aborted scanContinues a scan from a normal or grepable output file after it was interrupted.
--iflistList interfaces and routesPrints the interfaces and system routes nmap detected, then quits; handy for routing problems.

Firewall and IDS evasion 12

CommandWhat it does
-fFragment packetsSplits the probe into tiny IP fragments so simple filters cannot read the TCP header; repeat for 16-byte fragments.
--mtu MTUSet the fragment sizePicks your own fragment offset in bytes rather than the default eight; do not pair it with -f.
-D DECOYSCloak the scan with decoysMakes the target see scans from the listed decoy addresses too; put ME at your own position or use RND for random ones.
-S IPSet the source addressSends packets from the given IP, needed when nmap cannot work out your address; usually paired with -e and -Pn.
-e INTERFACEChoose the network interfaceTells nmap which interface to send and receive on when it cannot detect the right one by itself.
-g PORTFix the source portSends from a constant port to abuse rules that trust traffic from 53 or 20; --source-port is the long form.
--data-length NUMBERPad packets with random dataAppends that many random bytes to most packets instead of protocol payloads; 0 disables all padding.
--ttl VALSet the IP time-to-liveWrites the given value into the IPv4 TTL field of every packet nmap sends.
--spoof-mac MACSet a fake MAC addressUses the given MAC, vendor name or prefix for raw frames; 0 picks a random one, and it implies --send-eth.
--randomize-hostsShuffle the target orderReorders each group of up to 16,384 hosts so the sweep looks less obvious to network monitors.
--badsumSend a bad checksumDeliberately wrong checksums are dropped by host stacks, so any reply comes from a firewall or IDS.
--proxies URLSRelay through proxiesChains HTTP or SOCKS4 proxies for the connections nmap makes; only NSE and version scans use them so far.

Runtime interaction 4

CommandWhat it does
vorVRaise or lower verbosityPressing v during a running scan shows more, V shows less; lowercase keys increase printing, uppercase decrease it.
dorDRaise or lower debug levelAdjusts how much debugging detail the running scan prints, the same convention as the verbosity keys.
porPTurn packet tracing on or offSwitches the live packet-by-packet trace during a scan without restarting it.
?Show runtime helpPrints the list of keys you can press while a scan is running.

Notes

Discovery to detail

-sn is a ping sweep that lists the hosts answering and runs no port scan — the way to map a subnet quickly. A plain scan then checks the 1,000 most common TCP ports; -p- covers all 65,535, which takes far longer. -sV reads the service and version on each open port, -O guesses the operating system from stack fingerprints, and -A switches on both plus scripts and a traceroute. -sU scans UDP, which is slow because closed ports usually stay silent.

Speed, scope and scripts

-T4 is the timing template to reach for on a reliable network; -T5 is faster still but loses results on flaky links, and -T0 crawls to stay under an IDS. --open hides everything except open ports, and -iL FILE reads targets from a file. --script CATEGORY runs a group of NSE scripts — categories such as default, safe or vuln — while -sC runs just the default set that -A already includes.

Saving results

-oN FILE writes the plain report, -oX FILE writes XML for other tools, and -oA BASENAME writes normal, XML and grepable at once — worth doing before a long scan. -v prints open ports and progress as they appear rather than at the end. Scanning networks you do not own or have written permission to test is illegal in many places; keep to systems you are authorised to examine.

Questions

Does Nmap need root or administrator rights?

Many scan types send raw packets and need root on Unix or an administrator account on Windows. -sT and a plain -sn ping sweep work without them, because they rely on ordinary system calls.

How do I scan every TCP port instead of the common ones?

Use -p- to cover all 65,535 ports. By default Nmap scans the 1,000 most common, and -F cuts that to the top 100 for a faster pass.

What does the -A flag turn on?

It enables OS detection (-O), version detection (-sV), the default scripts (-sC) and --traceroute in a single flag. It is thorough but noisy, so avoid it on networks where you lack permission.

Sources and checks

6 more source pages

Every row on this page was matched to a line in the documentation above on . A binding that could not be found there is not listed.

1 row from the earlier version of this page was removed in that check: duplicates, and bindings the documentation does not list or lists differently.

Found a wrong or missing key? Tell us and it gets checked against the source. How we verify describes the process and its limits.