Network Discovery and Scanning with Nmap
Discover hosts, scan TCP and UDP ports, identify services, and read Nmap output honestly, inside a lab you own.
By the end, you’ll be able to…
- Explain what host discovery, port scanning, service detection, and NSE scripts actually do.
- Choose scan types and port ranges appropriate to an authorised lab.
- Interpret open, closed, filtered, and open|filtered states.
- Use timing and output options to produce reproducible evidence.
- Recognise how firewalls and intrusion detection systems change scan results.
01What Nmap Does, and When You May Use It
Nmap is a network mapper. It sends carefully crafted packets and interprets the replies to answer four related questions: which hosts are reachable, which ports are listening, which software and versions sit behind those ports, and which operating system the target is likely running. A fifth feature, the Nmap Scripting Engine, extends the tool with small programs that query services, check configuration, and collect information.
The scanning itself is not magic. Nmap builds packets at the transport layer, sends them, and classifies the responses using rules that ship with the tool. A SYN-ACK means a TCP port accepted the connection. A RST means the host is reachable but nothing is listening. Silence usually means a filter dropped the probe. Understanding those three outcomes is more important than memorising every flag.
Authorization comes first. Scan only hosts you own or have explicit written permission to test. Unauthorised scanning can violate computer-misuse law, breach a cloud provider's terms, trigger an incident response, or disrupt fragile industrial and medical devices. Write down the scope, the source address, the time window, and a stop condition before you send the first packet. A lab network you control is the correct place to practise.
LAB SCAN RECORDDate: 2026-11-01 09:00-11:00 UTCTester: your nameSource: 10.10.10.20 (kali-vm)Targets: 10.10.10.30 (target-vm), 10.10.10.0/24 lab subnetAuthorised: lab owner; note stored in lab-charter.mdOut of scope: host operating system, home router, internet, cloud accounts, any device owned by another personStop if: a probe reaches a non-lab address, or the target becomes unstable or unresponsive02Host Discovery Before Port Scanning
Host discovery asks which addresses answer at all. The -sn option performs a ping scan: Nmap sends ARP requests on a local Ethernet segment and a mix of ICMP echo, TCP SYN, and other probes across routed networks, then lists the addresses that respond. On a local subnet, ARP is the most reliable signal because a host normally cannot ignore an ARP request without losing its own connectivity.
A host that blocks ICMP may look down even though it is running services. That is why -Pn exists: it skips discovery and treats the target as online, sending port probes directly. -Pn is not a licence to scan; it is a technical choice. Use it when you have reason to believe the host is present and you are authorised to test it.
Read the summary carefully. The MAC address, when present, identifies the local network interface and often the virtualisation platform. Latency tells you whether the host is on the same segment or across a router. A scan that reports zero hosts is not proof that the network is empty; it may mean discovery probes are filtered. Confirm with a second method before drawing conclusions.
# Discover live hosts on the lab network without scanning ports.sudo nmap -sn 10.10.10.0/24# Skip discovery and treat one target as online.sudo nmap -Pn -p 22,80 10.10.10.30# Ask Nmap to explain why it considers a host up.sudo nmap -sn --reason 10.10.10.30Starting Nmap 7.94SVN at 2026-11-01 09:12 UTC Nmap scan report for 10.10.10.1 Host is up (0.00042s latency). MAC Address: 52:54:00:12:34:56 (QEMU virtual NIC) Nmap scan report for 10.10.10.20 Host is up (0.00031s latency). Nmap scan report for 10.10.10.30 Host is up (0.00058s latency). MAC Address: 52:54:00:AB:CD:EF (QEMU virtual NIC) Nmap done: 256 IP addresses (3 hosts up) scanned in 2.31 seconds
03TCP Scans and the Four Port States
The SYN scan, -sS, is the default when Nmap runs with enough privilege. It sends a SYN, waits for SYN-ACK, and then sends RST instead of completing the connection. Because the handshake never finishes, many applications do not log the attempt. This is often called a half-open scan. It is fast and relatively quiet at the application layer, but it still creates packets that a firewall or network sensor can see.
The connect scan, -sT, asks the operating system to complete a normal TCP connection. It works without raw-socket privileges, which makes it useful on a restricted workstation, but it is slower and more visible because the service accepts and then closes a real session. If you cannot run as root and you need a scan, -sT is the honest choice; do not pretend the difference does not exist.
Port selection is part of the experiment. -p 22,80,443 scans a list, -p 1-1024 scans a range, -p- scans all 65535 TCP ports, -F scans the 100 most common, and --top-ports 1000 uses Nmap's frequency data. Scanning every port takes longer and creates more noise; start with the services you expect, then widen only when the question requires it. Always record the exact port specification with the result.
# Half-open SYN scan of selected ports.sudo nmap -sS -p 22,80,443,3306,8080 10.10.10.30# Unprivileged connect scan, useful on a restricted workstation.nmap -sT -p 22,80,443 10.10.10.30# All TCP ports, saved in three formats.sudo nmap -sS -p- -oA scans/all-tcp 10.10.10.30PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 443/tcp closed https 3306/tcp filtered mysql 8080/tcp open http-proxy
04UDP, Service Versions, and Operating System Guesses
UDP scanning, -sU, is slower and less definitive than TCP scanning because UDP has no handshake. Nmap sends a payload that the service may or may not answer. An ICMP port-unreachable message means the port is closed. A valid response means it is open. Silence is reported as open|filtered because the tool cannot distinguish a service that ignores the probe from a firewall that dropped it. Target specific ports such as 53, 67, 123, 161, and 500 rather than scanning the whole UDP range.
Version detection, -sV, sends application-specific probes and compares the responses with a signature database. It can identify an SSH banner, an HTTP server, a TLS certificate subject, or a database greeting. The result is a best guess, not a vulnerability verdict. Probes can be logged, can be slow, and can disturb fragile services. The --version-intensity option ranges from 0 to 9; the default is a reasonable balance, and higher values send more probes.
Operating system detection, -O, compares low-level TCP/IP behaviours such as initial sequence number generation, TCP options, and responses to malformed packets. It needs at least one open and one closed port to work well, usually needs root, and can be wrong on virtual machines, NAT devices, and hardened stacks. --osscan-guess makes Nmap offer less certain matches. Treat the OS line as a hypothesis to verify, never as a fact.
# Target a few common UDP services.sudo nmap -sU -p 53,123,161 10.10.10.30# Identify service versions on TCP.sudo nmap -sV --version-intensity 5 -p 22,80 10.10.10.30# Guess the operating system and show the reasoning.sudo nmap -O --osscan-guess 10.10.10.30PORT STATE SERVICE 53/udp open domain 123/udp open|filtered ntp 161/udp closed snmp PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 9.6p1 Ubuntu 3ubuntu13 (Ubuntu Linux; protocol 2.0) 80/tcp open http nginx 1.24.0 (Ubuntu) OS details: Linux 5.0 - 6.9 Network Distance: 1 hop
05Scripts, Timing, and Reproducible Output
The Nmap Scripting Engine runs Lua scripts from categories such as safe, default, discovery, version, auth, brute, intrusive, and vuln. The -sC option runs the default set, which is intended to be useful without being destructive. The -A option is an alias for aggressive detection: it enables version detection, OS detection, default scripts, and traceroute. -A is convenient in a lab and noisy on a monitored network, so use it deliberately.
Timing templates trade speed for reliability. -T0 and -T1 are extremely slow and stealthy, -T2 is polite, -T3 is the default, -T4 is common on a reliable local network, and -T5 is fast enough to lose packets and produce false filtered results. --min-rate and --max-rate set packet rates directly. Faster is not better when the answer becomes wrong; a scan that reports every port filtered because it overwhelmed the target is not evidence.
Output formats matter for evidence. -oN writes the normal human-readable report, -oX writes XML for tools, -oG writes the older grepable format, and -oA writes all three plus a .nmap file. Use --open to reduce noise only after you have captured the full result; filtering the output before saving can hide the filtered ports that explain a failure. Record the Nmap version, command line, start time, and source address alongside the file.
# Full TCP sweep with version detection and all output formats.sudo nmap -sS -sV -p- --min-rate 500 -T4 -oA scans/tcp-full 10.10.10.30# Default scripts and versions on a short port list.sudo nmap -sC -sV -p 22,80,443 -oN scans/target.txt 10.10.10.30# Two safe scripts with readable output.sudo nmap --script http-title,smb-os-discovery -p 80,445 10.10.10.30Nmap scan report for 10.10.10.30 Host is up (0.00051s latency). Not shown: 65531 closed tcp ports (reset) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 9.6p1 Ubuntu 80/tcp open http nginx 1.24.0 |_http-title: Example Lab 445/tcp open netbios-ssn Samba smbd 4.6.2 | smb-os-discovery: | OS: Windows 6.1 (Samba 4.6.2) |_ Computer name: LAB-FILE Nmap done: 1 IP address (1 host up) scanned in 18.42 seconds
06Firewalls, IDS, and Honest Interpretation
A filtered result is the most misunderstood line in an Nmap report. It means Nmap did not receive a response that lets it decide whether the port is open. A firewall may have dropped the packet silently, rejected it with an ICMP administrative-prohibited message, or an intrusion prevention system may have blocked it. The port might be open, closed, or nonexistent. The report is telling you about the path, not only the host.
Rate limiting produces inconsistent results. A device that allows a few connections per second may answer the first probes and drop the rest, so a scan can show a random subset of ports as open. A target that responds slowly may be reported as filtered at high timing templates. Scan the same port twice with different timing, and compare the result before you conclude that a service is absent.
Intrusion detection systems watch for the shape of scanning: many SYNs from one source, sequential destination ports, version probes with distinctive payloads, and NSE script traffic. Some environments block the source automatically, some tarpit it, and some only alert. If your authorised test triggers a block, that is a finding about detection and response, not a failure of the test. Report it, stop if the rules of engagement require it, and do not attempt to evade controls without explicit permission.
open SYN-ACK received; a service accepted the connectionclosed RST received; host is reachable, no listener on that portfiltered no reply, or ICMP unreachable/prohibited; a filter is in the pathunfiltered reachable, but open/closed cannot be determined (ACK scan)open|filtered no reply is ambiguous (common with UDP and some scan types)INTERPRETATION CHECKLIST1. What exact command and timing template produced this result?2. Which state came from a reply, and which came from silence?3. Did the scan run from inside or outside the firewall?4. Does a second method agree (manual connection, host logs, packet capture)?5. What evidence would change the conclusion?07Common NSE Scripts and the vuln Caveat
A few NSE scripts are genuinely useful in routine lab work. http-title fetches a page and prints its title, which quickly confirms whether a web service is alive. http-headers shows response headers that may reveal server software or missing security controls. ssl-cert prints certificate subject, issuer, and validity dates. smb-os-discovery reports a Windows or Samba hostname, domain, and operating system. These are information-gathering scripts, not exploit tools, and they still belong only on systems you are authorised to test.
The vuln category is different. A vulnerability script checks for a specific known condition, such as a particular service version or a misconfiguration. It does not prove exploitability, and it can produce both false positives and false negatives. Some scripts are intrusive, slow, or capable of crashing a fragile service. Running --script vuln against a production system without approval is reckless. Read the script documentation first with --script-help, and verify any finding against the vendor advisory and the actual configuration.
Treat every script result as a lead. A certificate that expires soon is a real operational fact; a version banner that matches a vulnerable release is a reason to check the patch level, not proof of compromise. Write the command, the script version, the output, and the uncertainty into your report. Good scanning produces questions that can be verified, not a list of scary words.
# Page title and HTTP headers on a lab web server.sudo nmap --script http-title,http-headers -p 80,443 10.10.10.30# Certificate details.sudo nmap --script ssl-cert -p 443 10.10.10.30# SMB host and domain information.sudo nmap --script smb-os-discovery -p 445 10.10.10.30# Read what a script does before running it.sudo nmap --script-help http-titlePORT STATE SERVICE 443/tcp open https | ssl-cert: Subject: commonName=lab.example.test | Issuer: commonName=Lab CA | Public Key type: rsa | Public Key bits: 2048 | Not valid before: 2026-01-01T00:00:00 |_Not valid after: 2027-01-01T00:00:00
The ideas worth keeping.
- Scan only systems you own or have written permission to test, with scope and stop conditions recorded.
- Open, closed, and filtered describe the replies Nmap received, not absolute truth about the host.
- SYN scans are fast and half-open; connect scans are unprivileged and more visible; UDP is inherently ambiguous.
- Save raw output and the exact command, and verify important findings with a second method.
Make it yours.
Type and test your code right here in the interactive workspace. Run your solution, check the output, and compare with the worked guide when ready.
Exercise 1: Interpret a mixed scan result
A SYN scan of 10.10.10.30 returns 22/tcp open ssh, 80/tcp open http, 443/tcp filtered https, 3306/tcp closed mysql, and 8080/tcp open http-proxy. The scan ran from 10.10.10.20 on the same subnet with -T4. Explain what each state means, what you can and cannot conclude, and two follow-up checks.
Explore a worked solution
22 and 80 are open: the host returned SYN-ACK, so a service accepted the connection. 443 is filtered: Nmap received no usable response, so a firewall, host filter, or IPS may be dropping the probe; the port could still be open. 3306 is closed: the host returned RST, so it is reachable but nothing is listening there. 8080 is open and may be a proxy or development server rather than a production service. You cannot conclude that 443 has no service, that the host is vulnerable, or that the open ports are the only ones without a full-range scan. Follow-ups: rescan 443 with -Pn and a slower timing template, verify with a packet capture on the target, inspect host firewall rules with ss and ufw or iptables, and confirm each open service with -sV or a manual protocol check.The state describes the observed response, not the absolute state of the host. Silence and rejection both look like filtering and need a second method.
Exercise 2: Write an authorised scan plan
You have a lab with kali-vm at 10.10.10.20 and target-vm at 10.10.10.30 on an isolated host-only network. Write a short scan plan that covers scope, commands, timing, output, verification, and stop conditions. Explain why each choice is appropriate.
Explore a worked solution
Scope: only 10.10.10.30 and the 10.10.10.0/24 lab subnet, with the host operating system and home network out of scope. Authorisation: a note in the lab charter signed by the lab owner. Commands: start with sudo nmap -sn 10.10.10.0/24, then sudo nmap -sS -sV -p 22,80,443,445,8080 -T3 -oA scans/target for a first pass, then widen to -p- only if the question requires it. Timing: -T3 or -T4 on the isolated LAN, never -T5 for evidence. Output: -oA so normal, XML, and grepable files are preserved, with the command line and UTC start time in a notes file. Verification: confirm open ports with -sV and a manual connection, check the target's ss output and firewall rules, and capture packets on the target to see the scan arrive. Stop conditions: any probe leaving the lab subnet, target instability, or a finding that requires a change in scope. Clean up by stopping captures and reverting the snapshot if needed.A scan plan is evidence about intent and control. It makes the work reproducible and keeps the technical choices tied to authorisation.
What stayed with you?
Check the ideas while they’re fresh. Your answers stay in this page and feedback appears as you go.
Keep exploring.
The official references behind this lesson, when you want a second angle or the full details.
One lesson closer.
Reading is a start. Trying it yourself makes the connection.