Nmap Scanning Basics
Nmap (Network Mapper) is the go-to tool for discovering hosts, probing open ports, and gathering service/version and OS information. Itβs simple to start with and deep enough to support advanced reconnaissance, a must-have in any security toolkit.
This guide teaches the most useful Nmap scan types, practical command examples, how to interpret results, and responsible scanning etiquette.
Why Use Nmap?β
Nmap helps you discover:
- Which hosts are alive on a network (host discovery)
- Which ports are open and what services run on them
- Software versions and possible vulnerabilities (via scripts)
- The operating system of a host (OS fingerprinting)
Think of Nmap as the first step a security professional takes to map the attack surface.
Installing Nmapβ
-
Linux (Debian/Ubuntu):
sudo apt update
sudo apt install nmap -y -
macOS (Homebrew):
brew install nmap -
Windows: Download the installer from the official Nmap site and follow the wizard (it installs Npcap as well).
Basic Scan Types & When to Use Themβ
1. Ping Scan β Find live hostsβ
Quickly check which IPs are up (no port scan):
nmap -sn 192.168.1.0/24
Use when you want a list of responsive hosts on a subnet.
2. TCP Connect Scan (-sT) β Reliable, works without privilegesβ
Performs a full TCP handshake for each port. Good when you donβt have raw-socket privileges:
nmap -sT 10.0.0.5
Slower and noisier than SYN scan, but universally supported.
3. SYN Scan (-sS) β Fast and stealthier (requires root on UNIX)β
Sends SYN and analyzes responses without completing the handshake:
sudo nmap -sS 10.0.0.5
Common default for stealthy discovery β often used in pentesting labs.
4. Version Detection (-sV) β Identify services & versionsβ
Probes open ports to determine which service and version is running:
sudo nmap -sV 10.0.0.5
Useful to prioritize vulnerabilities (older versions are more likely vulnerable).
5. OS Fingerprinting (-O) β Guess the operating systemβ
Attempts to identify OS from network responses:
sudo nmap -O 10.0.0.5
Accuracy varies; combine with other data for confidence.
6. Aggressive Scan (-A) β Combined info (use carefully)β
Shortcut to run scans for service/version detection, OS detection, script scanning, and traceroute:
sudo nmap -A 10.0.0.5
Great for lab environments β noisy on production networks.
Useful Options & Flagsβ
| Option | Purpose |
|---|---|
-p | Specify port or range β e.g. -p 22,80,443 or -p 1-65535 |
--top-ports N | Scan top N most common ports (faster) |
-T0..-T5 | Timing template (0 slowest, 5 fastest / loudest) |
-Pn | Skip host discovery (treat hosts as up) |
-oN / -oX / -oG | Output formats: normal, XML, grepable |
--open | Show only open ports in output |
-v / -vv | Verbose output (more details) |
--script <name> | Run Nmap Scripting Engine (NSE) scripts (e.g., --script http-headers) |
--script vuln | Run vulnerability-related NSE scripts |
Examples:
# Scan top 100 ports, show only open, faster timing:
sudo nmap --top-ports 100 --open -T4 10.0.0.5
# Full port range with version detection and scripts:
sudo nmap -p 1-65535 -sV --script vuln 10.0.0.5
Nmap Scripting Engine (NSE)β
NSE adds powerful scripted checks β from simple info-gathering to complex vulnerability detection. Run specific script categories:
--script defaultβ safe default scripts--script vulnβ vulnerability scanning scripts--script discoveryβ extra discovery helpers
Example:
sudo nmap -sV --script vuln 192.168.1.10
Some NSE scripts can be intrusive. Use with permission.
Timing & Stealthβ
Timing controls (-T0 to -T5) let you balance speed vs detectability:
-T0/-T1β very slow; useful to avoid IDS triggers-T3β default, balanced-T4/-T5β fast but noisy; avoid on production
Use -sS (SYN) + -T1 for stealth; use -sT + -T4 for quick scans where stealth isnβt required.
Output & Reportingβ
Save scans for later:
# Normal text
nmap -sV 10.0.0.5 -oN result.txt
# XML (useful for automation)
nmap -sV 10.0.0.5 -oX result.xml
# Grepable output
nmap -sV 10.0.0.5 -oG result.gnmap
Combine outputs to feed other tools or reports.
Practical Examples & Workflowsβ
Quick host discovery + top ports:β
nmap -sn 192.168.1.0/24
nmap --top-ports 50 --open 192.168.1.23
Web server fingerprint + common scripts:β
sudo nmap -p 80,443 -sV --script http-headers,http-title 203.0.113.5
Full reconnaissance (lab use only):β
sudo nmap -A -p 1-65535 203.0.113.5 -oN full_recon.txt
Targeted service check (SSH):β
nmap -p 22 --script sshv1,ssh-hostkey 10.0.0.5
Interpreting Results β Quick Guideβ
- open β a service responded (attack surface)
- closed β port reachable but no service listening
- filtered β packets were blocked (firewall/ACL)
- unfiltered β port reachable but Nmap cannot determine open/closed (less common)
- open|filtered β Nmap cannot distinguish (common for UDP)
- closed|filtered β similar ambiguity in UDP/TCP scans
If a port is open and the service version is old, prioritize it for further testing (with permission).
Legal & Ethical Scanningβ
Nmap is powerful and scanning other people's networks without permission can be illegal.
- Scan only systems you own or have written permission for (e.g., lab, client with scope).
- Respect time windows and scope limits in engagement contracts.
- Do not run aggressive scans against unknown live infrastructure.
Always get explicit permission and document your scope.
Hands-On Lab Ideasβ
-
Local Subnet Discovery:
nmap -sn 192.168.1.0/24β identify all live hosts on your home LAN. -
Service Identification: Host a small web app on a VM and run:
sudo nmap -sV -p 80,443 <vm-ip>β inspect server banners. -
NSE Practice: Run safe discovery scripts:
sudo nmap --script discovery 192.168.56.0/24on an isolated lab. -
Timing & IDS: Compare
-T1vs-T4scans against a test host and observe logs on a local IDS (like Snort) to see how scan speed affects detection.
Best Practices Summaryβ
- Start with non-intrusive scans (
-sn,--top-ports) to map targets. - Use version detection (
-sV) to prioritize further testing. - Run NSE scripts carefully; know which are intrusive.
- Adjust timing (
-T) to avoid tripping alarms in production. - Save outputs (
-oN,-oX) for reporting and auditing. - Always gain permission before scanning networks you donβt own.