
Nmap (“Network Mapper”) is the de facto standard tool for network discovery, security auditing, and inventorying hosts and services. Its power, flexibility, and extensibility make it indispensable for system administrators, penetration testers, and security researchers alike.
This guide will walk you through everything you need to know to use Nmap effectively—from installation to advanced scanning techniques and automation.
What Is Nmap?
Nmap is an open-source utility for network discovery and security auditing. It can:
- Enumerate live hosts on a network
- Identify open ports and the services running on them
- Perform version detection of services
- Determine operating system and hardware characteristics
- Use scripting to automate sophisticated tasks (vulnerability detection, brute-forcing, etc.)
Its versatility spans single-host scans to large enterprise networks.
Installing Nmap
Linux (Debian/Ubuntu)
sudo apt update
sudo apt install nmap
CentOS/RHEL
sudo yum install epel-release
sudo yum install nmap
macOS (with Homebrew)
brew install nmap
Windows
- Download the Windows installer from https://nmap.org/download.html
- Run the installer, selecting optional components (Zenmap GUI, Npcap packet driver).
- Launch “Nmap” from the Start menu or use PowerShell/CMD.
Basic Scan Types
-
Ping Scan
Discovers which hosts are up without port scanning.nmap -sn 192.168.1.0/24 -
TCP SYN Scan (“half-open”)
Fast and stealthy scan of most TCP ports.nmap -sS target.com -
TCP Connect Scan
Full TCP handshake; used when SYN scan is not permitted.nmap -sT target.com -
UDP Scan
UDP scanning is slower and more resource-intensive.nmap -sU target.com -
Version Detection
Probes open ports to determine service version.nmap -sV target.com
Scan Timing and Performance
Nmap’s -T<0–5> timing templates balance speed vs. stealth:
-T0(Paranoid) /-T1(Sneaky) – Very slow, useful against IDS-T3(Normal) – Default-T4(Aggressive) – Fast for LANs-T5(Unpredictable) – Very fast, loud on the network
Example:
nmap -sS -T4 192.168.1.0/24
Port and Service Detection
- Scan specific ports (comma separated or ranges):
nmap -p 22,80,443 10.0.0.5 nmap -p 1-1024 10.0.0.5 - All ports:
nmap -p- target.com
Combine with version detection:
nmap -p 1-65535 -sV target.com
Operating System Fingerprinting
Detect remote OS, hardware, and uptime:
nmap -O target.com
For more accuracy, combine with version detection and increased verbosity:
nmap -O -sV --version-all -v target.com
Nmap Scripting Engine (NSE)
NSE extends Nmap’s functionality with Lua scripts:
- Categories: auth, brute, discovery, malware, vuln, etc.
- Listing available scripts:
ls /usr/share/nmap/scripts - Running a specific script:
nmap --script=http-vuln-cve2017-5638 -p 80 target.com - Running a category:
nmap --script vuln target.com
Popular scripts:
http-enum– enumerate web applicationsssh-brute– brute-force SSH credentialsdns-zone-transfer– check for zone transfer misconfiguration
Output Formats and Logging
- Normal output:
nmap target.com > report.txt - XML output:
nmap -oX report.xml target.com - Grepable output (deprecated but sometimes useful):
nmap -oG report.gnmap target.com - All formats:
nmap -oA myscan target.comThis produces
myscan.nmap,myscan.xml, andmyscan.gnmap.
Evasion, Firewalls, and IDS/IPS
- Fragment packets:
-f - Use decoys:
-D RND:10 - Spoof IP:
-S 1.2.3.4(requires root) - Scan via proxy:
--proxies http://proxy:port - Randomize host order:
-r
Note: Evasion tactics may violate policy or law—use ethically and with permission.
Automating Nmap in Workflows
- Bash loop for multiple targets:
for ip in $(seq 1 254); do nmap -sS -p 22 192.168.1.$ip >> ssh_results.txt done - Integration with other tools:
- Import XML output into vulnerability scanners (e.g., OpenVAS).
- Use Nmap data in Python scripts via
python-libnmapor parsing XML.
- Continuous monitoring: Schedule periodic scans with cron or CI pipelines.
Best Practices and Ethical Considerations
- Obtain permission before scanning third-party networks.
- Limit scan rates to avoid unintended disruption.
- Segment scans to minimize impact on production systems.
- Secure your data: Store scan results in encrypted form if they contain sensitive info.
- Stay compliant: Follow corporate policies and legal requirements (GDPR, HIPAA, etc.).
Further Resources
- Official Nmap documentation and book: https://nmap.org/book/
- Nmap Scripting Engine reference: https://nmap.org/book/nse.html
- Online forums & communities: Reddit r/netsec, StackExchange Information Security
- Advanced tutorials and CTF walkthroughs
Conclusion
Nmap’s versatility, ranging from simple ping sweeps to complex vulnerability audits, makes it a cornerstone of modern network security. By mastering scan types, timing options, scripting, and automation, you’ll gain deep visibility into your infrastructure and be better equipped to detect and mitigate risks. Always practice responsible scanning, respect legal boundaries, and continuously refine your Nmap skills through hands-on exercises and community engagement. Happy scanning!
Discover more from Aree Blog
Subscribe now to keep reading and get access to the full archive.


