A practical walkthrough for asking better questions about a network you are allowed to test
Nmap is easiest to learn when you treat it as a set of questions. Is the host alive? Which ports answer? What service is behind each port? Does the output give you enough evidence to investigate further? This page follows that order so the commands feel connected instead of random.
Use these examples only on systems you own, administer, or have written permission to test. A home lab, a VM network, TryHackMe, Hack The Box, or scanme.nmap.org is the right place to practice.
Use the Nmap Field Cheat Sheet when you want the short action page: one skeleton command and five master scan workflows.
Nmap is a network question tool. You give it a target, and it helps you learn what is reachable, which ports respond, and what services might be running there. It does not automatically prove "this system is hacked" or "this server is safe." It gives you evidence so you can decide what to check next.
In real work, that evidence is useful everywhere: a SOC analyst might review a suspicious internal host, a sysadmin might confirm which services are exposed after a change, and a learner might map a small home lab to understand how networking actually looks from the terminal.
Different people use Nmap for different reasons, but the workflow is similar: start broad, narrow down, then verify. This is the part beginners usually miss. Nmap is not the whole investigation. It is the first clean map before you decide where to spend attention.
A port is a numbered place where a service can listen for network traffic. Think of the IP address as the building, and ports as the doors for different services. SSH often listens on port 22, web traffic often uses 80 or 443, and DNS often uses 53.
Why does this matter? Because an open port tells you where a system is willing to talk. It does not prove a vulnerability by itself, but it tells you where to look next.
When Nmap scans a port, it reports a state. Read the state before jumping to conclusions. In real work, filtered often means "a firewall or network device is affecting the answer," not "nothing exists there."
| State | Meaning |
|---|---|
| open | Application actively accepting connections |
| closed | Port accessible but no application listening |
| filtered | Firewall/filter blocking; Nmap can't determine state |
| unfiltered | Port accessible but open/closed undetermined |
| open|filtered | Can't determine if open or filtered |
| closed|filtered | Can't determine if closed or filtered |
nmap 192.168.56.10
Look for the PORT, STATE, and SERVICE columns. If you see 22/tcp open ssh, the useful takeaway is simple: this host is reachable and SSH is accepting connections. The next step is not guessing passwords. The next step is confirming whether SSH should be exposed there.
Install Nmap from a trusted package source and verify that the command works before you start scanning. This sounds boring, but it saves time later. A broken install or an old version can make you chase scan behavior that is really just a local setup problem.
In a lab, install it on the machine you will scan from. That could be Kali, Ubuntu, Windows with Nmap installed, or any admin workstation you control.
# Update and install
sudo apt update
sudo apt install nmap
# Verify installation
nmap --version
sudo dnf install nmap # Fedora
sudo yum install nmap # CentOS/RHEL
# Using Homebrew
brew install nmap
Download the installer from nmap.org or use:
# Using Chocolatey
choco install nmap
# Using winget
winget install nmap
Run nmap --version. You should see the Nmap version and compiled features. If the command is not found, fix your PATH or installation before moving on.
Zenmap exists as a graphical interface, but learn the CLI first. Commands are easier to save in notes, repeat during labs, and paste into a report.
The basic shape is simple: choose scan options, then give Nmap a target. The target might be one IP, a hostname, a subnet, or a file of hosts. The skill is not memorizing every flag. The skill is knowing what question you are asking before you run the command.
nmap [Scan Type] [Options] {target specification}
Targets tell Nmap where to send probes. In a home lab, this might be your test VM. In a company environment, this should be a written scope from your team. Never guess the scope.
| Format | Example | Description |
|---|---|---|
| Single IP | nmap 192.168.1.1 |
Scan one host |
| Multiple IPs | nmap 192.168.1.1 192.168.1.5 |
Scan specific hosts |
| Range | nmap 192.168.1.1-100 |
Scan IP range |
| CIDR | nmap 192.168.1.0/24 |
Scan entire subnet (256 hosts) |
| Hostname | nmap scanme.nmap.org |
Scan by hostname |
| From File | nmap -iL targets.txt |
Read targets from file |
| Exclude | nmap 192.168.1.0/24 --exclude 192.168.1.1 |
Exclude specific hosts |
Get written permission before scanning networks you do not own or administer. Unauthorized scanning can be illegal and can also look hostile to monitoring teams. Use scanme.nmap.org for public practice because it is specifically set up for Nmap testing.
Start small. A basic scan checks the most common TCP ports and gives you a first view of what the host exposes.
# Basic scan (scans 1000 most common ports)
nmap scanme.nmap.org
# Scan specific ports
nmap -p 22,80,443 scanme.nmap.org
# Scan port range
nmap -p 1-1000 scanme.nmap.org
# Scan all ports (takes longer)
nmap -p- scanme.nmap.org
# Fast scan (top 100 ports)
nmap -F scanme.nmap.org
Focus on open ports first. If you see 80/tcp open http, that means a web service answered. If you see 22/tcp open ssh, SSH answered. A beginner mistake is treating the service name as a guarantee. It is Nmap's best guess until you do version detection.
Before you care about ports, you need to know which hosts are alive from your point of view. Host discovery is the sweep step. It asks, "Which devices on this range respond at all?"
In real work, this is useful for inventory, lab mapping, and sanity checks. For example, if your home lab subnet is 192.168.56.0/24, discovery tells you which VMs are currently online before you run deeper scans.
Different networks answer different probe types. On a local subnet, ARP discovery is often reliable. Across routed networks, ICMP or TCP probes may work better. If a host is known to exist but blocks discovery probes, -Pn tells Nmap to skip the "are you alive?" step and scan anyway.
| Flag | Technique | Best For |
|---|---|---|
| -sn | Ping Scan (no port scan) | Quick network sweep |
| -Pn | Skip host discovery | Hosts that block ping |
| -PS | TCP SYN ping | Hosts that respond on common TCP ports |
| -PA | TCP ACK ping | Firewall behavior testing in labs |
| -PU | UDP ping | Hosts filtering TCP |
| -PE | ICMP Echo ping | Local networks |
| -PP | ICMP Timestamp ping | When echo blocked |
| -PM | ICMP Netmask ping | Alternative ICMP |
| -PR | ARP ping (local only) | Same subnet - most reliable |
Run discovery first when you are not sure what is online. The output should show hosts that are up. If nothing appears, do not immediately assume the network is empty. Check your subnet, VPN, interface, and permission scope.
# Find all live hosts on your network (no port scan)
nmap -sn 192.168.1.0/24
# Scan host even if it doesn't respond to ping
nmap -Pn 192.168.1.50
# Use TCP SYN ping on port 80 and 443
nmap -PS80,443 192.168.1.0/24
# Use ARP discovery (best for local network)
nmap -PR 192.168.1.0/24
# Combine multiple discovery methods
nmap -PE -PS22,80,443 -PA80 192.168.1.0/24
Task: You manage a small lab network and want a quick list of live devices on 10.0.0.0/24.
# Quick discovery scan
nmap -sn 10.0.0.0/24 -oG - | grep "Up" | awk '{print $2}'
# With hostnames
nmap -sn 10.0.0.0/24
Look for IPs marked as up. If a hostname appears, note it, but do not treat hostnames as proof of ownership or purpose. They are hints.
Once you know a host is reachable, the next question is: which ports are listening? Nmap can ask that question in different ways. Some scan types are quick and common, some need admin privileges, and some are mainly useful when you are testing firewall behavior in a lab.
For learning, start with the default scan or SYN scan. Do not jump into unusual scan types until you understand what open, closed, and filtered mean in the output.
TCP scans are the normal starting point because most familiar services use TCP: SSH, HTTP, HTTPS, SMB, databases, and many admin panels. In real work, this is where you build your first attack surface list or inventory list.
| Flag | Scan Type | How It Works | Typical Use |
|---|---|---|---|
| -sS | SYN Scan (Half-open) | Sends SYN, waits for SYN/ACK, sends RST | Common default when running with privileges |
| -sT | Connect Scan | Full TCP connection (3-way handshake) | Works without admin privileges |
| -sA | ACK Scan | Sends ACK to detect firewall rules | Firewall rule testing |
| -sW | Window Scan | Like ACK but examines window field | Specialized firewall testing |
| -sM | Maimon Scan | FIN/ACK probe | Rare edge cases |
These scans send unusual TCP flag combinations and then watch how the target responds. They are worth knowing because they teach you how TCP behavior affects scanning, but they are not reliable on every system.
| Flag | Scan Type | Flags Sent |
|---|---|---|
| -sN | NULL Scan | No flags set |
| -sF | FIN Scan | Only FIN flag |
| -sX | Xmas Scan | FIN + PSH + URG |
These scans often produce open|filtered results. That means Nmap cannot cleanly separate an open port from a filtered one. In real work, this is where you slow down and verify with another scan type before reporting anything confidently.
UDP is different because it does not have the same connection handshake as TCP. DNS, SNMP, DHCP, and some VPN services use UDP, so ignoring UDP can leave gaps in your understanding of a host.
UDP scans are slower and often need privileges. Start with a small port list instead of scanning every UDP port at once.
# UDP scan (slower because no handshake)
nmap -sU 192.168.1.1
# Scan specific UDP ports
nmap -sU -p 53,67,68,161,500 192.168.1.1
# Combined TCP and UDP
nmap -sS -sU -p T:22,80,443,U:53,161 192.168.1.1
Use these examples in a lab to compare how the output changes. The useful skill is not running every scan type. The useful skill is seeing when one scan gives you uncertainty and another scan gives you a clearer answer.
# Default SYN scan (requires root/admin)
sudo nmap -sS 192.168.1.1
# Connect scan (no root needed)
nmap -sT 192.168.1.1
# Xmas scan for firewall testing
sudo nmap -sX 192.168.1.1
# ACK scan to map firewall rules
sudo nmap -sA 192.168.1.1
Do not treat filtered as boring. A filtered port tells you something about network controls. It might be a firewall, host-based filtering, a security group, or a path issue between you and the target.
An open port only tells you that something answered. Version detection tries to learn what that "something" is. This is where Nmap becomes more useful for security work, because "port 80 is open" is vague, while "Apache httpd 2.4.18 is responding" gives you something concrete to verify.
In real work, service detection helps with patch review, asset inventory, suspicious host triage, and deciding which logs or owners to check next.
The -sV flag sends extra probes and reads the responses. Higher intensity can produce better detail, but it can also take longer and create more traffic. Start with the default version detection, then increase intensity only when the result is unclear.
| Flag | Purpose |
|---|---|
| -sV | Enable version detection |
| --version-intensity [0-9] | How hard to try (0=light, 9=all probes) |
| --version-light | Quick version scan (intensity 2) |
| --version-all | Try all probes (intensity 9) |
# Basic version detection
nmap -sV 192.168.1.1
# More detailed version detection
nmap -sV --version-all 192.168.1.1
# Combined with service scripts
nmap -sV -sC 192.168.1.1
Task: You found a lab web server and want to know which service versions are visible before checking vendor advisories.
# Detailed version scan on common ports
nmap -sV --version-all -p 21,22,80,443,3306,8080 webserver.local
# Output shows:
# PORT STATE SERVICE VERSION
# 22/tcp open ssh OpenSSH 7.2p2 Ubuntu
# 80/tcp open http Apache httpd 2.4.18
# 443/tcp open ssl/http Apache httpd 2.4.18
# 3306/tcp open mysql MySQL 5.5.62
Look for service names and versions. Then verify with vendor advisories, package manager data, or authenticated inventory. Banners can be wrong, customized, or hidden.
OS detection tries to guess the target operating system by looking at tiny differences in network responses. It is useful context, not a courtroom-level fact. A result like "Linux 4.x" can help you choose the right admin team or log source, but you should verify it before making decisions.
In a home lab, try this against a Linux VM and a Windows VM. Seeing the difference makes the feature easier to understand than reading the flag alone.
OS detection usually works best when Nmap can see at least one open port and one closed port. If every port is filtered, the fingerprint may be weak or missing.
| Flag | Purpose |
|---|---|
| -O | Enable OS detection |
| --osscan-limit | Skip OS detection for hosts without open+closed ports |
| --osscan-guess | Guess OS more aggressively |
| --max-os-tries | Max attempts (default 5) |
# Basic OS detection
sudo nmap -O 192.168.1.1
# More detailed OS guessing
sudo nmap -O --osscan-guess 192.168.1.1
# Combined with version detection (common combo)
sudo nmap -O -sV 192.168.1.1
The -A flag enables OS detection (-O), version detection (-sV), default scripts (-sC), and traceroute (--traceroute). Use it when you have permission for a broader inventory scan and you want one command that gathers several kinds of detail.
sudo nmap -A 192.168.1.1
What to look for: OS guesses, service versions, script output, and traceroute hops. Common beginner mistake: running -A everywhere just because it is convenient. Use it when the scope and network impact make sense.
NSE is Nmap's scripting layer. Think of it as a library of small checks that can ask more specific questions after you know which services exist. For example, a script can read an HTTP title, check TLS certificate details, list supported SMB information, or look for a known vulnerability pattern.
This is useful in real work because it turns a port list into a more readable set of clues. Still, scripts are not all equal. Some are safe information gathering. Others are intrusive and should stay in labs unless you have explicit written permission.
Categories help you choose scripts without memorizing every script name. Beginners should spend most of their time with default, safe, discovery, and focused service scripts. Save intrusive categories for controlled labs.
| Category | Description |
|---|---|
| auth | Authentication and credential testing |
| broadcast | Network broadcast discovery |
| brute | Password guessing checks, labs only unless explicitly authorized |
| default | Safe, useful scripts (-sC) |
| discovery | Service discovery |
| dos | Denial of Service checks (authorized labs only) |
| exploit | Active exploitation checks, labs only unless explicitly authorized |
| fuzzer | Fuzzing tests |
| intrusive | Risky scripts that might crash services |
| malware | Malware detection |
| safe | Won't crash services |
| version | Version detection enhancement |
| vuln | Vulnerability detection |
Start with one script or one safe category. If you run too many scripts at once, the output gets noisy and you will not learn which result came from which check.
# Run default scripts
nmap -sC 192.168.1.1
# Run specific script
nmap --script=http-title 192.168.1.1
# Run multiple scripts
nmap --script=http-title,http-headers 192.168.1.1
# Run category of scripts
nmap --script=vuln 192.168.1.1
# Run all safe scripts
nmap --script=safe 192.168.1.1
# Combine categories
nmap --script="vuln and safe" 192.168.1.1
# Exclude specific scripts
nmap --script="default and not intrusive" 192.168.1.1
These examples show the style of NSE usage. Read the script name out loud and ask what it is checking. http-security-headers checks web headers. ssh-auth-methods checks SSH authentication methods. That simple habit keeps the output connected to the goal.
# Check for vulnerabilities in an authorized lab
nmap --script vuln 192.168.1.1
# SSL/TLS vulnerability check
nmap --script ssl-heartbleed,ssl-poodle,ssl-ccs-injection -p 443 192.168.1.1
# SMB vulnerabilities (EternalBlue etc.)
nmap --script smb-vuln* -p 445 192.168.1.1
# HTTP security headers
nmap --script http-security-headers -p 80,443 192.168.1.1
# DNS zone transfer
nmap --script dns-zone-transfer -p 53 ns.target.com
# FTP anonymous login
nmap --script ftp-anon -p 21 192.168.1.1
# SSH auth methods
nmap --script ssh-auth-methods -p 22 192.168.1.1
Scripts in the intrusive, dos, exploit, and brute categories can crash services, trigger security alerts, or behave like an attack. In real work, this is where you slow down and verify scope before running anything.
Timing controls how fast Nmap sends probes and how patient it is while waiting for replies. Faster scans feel nice in a lab, but they can miss results on slow networks or create unnecessary noise. Slower scans take longer, but they are easier on fragile systems and monitored environments.
In real work, timing is not about being clever. It is about matching the scan to the network. A small home lab can handle faster scans. A production subnet, a VPN link, or old equipment deserves more patience.
The -T templates are shortcuts. -T3 is the default. -T4 is common on reliable internal networks. -T5 is usually too aggressive for serious work because speed can cost accuracy.
| Flag | Name | Use Case |
|---|---|---|
| -T0 | Slowest | Very slow, low-traffic testing |
| -T1 | Very slow | Slow testing on monitored networks |
| -T2 | Polite | Reduce bandwidth/load |
| -T3 | Normal | Default |
| -T4 | Fast | Fast scan on reliable network |
| -T5 | Very fast | Very fast, may miss ports |
Fine-tuned options are useful when you need more control than a template gives you. For example, --max-rate can stop a scan from sending probes too quickly, and --host-timeout prevents one stubborn host from holding up the whole run.
# Set max outstanding probes
nmap --min-parallelism 100 192.168.1.0/24
# Set timeout values
nmap --host-timeout 30m 192.168.1.0/24
# Set probe rate
nmap --min-rate 1000 192.168.1.0/24
nmap --max-rate 500 192.168.1.0/24
# Set scan delay for monitored networks
nmap --scan-delay 1s 192.168.1.1
If a fast scan finds fewer ports than a normal scan, trust the slower verified result. Beginners often assume faster means better. With scanning, faster just means faster.
If a scan matters, save it. Terminal output disappears, scrollback gets messy, and reports need evidence. Output files let you compare before and after changes, share results with a teammate, or parse the scan later with tools.
In real work, this is a habit that separates casual scanning from useful notes. Name files clearly so future you knows what was scanned and why.
Nmap can save human-readable text, XML for tools, grepable output for quick parsing, or all common formats at once. Most of the time, -oA is the clean choice because it writes several useful formats with one base name.
| Flag | Format | Best For |
|---|---|---|
| -oN file.txt | Normal | Human-readable |
| -oG file.gnmap | Grepable | grep/awk parsing |
| -oX file.xml | XML | Tool import (Metasploit, etc.) |
| -oS file.txt | Novelty | Novelty output, rarely useful |
| -oA basename | All formats | Creates .nmap, .gnmap, .xml |
# Save in all formats
nmap -sV -oA myscan 192.168.1.0/24
# Append to existing file
nmap --append-output -oN results.txt 192.168.1.1
# Verbose output to screen + file
nmap -v -sV -oN scan.txt 192.168.1.1
A useful filename might be 2026-06-20_home-lab_webserver_sV or internal-inventory_weekly_001. The goal is simple: when you open the folder later, the scan names should still make sense.
Firewalls change what Nmap can see. Sometimes a port is open, but a firewall blocks your probe. Sometimes the host is alive, but it does not answer ping. This section is about reading those clues, not trying random tricks until something works.
In real work, firewall testing should be scoped and documented. If you are checking a lab firewall, change one thing at a time and compare the output. That way you learn what the control is doing instead of creating confusing noise.
These options help you understand scan behavior and firewall responses. Use them in authorized labs, and write down what changed between each run.
| Flag | What It Helps You Learn |
|---|---|
| -Pn | Scan a known host even when discovery probes are blocked |
| --reason | Show why Nmap chose a port state |
| -sA | Check whether packets are filtered by firewall rules |
| --packet-trace | Show sent and received packets for learning and troubleshooting |
| --traceroute | Show the network path Nmap sees to the target |
| --max-retries [n] | Control how patient Nmap is with missing replies |
# Scan a known host even if ping-style discovery is blocked
nmap -Pn -p 22,80,443 192.168.56.10
# Ask Nmap to explain why it chose each state
nmap --reason -p 22,80,443 192.168.56.10
# Check firewall filtering behavior in a lab
sudo nmap -sA -p 22,80,443 192.168.56.10
# Show packets while learning or troubleshooting
sudo nmap --packet-trace -p 80 192.168.56.10
Pay attention to filtered, unfiltered, and the reason field. If -Pn finds ports after a discovery scan found nothing, the host may simply be blocking discovery probes. That is a useful finding, but it still needs context.
The best way to learn Nmap is to practice small workflows. Each scenario below starts with a simple question, uses a command that matches that question, and points out what to notice in the result.
Question: Which lab machines are online right now?
# Step 1: Find live hosts
nmap -sn 192.168.56.0/24 -oG lab-hosts.gnmap
# Step 2: Scan the common ports on hosts you own
nmap -iL live_hosts.txt -F -oA lab-quick-scan
# Step 3: Take a closer look at one interesting host
nmap -sV -sC -O -p 22,80,443 -oA lab-webserver 192.168.56.10
What to notice: Start with live hosts, then narrow down. Beginners often run a heavy scan first and then wonder why the output feels overwhelming.
Question: Which web ports are open, and what does the server reveal?
# Full web scan
nmap -sV -sC -p 80,443,8080,8443 \
--script http-enum,http-headers,http-methods,http-security-headers \
-oA web-review webserver.local
What to notice: Look for unexpected ports, missing security headers, unusual HTTP methods, and version banners that need verification.
Question: A host appeared in an alert. What network services are visible from your analyst workstation?
# Visible service review
nmap -sV -sC -p 22,80,135,139,445,3389 -oA suspicious-host 10.10.20.45
What to notice: RDP, SMB, SSH, and web admin panels are good places to verify ownership, patch state, and logs. Do not jump from "port open" to "host compromised" without evidence.
Question: What services are exposed across a small authorized subnet?
# Comprehensive network inventory
nmap -sV --top-ports 1000 -oA weekly-inventory 192.168.1.0/24
# Quickly list hosts with open ports from grepable output
grep "Ports:" weekly-inventory.gnmap
What to notice: Save the output so you can compare it next week. New services, missing services, and changed banners are usually more interesting than one scan by itself.
Use this section as a reminder, not as a replacement for understanding the output. Pick the flag that matches your question, run a small scan, read the result, then decide the next step.
nmap 192.168.1.1 # Single IP
nmap 192.168.1.0/24 # Subnet
nmap -iL targets.txt # From file
nmap 192.168.1.1-100 # Range
nmap -sn # Ping scan
nmap -Pn # Skip discovery
nmap -PS22 # TCP SYN ping
nmap -PR # ARP ping
nmap -sS # SYN scan
nmap -sT # Connect scan
nmap -sU # UDP scan
nmap -sA # ACK scan
nmap -p 22 # Single port
nmap -p 1-1000 # Range
nmap -p- # All ports
nmap -F # Fast (100)
nmap -sV # Version
nmap -O # OS detect
nmap -A # OS, version, scripts, route
nmap -sC # Scripts
nmap -T0 # Slowest
nmap -T3 # Normal
nmap -T4 # Fast
nmap -T5 # Very fast
nmap -oN file.txt # Normal
nmap -oX file.xml # XML
nmap -oG file.gnmap # Grepable
nmap -oA basename # All
nmap -Pn # Skip discovery
nmap --reason # Explain states
nmap -sA # Check filtering
nmap --packet-trace # Show packets
Use these as quick self-checks. The goal is not to memorize every command. The goal is to recognize which Nmap question you are asking.
How would you scan the top 100 ports on 192.168.1.50?
nmap -F 192.168.1.50
The -F flag performs a fast scan of the top 100 most common ports. Look for open ports first, then decide whether a deeper scan is needed.
You are scanning an authorized lab host and want to keep traffic low. What scan type and timing would you use?
sudo nmap -sS -T2 192.168.1.50
SYN scan (-sS) avoids completing the full TCP connection, and -T2 slows the scan down. In real work, verify that the slower timing still gives complete enough results.
You found a web server and want to: detect OS, find service versions, run default scripts, and save in all formats as "webserver_scan".
sudo nmap -A -oA webserver_scan target.com
Or more explicitly:
sudo nmap -O -sV -sC --traceroute -oA webserver_scan target.com
Look for service versions, script output, and OS guesses. Treat the result as evidence to verify, not a final report by itself.
You need to identify the service and version on ports 22, 80, and 443 for a host you manage. What command would you run?
nmap -sV -p 22,80,443 192.168.1.50
Check the SERVICE and VERSION columns. If the version looks old, verify it with the system owner or package data before reporting it.
Find all live hosts on 10.0.0.0/24 without port scanning, saving results to live_hosts.txt.
nmap -sn 10.0.0.0/24 -oG live_hosts.txt
-sn does discovery only, and -oG saves grepable output. If expected hosts are missing, check whether they block discovery probes.
A host is known to exist, but your discovery scan reports nothing. What command helps you scan it anyway and see why Nmap chooses each state?
nmap -Pn --reason -p 22,80,443 192.168.1.50
-Pn skips host discovery, and --reason explains the state decisions. This is useful when discovery probes are filtered.
Port 8080 is open. Get detailed version info with maximum intensity.
nmap -sV --version-all -p 8080 192.168.1.50
Or use --version-intensity 9 for the same effect. Look for the service name, product, and version, then verify anything important.
Check for SNMP (161) and DNS (53) UDP services on a network segment.
sudo nmap -sU -p 53,161 192.168.1.0/24
UDP scans require root/admin privileges and are slower than TCP scans. Keep the port list small when you are learning.