Nmap (Network Mapper) is a powerful, open-source network scanning tool used for network discovery, security auditing, and vulnerability detection. It's one of the most essential tools in a penetration tester or network administrator's toolkit. Nmap works by sending specially crafted packets to target hosts and analyzing the responses to determine hosts' availability, open ports, services running, versions, and operating systems.
Nmap supports powerful features such as scriptable interactions with the target (via NSE — Nmap Scripting Engine), stealth scanning, version detection, and more. It is widely used in both offensive (reconnaissance, enumeration) and defensive (network auditing, exposure assessment) contexts.
sudo apt update
sudo apt install nmap
brew install nmap
Zenmap).nmap -sn 192.168.1.0/24
nmap 192.168.1.1
nmap -p 22,80,443 192.168.1.1
nmap -p- 192.168.1.1
nmap -sV 192.168.1.1
nmap -O 192.168.1.1
nmap -A 192.168.1.1
nmap -A 192.168.1.0/24
| Scan Type | Command Flag | Description |
|---|---|---|
| TCP SYN Scan | -sS |
Stealth scan, default for root |
| TCP Connect Scan | -sT |
Full TCP connection |
| UDP Scan | -sU |
Scans UDP ports |
| TCP FIN Scan | -sF |
Bypasses some firewalls |
| NULL Scan | -sN |
No flags set, evasion technique |
| Xmas Scan | -sX |
FIN, URG, and PSH flags set |
| SCTP INIT Scan | -sY |
SCTP INIT scan for SCTP ports |
nmap -sC 192.168.1.1
nmap --script http-title 192.168.1.1
nmap --script vuln 192.168.1.1
nmap -sV --script=vuln 192.168.1.1
| Output Format | Flag | Description |
|---|---|---|
| Normal | -oN |
Human-readable output |
| XML | -oX |
Useful for parsing |
| Grepable | -oG |
Output in grep-friendly format |
| All formats | -oA |
Output in all three major formats |
Example:
nmap -oA scan_results -sV 192.168.1.1
nmap -sS -Pn -D decoy1,decoy2,target 192.168.1.1
nmap --script vuln -sV 192.168.1.1
nmap -sU -p 161 192.168.1.0/24
| Category | Description |
|---|---|
auth |
Authentication bypass checks |
broadcast |
Network broadcast discovery |
brute |
Brute force logins |
default |
Default scripts for quick info |
discovery |
Host and service discovery |
exploit |
Known exploits |
external |
External services (e.g., WHOIS) |
malware |
Malware-related detection |
vuln |
Vulnerability detection |
-sS for stealthier scans if you're root.-A) on sensitive networks unless authorized.-T0 (paranoid) to -T5 (insane).-oA for outputting scan results and store them in a report.