Lesson 02 of 5
Nmap Host Discovery and Port Scanning: -sn, -Pn, -p and Port States
4 min read
Find live hosts, choose which ports to scan, and understand open, closed and filtered.
Before Nmap scans ports, it first checks which hosts are alive. This step is called host discovery (or a "ping scan"). On a big network it saves a lot of time, because Nmap won't waste effort on addresses where nothing is switched on.
Find live hosts with nmap -sn
sudo nmap -sn 192.168.1.0/24
-sn means "find live hosts, but don't scan their ports". On your local network the output usually includes each device's MAC address and vendor, like TP-Link, Apple or Samsung.
How does Nmap decide a host is up? It depends on where you are:
- Local network, with sudo – Nmap sends ARP requests. This is the most reliable method, because a device has to answer ARP to talk on the network at all.
- Other networks, with sudo – it sends an ICMP echo (ping), a TCP SYN to port 443, a TCP ACK to port 80 and an ICMP timestamp request.
- Without sudo – it tries to connect to ports 80 and 443.
When a host blocks ping: -Pn
Many servers and most Windows machines block ping. Nmap then decides the host is down and skips it, even if it has open ports. You'll see a message like "Host seems down. If it is really up, but blocking our ping probes, try -Pn".
Use -Pn to skip host discovery and scan anyway:
nmap -Pn 10.10.10.5
Use -Pn on single targets you know are up. On a large range it's very slow, because Nmap fully scans every address, even the empty ones.
Choose which ports to scan with -p
By default Nmap scans the top 1,000 TCP ports. There are 65,535, so it's easy to miss something. Control it with these options:
nmap -p 22 192.168.1.10 # one port
nmap -p 22,80,443 192.168.1.10 # a list of ports
nmap -p 1-1000 192.168.1.10 # a range
nmap -p- 192.168.1.10 # all 65,535 TCP ports
nmap -F 192.168.1.10 # fast: top 100 ports
nmap --top-ports 20 192.168.1.10 # top 20 ports
nmap -p http,ssh 192.168.1.10 # by service name
Pro tip: in CTFs and real pentests, always run a -p- scan at some point. Services hidden on high ports like 8080, 8443 or 31337 are very common.
Nmap port states explained
Nmap puts every port into one of six states:
- open – an application is accepting connections. This is what you're looking for.
- closed – the port is reachable but nothing is listening. It still proves the host is up.
- filtered – Nmap got no reply (or an ICMP error) because a firewall is dropping its packets, so it can't tell whether the port is open.
- unfiltered – the port is reachable, but Nmap can't tell if it's open or closed. You only see this with an ACK scan (-sA).
- open|filtered – Nmap can't decide between open and filtered. Very common in UDP scans, because open UDP ports often stay silent.
- closed|filtered – Nmap can't decide between closed and filtered. Only seen in the rare idle scan.
Ask Nmap to explain each result with --reason:
nmap --reason -p 22,80,443 scanme.nmap.org
Next to each port you'll see the evidence, such as syn-ack (open), reset or conn-refused (closed) and no-response (filtered).
Options for cleaner results
nmap --open 192.168.1.0/24 # show only open ports
nmap -n 192.168.1.0/24 # skip DNS lookups (faster)
nmap -v 192.168.1.10 # verbose: print results as they're found
Press Enter while a scan is running and Nmap prints its progress and an estimated finish time.
Simple words mein (Hinglish)
Pehle Nmap check karta hai ki host zinda hai ya nahi (-sn). Agar target ping block karta hai to -Pn lagao. Ports choose karne ke liye -p use karo, aur poora scan chahiye to -p- (saare 65,535 ports). Result mein open matlab service chal rahi hai, closed matlab host on hai par us port par kuch nahi chal raha, aur filtered matlab beech mein firewall packets rok raha hai.
FAQ
What does nmap -sn do? It finds live hosts without scanning their ports. Older tutorials call it -sP; that option was renamed to -sn.
Why does Nmap say "Host seems down"? The target is probably blocking ping. Run the scan again with -Pn.
What does filtered mean in Nmap? A firewall or filter is blocking Nmap's probes, so it can't tell whether the port is open or closed.
How do I scan all ports with Nmap? Use nmap -p- target. It scans all 65,535 TCP ports.
Practice task
- Run sudo nmap -sn on your home network and count the devices
- Pick one of your own devices and run nmap -p- --open on it
- Run nmap --reason against scanme.nmap.org and match each port to its reason
Next lesson: scan types (-sS, -sT, -sU) and how to detect software versions and operating systems.