Nmap

On this page 7

Nmap, short for Network Mapper, is an open-source network scanner that sends crafted packets to target systems and interprets the replies to discover live hosts, open ports, running services and operating systems. In security testing and cybersecurity defense, it is the standard tool for the reconnaissance phase, where testers build an accurate map of the attack surface before any exploitation begins.

First released in 1997 and maintained by its original author and a community of contributors, Nmap runs on Linux, Windows and macOS. It combines a fast scanning engine with version detection, OS fingerprinting and the Nmap Scripting Engine, which extends it from a port scanner into a lightweight vulnerability and configuration auditing tool.

How Nmap discovers hosts and ports

Nmap works in stages. Host discovery first decides which addresses respond, using ICMP echo requests, TCP SYN or ACK probes to common ports and, on a local segment, ARP requests, which are the most reliable method there. Only hosts judged alive move on to port scanning, unless the tester disables discovery with the -Pn option.

Each probed port is then classified by the reply it produces. Nmap reports six states, and correct interpretation of them is a core skill, because a filtered result usually indicates a firewall rather than an absent service.

StateMeaningTypical cause
openAn application accepts connectionsListening service
closedPort reachable, no application listeningHost up, service absent
filteredNo reply or ICMP unreachableFirewall dropping probes
unfilteredReachable, state undeterminedACK scan result
open|filteredCannot tell open from filteredUDP or FIN scan silence
closed|filteredCannot tell closed from filteredRare IP ID idle scan result
Port states reported by Nmap

Nmap scan types and when to use them

Nmap offers several scan techniques that trade speed, stealth and accuracy against one another. The default for privileged users is the TCP SYN scan, often called a half-open scan, because it never completes the three-way handshake and therefore leaves fewer application-level log entries.

OptionScan typeBest use
-sSTCP SYN scanFast default with raw packet privileges
-sTTCP connect scanUnprivileged users or proxies
-sUUDP scanDNS, SNMP and other UDP services
-sVVersion detectionIdentifying software and versions
-OOS fingerprintingInferring operating system family
-snPing sweep onlyInventory without port scanning
Common Nmap scan techniques

UDP scanning is slow because closed UDP ports answer with rate-limited ICMP messages, so a full UDP scan of one host can take many minutes or hours. Testers therefore restrict it to the most common ports with --top-ports. Timing templates from -T0 to -T5 control parallelism and delays; -T4 is a common choice on reliable networks, while lower values reduce load on fragile devices.

The Nmap Scripting Engine

The Nmap Scripting Engine (NSE) runs scripts written in the Lua language against discovered hosts and services. Scripts are grouped into categories such as default, safe, discovery, vuln, auth, brute and intrusive, which lets testers select a risk level rather than individual scripts.

Typical NSE tasks include enumerating TLS cipher suites, reading SMB shares, retrieving HTTP titles and checking for specific known vulnerabilities. The -sC option runs the default script set, which is designed to be useful and reasonably safe. Scripts in the intrusive and brute categories can lock accounts or crash weak services and require explicit agreement in the test scope.

Nmap compared with other security testing tools

Nmap is a discovery and enumeration tool, not a full vulnerability scanner or exploitation framework. It answers what is exposed and what is running; other tools in the security testing toolkit answer whether that exposure is exploitable.

ToolMain question answeredRelation to Nmap
NmapWhat hosts and services are exposedReconnaissance baseline
Vulnerability scannerWhich known flaws are presentOften uses Nmap-style discovery
MetasploitCan a flaw be exploitedCan import Nmap XML results
Burp Suite and OWASP ZAPIs a web application vulnerableTests web ports Nmap found
MasscanWhich ports are open at huge scaleFaster, far less detailed
How Nmap fits among related tools

Nmap output in XML format (-oX) feeds reporting tools and frameworks, while the grepable format (-oG) suits quick shell processing. Saving every scan with -oA is standard practice in penetration testing because results become evidence in the final report.

Scanning systems without written authorization may breach computer misuse laws or provider terms in many jurisdictions, even when no exploitation follows. Professional testers work from a signed rules of engagement document that lists permitted address ranges, times and techniques.

  • Trusting version banners blindly: administrators can change banners, and backported patches keep old version strings.
  • Skipping UDP: many serious exposures, such as open SNMP, appear only on UDP ports.
  • Scanning too aggressively: high timing values can overload industrial controllers, printers and old embedded devices.
  • Misreading filtered ports: a filtered port is unknown, not proven closed.
  • Forgetting IPv6: hosts may expose services on IPv6 that the IPv4 firewall blocks; use the -6 option.

Blue teams also use Nmap defensively, for asset inventory and exposure monitoring. Comparing scheduled scans with the Ndiff utility reveals new open ports quickly, which is often the first sign of shadow IT or a misconfigured firewall change.

The idea in brief

Nmap is a tool that knocks on the doors of computers on a network and notes which ones answer. From the replies, it works out which machines are switched on, which services they offer and often which software they run.

It is a bit like walking around a building and checking which doors and windows are unlocked. Doing this on your own building is good practice; doing it on someone else’s building without permission is not acceptable.

A practical scenario

A penetration tester is hired by a mid-sized manufacturer to assess its office network of about 500 addresses in a /23 range. The signed scope allows scanning during evening hours but excludes the production line controllers on a separate segment.

She starts with a ping sweep using -sn and finds 212 live hosts. A SYN scan of the top 1,000 TCP ports with version detection and default scripts follows, and a limited UDP scan of the top 50 ports runs overnight. All results are saved with -oA for the report.

The scans reveal a forgotten Telnet service on a network switch, an SNMP service answering to a default community string and an old web server with an outdated TLS configuration. These three findings become the priority items in the report, and the IT team closes them within a week. A repeat scan a month later confirms the fixes and serves as the new baseline for quarterly exposure checks.