Nmap
Nmap ("Network Mapper") is the standard tool for discovering what is alive on a network, which ports are open, what services are listening and often which operating system is running. Every penetration test starts here.
What it is
Nmap is a port scanner — but calling it just a port scanner undersells it. It is a network discovery and security auditing tool that answers four questions in sequence: which hosts are up, which ports are open, what service is behind each port, and what version of that service is running.
It was written by Gordon Lyon (known as Fyodor) and released in 1997. It is free and open source, and it ships by default in Kali Linux, Parrot OS and most security distributions. Nmap is not a hacking tool in itself — it produces information. What you do with that information is the offensive part, and that is where authorisation matters.
The feature that makes Nmap more than a scanner is the NSE — Nmap Scripting Engine. Scripts written in Lua can brute-force logins, check for known CVEs, enumerate SMB shares, query DNS records and much more. That turns Nmap from "what is open" into "what is open and what is wrong with it".
How to use Nmap
Follow it exactly as you would in a real session — every command, every line of output, and what each result actually tells you. This is a terminal walkthrough.
Confirm the target is alive before scanning
kali@errordex:~$ ping -c 2 scanme.nmap.org
PING scanme.nmap.org (45.33.32.156) 56(84) bytes of data. 64 bytes from 45.33.32.156: icmp_seq=1 ttl=53 time=28.4 ms 64 bytes from 45.33.32.156: icmp_seq=2 ttl=53 time=28.1 ms --- scanme.nmap.org ping statistics --- 2 packets transmitted, 2 received, 0% packet loss
Fast scan: top 1000 ports with version detection
kali@errordex:~$ nmap -sV -T4 scanme.nmap.org
Starting Nmap 7.94SVN ( https://nmap.org ) Nmap scan report for scanme.nmap.org (45.33.32.156) Host is up (0.031s latency). # 996 ports answered RST — closed, and skipped from the output Not shown: 996 closed tcp ports (reset) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.13 80/tcp open http Apache httpd 2.4.7 ((Ubuntu)) 9929/tcp open nping-echo Nping echo 31337/tcp open tcpwrapped Nmap done: 1 IP address (1 host up) scanned in 12.84 seconds
Full port sweep — find what the fast scan missed
kali@errordex:~$ sudo nmap -sS -p- -T4 --min-rate 1000 scanme.nmap.org
PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 9929/tcp open nping-echo 31337/tcp open tcpwrapped Nmap done: 1 IP address (1 host up) scanned in 61.27 seconds # Same four ports here — but on other hosts this is where you # find 8080, 8443, 9000, 3306, 5432, 6379, 27017 …
Targeted scripts — turn ports into findings
kali@errordex:~$ nmap -sV --script http-headers,http-title -p 80 scanme.nmap.org
PORT STATE SERVICE VERSION 80/tcp open http Apache httpd 2.4.7 ((Ubuntu)) |_http-title: Go ahead and ScanMe! | http-headers: | Date: Sat, 14 Nov 2026 04:12:08 GMT | Server: Apache/2.4.7 (Ubuntu) | X-Frame-Options: (missing) |_ (Connection: close) # Missing security headers = a low-severity but real finding
Save everything — this is your evidence
kali@errordex:~$ nmap -sV -oA scans/scanme_2026-11-14 scanme.nmap.org
Nmap done: 1 IP address (1 host up) scanned in 12.84 seconds $ ls scans/ scanme_2026-11-14.nmap # human readable scanme_2026-11-14.xml # import into Metasploit / tools scanme_2026-11-14.gnmap # grep-able one-liners
Flags & options
| FLAG | WHAT IT DOES |
|---|---|
| -sn | Ping sweep only — find live hosts, no port scan. |
| -sS | SYN scan: half-open, fast, needs root. The default choice. |
| -sT | Connect scan: full handshake, works without root, noisier. |
| -sU | UDP scan. Slow, but the only way to see DNS, SNMP, NTP. |
| -sV | Probe open ports to identify product and version. |
| -O | Guess the operating system from TCP/IP behaviour. |
| -p- | Scan all 65535 ports instead of the top 1000. |
| -p 22,80,443 | Scan only the ports you name. |
| -T0 … -T5 | Timing template. -T4 is fast; -T5 is reckless and causes false results. |
| --min-rate 1000 | Force at least 1000 packets per second. Speeds up big sweeps. |
| --script vuln | Run the NSE vulnerability category against found services. |
| -oA name | Save output in normal, XML and grepable formats. |
| -v / -vv | Verbose — show progress and results as they arrive. |
| --reason | Show why Nmap thinks a port is in that state. |
Why it matters
Every engagement, every CTF box, every internal assessment starts with the same question: what is reachable? Nmap answers it in seconds. The analysts who get good at Nmap are the ones who read the version strings, not the port numbers — "port 8080 open" is noise, "Apache Tomcat 9.0.30" is a lead you can search for a CVE.
How it works
Nmap works by sending carefully crafted packets and analysing what comes back — or what does not come back. The response pattern tells you the state of a port:
- Open — a service accepted the connection.
- Closed — the host replied but nothing is listening; the port is reachable.
- Filtered — no reply at all; a firewall is silently dropping packets.
- Open|filtered — Nmap cannot tell the difference (common with UDP).
The scan type decides which packets are sent. A SYN scan (-sS) sends a TCP SYN, reads the reply and then tears the connection down before it completes — fast and quiet, and it needs root. A connect scan (-sT) completes the full TCP handshake using the operating system, so it works without root but is slower and leaves full connections in logs. A UDP scan (-sU) is slow by nature because UDP gives no acknowledgement.
Service detection (-sV) goes further: after finding an open port, Nmap probes the service and compares the replies against a database of thousands of signatures to identify the product and version — for example "OpenSSH 8.9p1" rather than just "port 22 open". OS detection (-O) analyses subtle differences in how the target's TCP/IP stack behaves.
Sends a TCP SYN. If the port replies SYN-ACK it is open; RST means closed; nothing means filtered. The handshake is never completed, so the connection never appears in the application log.
WHEN TO USEDefault choice on any network where you can use root. Fast, quiet, and the most accurate TCP scan.
TRADE-OFFNeeds raw socket privileges. Some stateful firewalls and IDS engines specifically alert on half-open connections.
Uses the operating system's own connect() call — a full TCP handshake for every port.
WHEN TO USEWhen you have no root, or when scanning through a proxy or SOCKS tunnel where raw packets are impossible.
TRADE-OFFSlower, and every attempt is logged by the application as a real connection. Noisy.
Sends UDP datagrams. An ICMP port-unreachable means closed; a reply means open; silence is ambiguous (open|filtered).
WHEN TO USEAlways at least once — DNS (53), SNMP (161), NTP (123), DHCP (67/68) and TFTP (69) only exist on UDP. Forgotten SNMP with a default community string is a classic finding.
TRADE-OFFSlow by design (no acknowledgements), so scope it to the ports that matter.
Commands & syntax
# ping sweep, no port scan nmap -sn 192.168.1.0/24 # list-only, skip DNS resolution for speed nmap -sn -n 10.0.0.0/24
# SYN scan, all 65535 ports, service + OS detection sudo nmap -sS -sV -O -p- 192.168.1.10 # faster: top 1000 ports, aggressive timing nmap -sV -T4 192.168.1.10 # UDP (slow — scope it to the ports you care about) sudo nmap -sU -p 53,123,161 192.168.1.10
# run the default safe script set nmap -sV --script default 192.168.1.10 # category scans nmap --script vuln 192.168.1.10 nmap --script smb-enum-shares -p 445 192.168.1.10 nmap --script http-headers -p 80,443 example.local
# -oA writes .nmap, .xml and .gnmap in one go
nmap -sV -oA scans/internal_10.10.10.5 10.10.10.5kali@errordex:~/labs$ nmap -sV -T4 scanme.nmap.org Starting Nmap 7.94SVN ( https://nmap.org ) at 2026-11-11 09:12 IST Nmap scan report for scanme.nmap.org (45.33.32.156) Host is up (0.031s latency). Not shown: 996 closed tcp ports (reset) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.13 (Ubuntu Linux; protocol 2.0) 80/tcp open http Apache httpd 2.4.7 ((Ubuntu)) 9929/tcp open nping-echo Nping echo 31337/tcp open tcpwrapped Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 12.84 seconds # Read this carefully: # 22 + OpenSSH 6.6.1 → old, worth checking known issues # 80 + Apache 2.4.7 → version is public, search CVEs for it # 31337 tcpwrapped → access is being filtered by TCP wrappers
Common mistakes
Scanning without permission
This is the one that ends careers. Even a port scan against infrastructure you do not own can be a criminal offence in India under the IT Act.
Using -T5 on real networks
Insane timing causes dropped packets, false "filtered" results and can knock over fragile devices. -T4 is the practical maximum.
Ignoring UDP
DNS (53), SNMP (161), NTP (123) and DHCP live on UDP — and SNMP with a default community string is a classic finding.
Trusting a single scan
Firewalls rate-limit. Scan again with different timing or from a different source before concluding a port is closed.
Not saving output
Re-scanning a large range because you forgot -oA wastes hours.
Assuming the version is accurate
Services lie, banners are faked, and reverse proxies mask the real backend.
Practice safely
Legal practice targets: scanme.nmap.org is maintained by the Nmap project specifically for this purpose — scanning it is authorised. For everything else, build a local lab: a Kali VM plus a Metasploitable VM on a host-only network gives you a realistic target range you fully own.
Structured learning: TryHackMe has a dedicated Nmap room that walks through every flag interactively. Hack The Box machines expect Nmap fluency from the first box.