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.
| State | Meaning | Typical cause |
|---|---|---|
| open | An application accepts connections | Listening service |
| closed | Port reachable, no application listening | Host up, service absent |
| filtered | No reply or ICMP unreachable | Firewall dropping probes |
| unfiltered | Reachable, state undetermined | ACK scan result |
| open|filtered | Cannot tell open from filtered | UDP or FIN scan silence |
| closed|filtered | Cannot tell closed from filtered | Rare IP ID idle scan result |
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.
| Option | Scan type | Best use |
|---|---|---|
-sS | TCP SYN scan | Fast default with raw packet privileges |
-sT | TCP connect scan | Unprivileged users or proxies |
-sU | UDP scan | DNS, SNMP and other UDP services |
-sV | Version detection | Identifying software and versions |
-O | OS fingerprinting | Inferring operating system family |
-sn | Ping sweep only | Inventory without port scanning |
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.
| Tool | Main question answered | Relation to Nmap |
|---|---|---|
| Nmap | What hosts and services are exposed | Reconnaissance baseline |
| Vulnerability scanner | Which known flaws are present | Often uses Nmap-style discovery |
| Metasploit | Can a flaw be exploited | Can import Nmap XML results |
| Burp Suite and OWASP ZAP | Is a web application vulnerable | Tests web ports Nmap found |
| Masscan | Which ports are open at huge scale | Faster, far less detailed |
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.
Legal limits, accuracy pitfalls and common mistakes
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
-6option.
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.