On this page 20 sections
  1. Start with host discovery
  2. When the host does not respond to discovery
  3. Understand why Nmap reports a result
  4. ARP discovery on local networks
  5. Choose which ports to scan
  6. TCP SYN scan
  7. TCP ACK scan
  8. UDP scanning
  9. Detect services and versions
  10. Nmap Scripting Engine
  11. Operating system detection
  12. Aggressive enumeration
  13. Save scan results
  14. Verbose output and progress
  15. Timing templates
  16. Control retries and packet rate
  17. RTT timeout control
  18. Interface and source options
  19. Use a specific DNS server
  20. A practical enumeration workflow
01

Start with host discovery

Before scanning ports, it is often useful to determine which hosts are reachable. Nmap can perform host discovery without starting a full port scan. The behaviour changes depending on whether the target is on the local network or across routed networks.

Discover hosts in a subnet
nmap -sn 10.20.20.0/24
Use ICMP Echo discovery
nmap -sn -PE target1.sam0x.me
Skip DNS resolution
nmap -sn -n 10.20.20.0/24
02

When the host does not respond to discovery

A host may be online but not respond to the discovery probes Nmap normally uses. The -Pn option tells Nmap to treat the target as online and continue directly with the port scan. This is useful when ICMP or other discovery traffic is filtered.

Treat the target as online
nmap -Pn target1.sam0x.me
03

Understand why Nmap reports a result

When troubleshooting a scan, --reason explains why Nmap considers a host or port to be in a particular state. --packet-trace goes further by displaying packets sent and received during the scan.

Show the reason behind results
nmap --reason target1.sam0x.me
Inspect packets sent and received
nmap --packet-trace target1.sam0x.me
04

ARP discovery on local networks

On a local Ethernet network, Nmap can use ARP for host discovery. ARP is generally very reliable because devices on the same Layer 2 segment must answer ARP requests to communicate. The --disable-arp-ping option disables this behaviour when you specifically want to test another discovery method.

Disable ARP discovery
nmap --disable-arp-ping target1.sam0x.me
05

Choose which ports to scan

The port selection has a major impact on scan time. A quick scan can focus on common ports, while a complete enumeration should eventually cover the full TCP port range.

Fast scan of common ports
nmap -F target1.sam0x.me
Scan the top 1000 ports
nmap --top-ports 1000 target1.sam0x.me
Scan specific ports
nmap -p 22,80,443 target1.sam0x.me
Scan a port range
nmap -p 22-110 target1.sam0x.me
Scan all TCP ports
nmap -p- target1.sam0x.me
06

TCP SYN scan

The SYN scan is one of the most commonly used TCP scan types. Nmap sends a SYN packet and evaluates the response without completing a normal TCP connection. It is commonly used for efficient TCP port discovery.

TCP SYN scan
sudo nmap -sS target1.sam0x.me
SYN scan all TCP ports
sudo nmap -sS -p- target1.sam0x.me
07

TCP ACK scan

An ACK scan is mainly useful for understanding firewall filtering behaviour rather than determining whether a service is listening. It can help distinguish between filtered and unfiltered ports depending on how the target network handles ACK packets.

TCP ACK scan
sudo nmap -sA target1.sam0x.me
08

UDP scanning

UDP enumeration is different from TCP because many UDP services do not respond when a probe is sent. This can make UDP scans slower and results may appear as open|filtered when Nmap cannot determine the exact state.

UDP scan
sudo nmap -sU target1.sam0x.me
Scan common UDP ports
sudo nmap -sU --top-ports 50 target1.sam0x.me
09

Detect services and versions

Finding an open port is only the beginning. The -sV option probes discovered services to identify the application, protocol and possible version running behind each port.

Service version detection
nmap -sV target1.sam0x.me
Enumerate selected services
nmap -sV -p 22,80,443 target1.sam0x.me
10

Nmap Scripting Engine

The Nmap Scripting Engine (NSE) extends Nmap with scripts for discovery, enumeration and protocol-specific checks. -sC runs the default script category, while --script allows a specific script or group of scripts to be selected.

Run default NSE scripts
nmap -sC target1.sam0x.me
Service detection with default scripts
nmap -sV -sC target1.sam0x.me
Run HTTP enumeration scripts
nmap --script http-enum -p 80,443 target1.sam0x.me
Run SMB OS discovery
nmap --script smb-os-discovery -p 445 target1.sam0x.me
11

Operating system detection

Nmap can estimate the operating system by comparing network responses against its fingerprint database. OS detection is more reliable when Nmap can observe both open and closed ports.

Detect operating system
sudo nmap -O target1.sam0x.me
12

Aggressive enumeration

The -A option enables several enumeration features at once, including OS detection, service/version detection, default NSE scripts and traceroute. It provides a lot of information but also generates more traffic than a focused scan.

Aggressive scan
sudo nmap -A target1.sam0x.me
13

Save scan results

Saving results is important when scans are part of a larger enumeration process. Nmap supports normal text, XML, grepable output and -oA, which creates several output formats from a single scan.

Save in normal format
nmap -sV target1.sam0x.me -oN target1.txt
Save in XML format
nmap -sV target1.sam0x.me -oX target1.xml
Save in grepable format
nmap -sV target1.sam0x.me -oG target1.gnmap
Save all main formats
nmap -sV target1.sam0x.me -oA scans/target1
14

Verbose output and progress

Long scans can take time. Verbose mode provides additional information while the scan runs, and --stats-every can periodically display scan progress.

Verbose scan
nmap -v target1.sam0x.me
More verbose output
nmap -vv target1.sam0x.me
Display statistics every 5 seconds
nmap -p- --stats-every=5s target1.sam0x.me
15

Timing templates

Nmap timing templates range from T0 to T5. Lower values are slower and more conservative, while higher values make the scan more aggressive. Faster is not always better because packet loss, latency or rate limiting can reduce scan accuracy.

Slower scan
nmap -T2 target1.sam0x.me
Common faster scan
nmap -T4 target1.sam0x.me
16

Control retries and packet rate

Performance can also be adjusted directly. --max-retries limits how often Nmap retransmits probes, while --min-rate requests a minimum packet sending rate. These options can reduce scan time but aggressive values may cause ports to be missed on unstable networks.

Limit retries
nmap -p- --max-retries 2 target1.sam0x.me
Set a minimum packet rate
nmap -p- --min-rate 300 target1.sam0x.me
17

RTT timeout control

Round-trip timeout values determine how long Nmap waits for responses. Reducing these values can improve performance on fast and predictable networks, but values that are too aggressive may cause valid responses to be missed.

Configure RTT timeouts
nmap --initial-rtt-timeout 50ms --max-rtt-timeout 100ms target1.sam0x.me
18

Interface and source options

Nmap can be instructed to use a specific network interface, source address or source port. These options are mainly useful when working with multiple interfaces, routing scenarios or controlled network testing.

Use a specific interface
sudo nmap -e eth0 target1.sam0x.me
Specify a source IP
sudo nmap -S 10.20.20.10 target1.sam0x.me
Specify a source port
sudo nmap -g 53 target1.sam0x.me
19

Use a specific DNS server

Nmap can perform DNS resolution through a specified DNS server instead of relying only on the system resolver.

Specify DNS server
nmap --dns-server 10.20.20.53 target1.sam0x.me
20

A practical enumeration workflow

A useful workflow is to start with discovery, identify open ports, and only then perform deeper enumeration against the services that were actually discovered. This keeps scans organised and avoids running every option at once.

1. Host discovery
nmap -sn 10.20.20.0/24
2. Full TCP port discovery
sudo nmap -sS -p- --min-rate 300 --stats-every=5s target1.sam0x.me -oA scans/target1-ports
3. Enumerate discovered services
nmap -sV -sC -p 22,80,443 target1.sam0x.me -oA scans/target1-services