Explore our new Cybersecurity Terms Glossary, explained by our experts.

View the Glossary View the Glossary
PRIVIA

Cybersecurity Terms Glossary

What Is Nmap? Basic and Advanced Usage – Part 1

Nmap is an open-source network scanner. Part 1 covers its scan phases, installation on Linux and Windows, and host discovery options from list scans to SYN, ACK, UDP, and ARP pings.

What Is Nmap? Basic and Advanced Usage – Part 1
Home / Blog / Cybersecurity Terms / What Is Nmap? Basic and Advanced Usage – Part 1
27 January 2020

What Is Nmap? Basic and Advanced Usage – Part 1

What Is Nmap? Basic and Advanced Usage – Part 1

Nmap is an open-source tool for network scanning and vulnerability discovery. It can scan large numbers of systems and returns flexible, fast, and meaningful results: whether hosts are up, the state of their ports, which services are running, and which operating system they use. You can also find out whether the services Nmap detects contain known vulnerabilities. Its built-in scripts go further still, producing detailed information about a target and checking it for security weaknesses. Nmap is widely regarded as one of the best tools in its field.

Nmap Scan Phases

For a scan to succeed, Nmap works through a defined sequence of phases.

Pre-Scan Scripts

Nmap includes scripts that gather information about the network before the scan proper begins. For example, scripts such as dhcp-discover and broadcast-dns-service-discovery use broadcast queries to collect information from network services.

Target Enumeration

During target enumeration, Nmap resolves the host specifiers you give it—DNS names, IP addresses, CIDR ranges, and so on—into a list of targets. The -iR option can be used to have Nmap choose random targets.

Host Discovery

Host discovery establishes whether a machine is up. By default, Nmap performs host discovery first and then moves on to port scanning. If you only want host discovery without a port scan, use -sn. If you want to skip host discovery altogether, use -Pn: Nmap then sends no pings and treats every host as up.

Reverse DNS Resolution

Nmap performs reverse DNS resolution on the live machines identified by the ping scan. Under normal conditions this is done only for hosts that are up; the -R option forces it for every target.

Port Scanning

Port scanning is one of Nmap’s core functions. Nmap sends requests to the ports of a live system and determines whether each port is open or closed.

Version Detection

Version detection identifies which service is running on each open port. Nmap compares the responses to its built-in probes against more than 6,500 service signatures. This is enabled with the -sV option.

Operating System Detection

Nmap can also identify the operating system of live machines. It holds a database of how different operating systems respond, sends its own probes to the target, and compares the replies with the entries in that database to determine the operating system. This is enabled with the -O option.

Traceroute

With the --traceroute option, Nmap can determine the route that packets take to each target.

Script Scanning

Nmap includes the Nmap Scripting Engine (NSE), which contains a large collection of scripts. These scripts can be used for many tasks, such as gathering information about a target and detecting vulnerabilities. NSE is built on the Lua programming language and a standard library designed for network information gathering. Scripts typically run once for each port on each host that is discovered. You can run Nmap’s scripts with the --script or -sC options.

Output

Nmap prints the information gathered during the scan to the screen. The results can also be saved in several different file formats.

Installing Nmap

Linux (Debian/Ubuntu)

Running sudo apt-get install nmap in the terminal installs Nmap. You can also download .rpm or .deb packages from the Nmap website and install those.

Installing Nmap with apt-get in a Linux terminal
Figure 211 Installation on Linux

As Figure 2.1.1 shows, the sudo apt-get install nmap command makes installation straightforward.

Linux terminal showing the Nmap installation output
Figure 212 Linux Terminal Screenshot

Windows

To install Nmap on Windows, download the installer from https://nmap.org/download.html, as shown below.

Nmap download page with the Windows installer link
Figure 221 Downloading Nmap for Windows

Next, run the downloaded .exe setup file as an administrator.

Nmap setup wizard running on Windows
Figure 222 Windows Installation

Once installation is complete, you can run nmap.exe from the C:\Program Files (x86)\Nmap directory. The installer also adds Zenmap, Nmap’s graphical user interface.

nmap.exe running in the Windows Command Prompt
Figure 223 Nmap in the Command Prompt

Figure 2.2.3 shows nmap.exe running in the Command Prompt.

Zenmap graphical interface open on Windows
Figure 224 Running Zenmap on Windows

The Nmap and Zenmap tools shown in Figures 2.2.3 and 2.2.4 are also available on Linux, where you can launch them by running the nmap and zenmap commands in the terminal.

Host Discovery in Practice

Host discovery is usually carried out by pinging the systems on a network. However, when the network is large, or when some machines do not respond to ICMP packets, other methods can be used. Nmap can scan a target network without pinging it at all, and it can optionally use TCP SYN, TCP ACK, UDP, and other probes. Whatever the probe type, the aim is the same: to work out from the response whether the machine at a given IP address is genuinely up.

Specifying Target Hosts and Networks

To define targets, give Nmap the IP address or hostname of the target network. Instead of a single IP address, you can supply an address range. Nmap also supports CIDR notation—the /24, /18, and similar suffixes that follow an IP address or hostname. From that suffix, Nmap calculates how many hosts need to be scanned and scans them automatically. For example, entering 192.168.10.0/24 scans 256 hosts. The same works with a hostname: you could start a scan with www.priviasecurity.co.uk/24.

Nmap host discovery command against an IP address range
Figure 31 Sample Host Discovery Query

In Figure 3.1, Nmap is given an IP address range, and the scan covers every address within it.

Specifying a List of IP Addresses

This approach is common in large network scans. Save the hundreds or thousands of IP addresses you have been given to a file, then start the scan with the -iL option.

Nmap scanning targets read from a file with the -iL option
Figure 311 Scanning a Target List with Nmap

As Figure 3.1.1 shows, the -iL option follows the nmap command and points to a file containing IP addresses, which Nmap then scans.

Choosing Random Targets

To scan random IP addresses with Nmap, use the -iR option.

Excluding Out-of-Scope Targets

Defining out-of-scope targets is often overlooked, yet it prevents risky mistakes. IP addresses that must not be scanned are specified with the --exclude option. When there are many of them, save them to a file and use the --excludefile option instead.

Nmap command excluding IP addresses with the --exclude option
Figure 313 Using the exclude Option

As Figure 3.1.3 shows, the IP addresses given after --exclude are left out of the scan. Where there are several addresses to exclude, the --excludefile option can be used.

In Figure 3.1.4, the -sL option is used to list the IP addresses in a network to be scanned.

Nmap -sL output listing the IP addresses in a range
Figure 314 Using the sL Option with Nmap

To scan several unrelated targets, list their IP addresses or hostnames separated by spaces, as shown in Figure 3.1.5.

Nmap scanning several separate targets in a single command
Figure 315 Scanning Multiple Targets at Once with Nmap

Finding the Target Organisation’s IP Addresses

Before a scan, you are usually given the organisation’s main domain. The scan can then be run against the IP addresses behind that domain.

Obtaining DNS Information

The primary purpose of DNS is to resolve domain names to IP addresses, so DNS information needs to be researched first, as shown in Figure 3.2.1.

host command querying DNS record types for a domain
Figure 321 Querying DNS Record Types

In Figure 3.2.1, the host utility on Linux is used to query DNS record types and obtain information about the domain’s name servers. Figure 3.2.2 shows a zone transfer check.

host command attempting a DNS zone transfer
Figure 322 Checking for a Zone Transfer

Figure 3.2.2 shows whether the zone transfer succeeded or failed. To check whether a domain’s IP address falls within the agreed scope, use DNS resolution, traceroute, and whois for the relevant IP address registrations.

Nmap scan with --traceroute showing the intermediate hops
Figure 323 Using Traceroute with Nmap

As Figure 3.2.3 shows, scanning the target domain with the --traceroute option displays the intermediate IP addresses on the way to the target. Figure 3.2.4 shows information gathering based on an IP address.

whois lookup returning registration details for a target IP address
Figure 324 Gathering Information About the Target

In Figure 3.2.4, whois returns information about the target IP address.

DNS Resolution

DNS resolution matters a great deal in host discovery. Nmap performs DNS resolution for every IP address that responds to its host discovery probes. Four options control this behaviour:

-n: tells Nmap not to perform reverse DNS resolution on the IP addresses it finds. This usually shortens the scan.

-R: tells Nmap to perform reverse DNS resolution on every IP address it targets. By default, reverse DNS resolution is carried out only for hosts that are up.

--system-dns: by default, Nmap resolves IP addresses by sending queries to the name servers configured on your machine and listening for the answers, with many requests running in parallel to improve performance. This option makes Nmap use the system resolver instead. Older versions of Nmap also relied on the system resolver for IPv6 addresses.

--dns-servers: by default, Nmap takes its DNS servers from resolv.conf (Unix) or the registry (Win32). This option lets you specify your own. Using several DNS servers is faster, and because the requests can be spread across recursive DNS servers on the internet, it can also improve stealth.

Figure 3.3 applies these options to DNS resolution.

Nmap scan using the --system-dns option
Figure 33 Using the system dns Option with Nmap

Figure 3.3 shows DNS resolution in action, with results obtained using the options described above.

Host Discovery Controls

The host discovery options let you determine whether targets are up or down. To do so, you need to check the responses to the probes sent to each machine.

List Scan (-sL)

A list scan is used to check the target IP addresses. It is a form of host discovery that lists the hosts on the specified network without sending any packets to them.

Nmap list scan output with the -sL option
Figure 341 Running a List Scan with Nmap

Figure 3.4.1 shows a list scan using the -sL option. Adding -Pn skips the ping stage so that the rest of the scan can still proceed.

A preliminary list scan helps you confirm which targets are actually being scanned. Another reason to run one is stealth: some scanning activity triggers IDS alerts, whereas a list scan shows which machines will be targeted without causing them. If the targets might notice the reverse DNS lookups, you can use the --dns-servers option to spread them across anonymous recursive DNS servers.

Disabling Port Scanning (-sn)

Nmap uses the -sn option to identify live hosts on a network quickly, reporting the IP addresses of the hosts it finds. This is known as a “ping scan”. No port scan is performed, although Nmap can still use its host scripts and traceroute probes. A ping scan is more intrusive than a list scan and returns the IP addresses and hostnames of the targets. Figure 3.4.2 shows a ping scan with Nmap.

Nmap ping scan with -sn showing the live hosts
Figure 342 Ping Scan with Nmap

In Figure 3.4.2, a ping scan is run with the -sn option. As the screenshot shows, no port scan has been carried out.

Disabling Ping (-Pn)

Scanning without ping means skipping host discovery. Every machine in the network is passed on to the subsequent stages in turn, as if it were up. Running host discovery across a set of IP addresses takes extra time compared with a no-ping scan. The -Pn option performs a scan without pinging, as shown in Figure 3.4.4.

Other Useful Options

--disable-arp-ping: host discovery on a local network normally sends ARP packets and decides from the replies whether a host is up. This option is useful on networks where a router answers all ARP requests on behalf of other hosts, making every target appear to be up in an ARP scan. It disables the default ARP scan, as shown in Figure 3.4.4.

Nmap scan with ARP and ND ping disabled
Figure 344 Scanning with ARP and ND Ping Disabled

--resolve-all: if a hostname target resolves to more than one address, all of them are scanned. By default, only the first resolved address is scanned.

--traceroute: traceroute runs after the scan, using information from the scan results to choose the port and protocol most likely to reach the target. It works with every scan type except connect scans (-sT) and idle scans (-sI). Traceroute sends packets with a low TTL (time-to-live) to elicit ICMP Time Exceeded messages from the intermediate hops between the scanner and the target host. Standard traceroute implementations start with a TTL of 1 and increase it until they reach the target. Nmap works backwards from a higher TTL instead and uses a caching algorithm to speed up the process.

Host Discovery Techniques

The traditional way to check whether machines on a network are up is to send them ICMP echo requests and look at the replies. Whether a reply arrives tells you whether the machine is up or down. It is a simple and long-established host discovery technique, although many firewalls now block these requests. In Figure 3.5, the -sn -PE options specify an ICMP ping scan, while -R requests reverse DNS resolution for every machine.

Nmap ICMP echo host discovery with the -sn -PE -R options
Figure 35 Nmap Host Discovery Techniques

TCP SYN Ping

The -PS option sends an empty TCP packet with the SYN flag set, by default to port 80. The flag signals an attempt to open a connection to the remote system. If the port is open, the target replies with a SYN/ACK packet; rather than completing the three-way handshake with an ACK, Nmap sends an RST and drops the connection. Either an RST or a SYN/ACK reply shows that the machine is up.

Nmap TCP SYN ping host discovery with the -PS option
Figure 351 Host Discovery with a TCP SYN Probe

TCP ACK Ping

This host discovery technique uses the -PA option. It is similar to SYN ping; the only difference is the flag. A TCP packet with the ACK flag set is sent to the target, by default to port 80, and if the target is up it replies with an RST packet. It is useful when scans using -PS are being blocked.

Nmap TCP ACK ping with the -PA option
Figure 352 Using the TCP ACK Ping Technique with Nmap

UDP Ping

UDP ping uses UDP packets to determine whether systems are up. It is enabled with the -PU option, which takes the same port syntax as -PS and -PA. By default it uses port 40125. The packets sent are usually empty, but because ports 53 and 161 are common services, protocol-specific payloads are sent to them. The --data-length option adds a random payload for all ports. The main advantage of this scan type is that it can get past firewalls and filters that only screen TCP ports.

ICMP Ping Types

Nmap uses ICMP packets in host discovery. It sends ICMP type 8 (echo request) to the target hosts and expects ICMP type 0 (echo reply) in return, but many firewalls block these requests. The -PE option sends an ICMP echo request; this is known as an ICMP ping. Live hosts can also be discovered with timestamp and address mask requests, using the -PP and -PM options respectively.

Nmap scans using ICMP echo, timestamp, and address mask pings
Figure 354 Scanning with ICMP Ping Types

IP Protocol Ping

This scan type uses the protocol number in the header of IP packets. If no protocol is specified, Nmap sends multiple IP packets for ICMP, IGMP, and IP-in-IP. Whether a machine is up is determined from replies that use the same protocol as the probe, or from ICMP messages reporting that the target host is unreachable.

ARP Ping

ARP ping is one of the most commonly used scans on local networks and is enabled with the -PR option. Nmap sends raw ARP requests and so learns the physical (MAC) address of the machine that corresponds to the target IP address.

IP ping and ARP ping scans against an offline target, with their timings
Figure 356 IP Ping Scan and ARP Ping Scan Against an Offline Target

Figure 3.5.6 shows two example scans. In the first, the --send-ip option makes Nmap send IP-level packets even though the target is on the local network. This first example took 3.09 seconds. Because only one target was scanned, it finished quickly, but on a corporate local network with many machines the time adds up. The operating system does not give up on the host until it has sent three ARP requests one second apart. In the second example, the ARP scan completed in 0.47 seconds. Network administrators often block ping packets, but ARP requests and replies are generally not blocked. You can also hide the scanning machine’s MAC address during these scans with the --spoof-mac option.

SCTP INIT Ping

This scan type uses the -PY option, which sends an SCTP packet containing an INIT chunk, by default to port 80. For example, -PY22,80 sends probes to ports 22 and 80. If a port is open, the target returns an INIT-ACK. Instead of continuing with a functional SCTP packet, Nmap replies with an ABORT and ends the association. These responses show that the ports on the target machine are open and that the host is up.

Host Discovery Strategies

Nmap provides a number of options that make host discovery more effective. You choose them according to the type of scan you want to run. They are described below.

-v/--verbose

This option makes Nmap’s output more detailed, including additional information about each host.

Nmap verbose output with the -v option
Figure 361 Using the Verbose Option

--source-port <portnumber>

Firewall administrators often create special rules that keep DNS and FTP ports open. Source port manipulation exploits such rules and is one of the common techniques for bypassing a firewall.

--data-length <length>

This option appends random data to every packet and can be used with TCP, UDP, and ICMP scans. It is one of the methods used to evade many IDS products. Payload size can also act as a fingerprint: a Windows echo request carries 32 bytes of data by default, while a Linux one carries 56, so an IDS that judges the source by payload length may wrongly conclude which operating system the scanning machine is running.

Nmap scan padding packets with the --data-length option
Figure 363 Using the data length Option

--ttl <value>

Setting the outgoing TTL is used in IPv4 ping scans as a safety measure to keep the scan within the boundaries of the local network. Lowering the outgoing --ttl value also reduces the processing load on router CPUs if a routing loop is encountered.

Nmap scan with a custom --ttl value
Figure 364 Using the TTL Option

Timing Templates

Timing templates are preset combinations of settings that speed up a ping scan and the delivery of its results. They are selected with the -T option. There are six templates: paranoid (0), sneaky (1), polite (2), normal (3), aggressive (4), and insane (5).

Nmap scan using a -T timing template
Figure 365 Using a Timing Template

--min-parallelism/--max-parallelism <value>

These options control how many targets are probed in parallel. The <value> sets the number to run at once.

--min-rtt-timeout/--max-rtt-timeout/--initial-rtt-timeout <time>

These options control how long Nmap waits for a response to each probe it sends.

Output Options

The output options include -oA, -oN, -oG, and -oX. For example, -oX writes Nmap’s results in XML format.

--randomize-hosts

Using --randomize-hosts when scanning a network makes the scan less conspicuous, which helps avoid IDS and IPS systems. By default, Nmap scans the machines on a network in sequence, and some IDS and IPS systems can detect and block that pattern.

--reason

Default scan output shows whether a target port is open, but not why. With this option, Nmap explains which discovery probes the target responded to. For instance, during one run Nmap might record an ICMP echo reply as the response, while a second scan might receive an RST packet first and report that instead. To see in detail what kinds of responses the target does or does not give, this option is well worth using.

Nmap output with --reason explaining host and port states
Figure 3610 Using the reason Option

--packet-trace

With --packet-trace, Nmap shows in detail what it does during the scan. It prints every packet sent and received, including details such as sequence numbers, TTL values, and TCP flags.

-D <decoy1,decoy2,...>

Decoys are spoofed IP addresses used to hide the attacker’s real IP address. In Figure 3.6.12, the attacker’s IP address is 192.168.16.163, but the scan was run alongside spoofed addresses such as 192.168.16.138 and 192.168.16.2, given with the -D option. This makes it harder for the people monitoring the network to identify the attacker.

Nmap decoy scan with the -D option and spoofed source addresses
Figure 3612 Using the Decoy Option

-6

Uses IPv6 instead of IPv4 addresses for the scan.

-S <source IP address>, -e <sending device name>

These options let you specify the source IP address and the name of the sending network interface for the scan.

Selecting and Combining Ping Options

Scanning a target effectively can take more than knowing every option. Success rates vary depending on which options you specify and how you combine them, as Figures 3.7a and 3.7b show.

Table of success rates for individual host discovery probes
Figure 37a Success Rates of the Probes Used in Scanning
Table of success rates for combined host discovery probes
Figure 37b Combined Probes and Their Success Rates

You May Be Interested In These

What Is Dirty COW?

Cybersecurity Terms

17 November 2026

What Is Dirty COW?

Read More
What Is AI-Assisted Phishing?

Cybersecurity Terms

17 November 2026

What Is AI-Assisted Phishing?

Read More
What Is Velociraptor?

Cybersecurity Terms

17 November 2026

What Is Velociraptor?

Read More