Network Scanning and Enumeration With Nmap in Your Own Lab
Nmap (Network Mapper) is the most widely used tool for discovering hosts and services on a network. Administrators use it to inventory systems, penetration testers use it to map attack surfaces, and defenders use it to verify that firewalls do what they should. This lesson teaches you to use Nmap properly and interpret its output, only inside your own isolated lab, and ends with the defender’s view of what scanning reveals.
Important: scanning networks you do not own or are not authorised to test can be illegal and can trigger security alerts or even disrupt fragile devices. Use your lab’s host-only network (for example 192.168.56.0/24), as set up in How to Build a Safe Cyber Security Home Lab.
What a Port Scan Tells You
Every network service listens on a port; scanning discovers which ports respond. Nmap classifies ports as:
| State | Meaning |
|---|---|
| open | A service is actively accepting connections |
| closed | The host responded, but nothing is listening |
| filtered | No clear answer; a firewall or filter is probably dropping or blocking probes |
| open|filtered / closed|filtered | Nmap cannot tell which state applies |
For TCP, the classic technique is the SYN scan (-sS, requires administrator privileges): Nmap sends a SYN packet and interprets the reply (SYN-ACK means open; RST means closed; silence suggests filtered), without completing the handshake. The TCP connect scan (-sT) completes the handshake and needs no special privileges but is more visible in logs. UDP scanning (-sU) is slower because UDP services often do not reply.
Step-by-Step Lab
Assume your analyst VM is 192.168.56.101 and your target VM is 192.168.56.102.
Step 1: Host discovery
nmap -sn 192.168.56.0/24
-sn performs host discovery without scanning ports. On a local network it uses ARP, which is reliable. Result: a list of live hosts. Compare it with the VMs you know exist.
Step 2: Basic port scan
nmap 192.168.56.102
Scans the 1,000 most common TCP ports. Example output (illustrative):
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
3306/tcp open mysql
Ask for each open port: should this be reachable from here? A database port open to the whole network is a finding.
Step 3: Scan all ports
nmap -p- 192.168.56.102
Checks all 65,535 TCP ports and finds services on unusual ports that the default scan misses. It takes longer; add -T4 for a faster timing profile on a reliable lab network.
Step 4: Service and version detection
nmap -sV -p 22,80,3306 192.168.56.102
Nmap probes services to identify the software and version, such as OpenSSH 7.x or Apache httpd 2.4.x. Versions let you look up known vulnerabilities (see Vulnerability Management). Old versions are a defender’s to-do list.
Step 5: Operating system detection
sudo nmap -O 192.168.56.102
Estimates the operating system from network behaviour. It is a guess with a confidence level, not a certainty.
Step 6: Default scripts and safe NSE scripts
The Nmap Scripting Engine (NSE) adds checks written in Lua. Scripts are categorised (default, safe, discovery, vuln, intrusive and so on). In your own lab you can run the default set and a few informational scripts:
nmap -sC -sV 192.168.56.102 # default scripts plus version detection
nmap --script http-title,http-headers -p 80 192.168.56.102
nmap --script ssl-enum-ciphers -p 443 192.168.56.102 # list TLS ciphers a server accepts
Scripts in the intrusive or dos categories can crash services, so avoid them even in a lab unless you are specifically learning and have snapshots ready. Use nmap --script-help <script> to read what a script does before running it.
Step 7: Save your results
nmap -sV -oA lab-scan 192.168.56.102
# creates lab-scan.nmap (readable), lab-scan.xml (for tools) and lab-scan.gnmap (greppable)
Always save output. Evidence and repeatability are professional habits, and saved scans let you compare before and after hardening.
Useful Options at a Glance
| Option | Purpose |
|---|---|
-sn | Host discovery only |
-Pn | Skip discovery, treat host as up (useful when ping is blocked) |
-p 22,80,443 / -p- | Choose ports / scan all ports |
--top-ports 100 | Scan the most common 100 ports |
-sS / -sT / -sU | SYN scan / connect scan / UDP scan |
-sV | Service version detection |
-O | OS detection |
-sC | Default scripts |
-T0 to -T5 | Timing templates (slow to aggressive) |
-oN / -oX / -oA | Output in normal, XML or all formats |
--reason | Show why Nmap decided a port’s state |
-v | More verbose output |
Enumeration: Going Beyond Ports
Enumeration means collecting more detailed information about discovered services: for example the web server’s title and headers, the names of shared folders offered by a file server, the supported TLS versions, or the SSH key types. Each answer helps an assessor decide where to look next and helps a defender understand what is unintentionally exposed. For your own lab targets, practise with curl, a browser and the NSE informational scripts:
curl -I http://192.168.56.102/
nmap --script ssh2-enum-algos -p 22 192.168.56.102
nmap --script smb-protocols -p 445 192.168.56.102 # only if the target runs SMB
The Defender’s View
Run a scan from the analyst VM, then look at the target’s logs and firewall:
- On the target, check the authentication, web server and firewall logs. Can you see your scan? Which entries stand out?
- Enable a host firewall on the target, rerun the scan and compare. What changed from open to filtered?
- Stop one unneeded service (for example a test database), rerun, and confirm the port closes.
- Install a simple intrusion detection system such as Snort or Suricata on the lab monitoring machine and see which alerts a scan triggers; see Firewalls, IDS/IPS and Segmentation.
Compare scans before and after hardening. This is how real teams prove that a change reduced the attack surface.
Reading Results Like a Professional
- List every open port with its service and version.
- Mark each as expected, unexpected or unsafe (cleartext protocols such as Telnet or FTP; management interfaces; databases).
- Identify outdated versions to research for known vulnerabilities.
- Note anything that looks inconsistent, like a web server on an odd port.
- Record everything in a table with evidence file names.
Practice Exercises
- Perform host discovery on your lab network and confirm that every live host is one you created.
- Scan a lab target with the default scan and with
-p-. Did the full scan find anything the default missed? - Run
-sVagainst two services, record their versions, and search the vendor’s security advisories for those versions. - Harden the target (enable a firewall, remove an unnecessary service), rescan and write a one-paragraph before-and-after summary.
- Explain the difference between closed and filtered and what each suggests about the target’s firewall.
Mentor tip: Beginners memorise flags. Professionals know what each packet looks like. Capture your own scan in Wireshark once to see the SYN, SYN-ACK and RST packets and it will make the output permanently clearer.
Educational use only: scan only systems you own or are explicitly authorised in writing to test. Unauthorised scanning may be illegal and may disrupt services.
- Nmap discovers hosts, open ports, service versions and basic OS details.
- Port states: open, closed and filtered; filtered usually means a firewall is involved.
- Use
-sn, default scans,-p-,-sV,-sCand-oAin the right order, and read script help before running scripts. - Compare results before and after hardening to prove improvement.
- Scan only systems you own or are authorised to test.