Nmap ("Network Mapper") is a free and open source utility for network discovery and security auditing. Many systems and network administrators also find it useful for tasks such as network inventory, managing service upgrade schedules, and monitoring host or service uptime. Nmap uses raw IP packets in novel ways to determine what hosts are available on the network, what services (application name and version) those hosts are offering, what operating systems (and OS versions) they are running. It was designed to rapidly scan large networks, but works fine against single hosts.
Privileged (sudo/root): Sends ICMP Echo, TCP SYN (443), TCP ACK (80), and ICMP Timestamp (-PE -PS443 -PA80 -PP).
Unprivileged (Non-root): Sends TCP SYN to ports 80 and 443 using connect().
Local LAN: Automatically uses ARP Ping (IPv4) or ND Ping (IPv6).
Flag
Function
-sL
List Scan - simply list targets to scan
-sn
Ping Scan - disable port scan
-Pn
Treat all hosts as online -- skip host discovery
-PS/PA/PU/PY[portlist]
TCP SYN, TCP ACK, UDP or SCTP discovery to given ports
-PE/PP/PM
ICMP echo, timestamp, and netmask request discovery probes
-PO[protocol list]
IP Protocol Ping
-n/-R
Never do DNS resolution/Always resolve
--disable-arp-ping
No ARP or ND Ping
--traceroute
Trace hop path to each host
bash
# Scan targets within a subnet
sudonmap-sn10.129.2.0/24# Scan targets from a file
sudonmap-sn-iLtargets.txt# Scan IP ranges or multiple specific IPs
sudonmap-sn10.129.2.14-19
sudonmap-sn10.129.2.1810.129.2.1910.129.2.21
# Force ICMP ping on local LAN (bypassing default ARP ping)
sudonmap-sn-PE--disable-arp-ping192.168.1.50# Skip host discovery (treat all host as online)
sudonmap-Pn10.129.2.18
# List Scan (list targets without sending packets)
nmap-sL10.129.2.0/24
While Nmap has grown in functionality over the years, it began as an efficient port scanner, and that remains its core function. The simple command nmap target scans 1,000 TCP ports on the host target. While many port scanners have traditionally lumped all ports into the open or closed states, Nmap is much more granular. It divides ports into six states: open, closed, filtered, unfiltered, open|filtered, or closed|filtered.
Scan all ports in nmap-services file with ratio greater than specified
bash
# Default SYN scan on top 10 ports (Requires root/sudo)
sudonmap10.129.2.28--top-ports=10# TCP Connect scan on port range 1-1024 without host discovery
nmap-sT-p1-1024-Pn-n--disable-arp-ping10.129.2.28
# Fast UDP scan on top 100 ports
sudonmap-sU-F10.129.2.28
# Explicit TCP and UDP port selection in a single command
sudonmap-sS-sU-pU:53,161,T:22,80,44310.129.2.28
# Sequential scan of all 65535 ports (disables port randomization)
sudonmap-p--r10.129.2.28
# Exclude specific ports from scan
sudonmap-p1-1024--exclude-ports80,44310.129.2.28
# Map firewall statefulness using ACK scan
sudonmap-sA-p22,80,443,338910.129.2.28
# Null, FIN, and Xmas scans
sudonmap-sN-p22,8010.129.2.28
sudonmap-sF-p22,8010.129.2.28
sudonmap-sX-p22,8010.129.2.28
# Trace raw packet exchange on port 21
sudonmap-p21--packet-trace-Pn-n--disable-arp-ping10.129.2.28
Enable light mode (alias for --version-intensity 2)
--version-all
Try every single probe (alias for --version-intensity 9)
--version-trace
Trace version scan activity
bash
# Standard service version scan
sudonmap-sV10.129.2.28
# Fast version scan on specific ports
sudonmap-sV--version-light-p22,80,44510.129.2.28
# High-intensity version detection on all ports without exclusion
sudonmap-sV--version-all--allports-p-10.129.2.28
Set the maximum number of OS detection tries against a target
bash
# Standard OS detection
sudonmap-O10.129.2.28
# Limit OS detection to targets with at least one open and one closed TCP port
sudonmap-O--osscan-limit10.129.2.28
# Force aggressive OS guessing when match is not perfect
sudonmap-O--osscan-guess10.129.2.28
The Nmap Scripting Engine (NSE) is one of Nmap's most powerful and flexible features. It allows users to write (and share) simple scripts (using the Lua programming language) to automate a wide variety of networking tasks.
Flag
Function
-sC
Performs a script scan using the default set of scripts. It is equivalent to --script=default.
If this option is specified all incoming and outgoing communication performed by a script is printed.
--script-updatedb
This option updates the script database found in scripts/script.db.
bash
# Loads all scripts whose name starts with http-
nmap--script"http-*"# Loads every script except for those in the intrusive category.
nmap--script"not intrusive"# Loads all scripts that are in the default category or the safe category or both.
nmap--script"default or safe"# Loads those scripts that are in both the default and safe categories.
nmap--script"default and safe"# Loads scripts in the default, safe, or intrusive categories, except for those whose names start with http-.
nmap--script"(default or safe or intrusive) and not http-*"# A complex example of script arguments is
nmap--script-args'user=foo,pass=",{}=bar",whois={whodb=nofollow+ripe},xmpp-info.server_name=localhost'# For example if you want help about the ftp-anon script, you would run
nmap--script-helpftp-anon
# Preview of what scripts will be run for a specification, for example with
nmap--script-helpdefault
# This option is generally used by itself:
nmap--script-updatedb
Specify maximum number of port scan probe retransmissions
--host-timeout <time>
Give up on slow target hosts
--script-timeout <time>
Set a ceiling on script execution time
--scan-delay / --max-scan-delay <time>
Adjust minimum or maximum delay between probes
--min-rate / --max-rate <number>
Directly control the scanning rate in packets per second
--defeat-rst-ratelimit
Ignore RST rate limits to speed up SYN scans
--defeat-icmp-ratelimit
Ignore ICMP rate limits to speed up UDP scans
bash
# Aggressive scan template for modern/fast networks
sudonmap-T410.129.2.28
# Force a minimum packet rate (packets per second) for rapid enumeration
sudonmap--min-rate500010.129.2.28
# Limit retransmissions and give up on slow hosts after 15 minutes
sudonmap--max-retries2--host-timeout15m10.129.2.28
# Ignore RST rate limits for fast TCP SYN open-port discovery
sudonmap-sS--defeat-rst-ratelimit-p-10.129.2.28
# Ignore ICMP rate limits to accelerate UDP scans
sudonmap-sU--defeat-icmp-ratelimit10.129.2.28
# Fine-tune probe timeouts for local network responsiveness
sudonmap--min-rtt-timeout100ms--max-rtt-timeout300ms10.129.2.28
Network obstructions such as firewalls can make mapping a network exceedingly difficult. Nmap offers many features to help understand these complex networks, and to verify that filters are working as intended. It even supports mechanisms for bypassing poorly implemented defenses.
Flag
Function
-f / --mtu <number>
fragment packets; using the specified MTU
-D <decoy1[,decoy2][,ME][,...]>
Cloak a scan with decoys
-S <IP_Address>
Spoof source address
-e <interface>
Use specified interface
--source-port <portnumber> / -g <portnumber>
Spoof source port number
--data <hex string>
Append custom binary data to sent packets
--data-string <string>
Append custom string to sent packets
--data-length <number>
Append random data to sent packets
--ip-options <opts>
Send packets with specified ip options
--ttl <value>
Set IP time-to-live field
--randomize-hosts
Randomize target host order
--spoof-mac <MAC address, prefix, or vendor name>
Spoof MAC address
--proxies <Comma-separated list of proxy URLs>
Relay TCP connections through a chain of proxies
--badsum
Send packets with bogus TCP/UDP checksums
--adler32
Use deprecated Adler32 instead of CRC32C for SCTP checksums
bash
# fragment packets; using the specified MTU
sudonmap-f10.129.2.28
sudonmap-f-f10.129.2.28
sudonmap--mtu2410.129.2.28
# Cloak a scan with decoys
sudonmap-D10.129.2.1,10.129.2.2,ME,RND:310.129.2.28
# Spoof source address
sudonmap-S10.129.2.50-eeth0-Pn10.129.2.28
# Spoof source port number
sudonmap--source-port5310.129.2.28
sudonmap-g2010.129.2.28
# Append custom binary data to sent packets
sudonmap--data0xdeadbeef10.129.2.28
# Append custom string to sent packets
sudonmap--data-string"Scan conducted by Security Ops, extension 7192"10.129.2.28
# Append random data to sent packets
sudonmap--data-length2510.129.2.28
# Send packets with specified ip options
sudonmap--ip-optionsR10.129.2.28
# Set IP time-to-live field
sudonmap--ttl6410.129.2.28
# Randomize target host order
sudonmap--randomize-hosts10.129.2.0/24
# Spoof MAC address
sudonmap--spoof-macApple10.129.2.28
sudonmap--spoof-mac010.129.2.28
sudonmap--spoof-mac01:02:03:04:05:0610.129.2.28
# Relay TCP connections through a chain of proxies
nmap-sV--proxies[http://10.129.2.1:8080](http://10.129.2.1:8080),socks4://10.129.2.2:108010.129.2.28
# Send packets with bogus TCP/UDP checksums
sudonmap--badsum10.129.2.28
# Use deprecated Adler32 instead of CRC32C for SCTP checksums
sudonmap--adler3210.129.2.28