TL;DR — The 5 Nmap commands you'll use most

nmap -sn 192.168.1.0/24 # Host discovery (no port scan) nmap 192.168.1.10 # Default scan, top 1000 TCP ports sudo nmap -sV -sC -p- 192.168.1.10 # Full TCP scan + version + scripts sudo nmap -A 192.168.1.10 # Aggressive: OS, version, scripts, traceroute sudo nmap --script vuln 192.168.1.10 # Vulnerability scan via NSE

Each is explained in detail below. Skip to Scan Types if you want to dive in, or read on for the full walkthrough.

What is Nmap?

Nmap (Network Mapper) is the most widely used network reconnaissance tool in the world. Created in 1997 by Gordon Lyon (a.k.a. "Fyodor"), it's been continuously developed for nearly three decades and ships pre-installed on Kali Linux. Nmap discovers what hosts are alive on a network, what ports are open on those hosts, what services are running on those ports, and even what operating system each host is likely running.

Every penetration test, security audit, and CTF challenge starts with Nmap. The information it gives you determines what you do next — which exploits to try, which credentials to brute-force, which web apps to investigate. It's the first of the 10 essential Kali Linux tools every pentester learns.

⚠️ Legal disclaimer: Nmap is legal to install and run, but using it against systems you don't own or have explicit written authorization to scan is a crime under the Computer Fraud and Abuse Act (CFAA) and equivalent laws worldwide. Aggressive scans can also crash fragile systems. Always practice on your own lab, intentionally vulnerable VMs (Metasploitable, DVWA), or platforms like TryHackMe and HackTheBox.

Setting Up a Safe Practice Lab

Before running any nmap commands, you need a target you control. The simplest setup:

  1. Kali Linux VM — your attack box. See the install guide.
  2. Metasploitable 2 — intentionally vulnerable Linux VM with dozens of open services. Free download from Rapid7.
  3. Both VMs on the same host-only network in VirtualBox so they can talk to each other but not the internet.

Once both VMs are running, find your Metasploitable IP (login as msfadmin/msfadmin, then ifconfig). All the examples below assume you're scanning that VM at something like 192.168.56.102.

Installing and Updating Nmap

Nmap ships with Kali, but it's worth checking you're on a recent version. Nmap 7.95 is current as of 2026 with new NSE scripts and improved IPv6 support.

Terminal — Install & verify
# Install or update $ sudo apt update && sudo apt install nmap # Check the version $ nmap --version Nmap version 7.95 ( https://nmap.org ) # See available script categories $ ls /usr/share/nmap/scripts | head

If apt update throws a signing-key or repository error here, see how to fix broken Kali updates. New to the terminal in general? The beginner commands guide covers the basics every command below assumes. For every flag in exhaustive detail, the official Nmap reference guide is the authoritative source.

Nmap Basic Syntax

Every nmap command follows the same pattern:

Terminal — Syntax
$ nmap [scan-type] [options] [target] # Examples $ nmap 192.168.1.10 # Single host $ nmap 192.168.1.0/24 # Whole subnet $ nmap 192.168.1.1-50 # Range $ nmap 192.168.1.10 192.168.1.20 # Multiple specific hosts $ nmap example.com # Hostname (must resolve) $ nmap -iL targets.txt # Read targets from file
ℹ️ Root or sudo? Many of Nmap's most useful features (SYN scans, OS detection, raw packet manipulation) require root privileges. The general rule: if you want speed, stealth, or OS fingerprinting, run nmap with sudo. Without sudo, nmap falls back to slower TCP connect scans.

Host Discovery: What's Alive?

Before port scanning, you usually want to know which hosts on a network are even alive. This is called host discovery or ping scanning.

Terminal — Host discovery
# Ping scan only — no port scan (-sn = "skip port scan") $ sudo nmap -sn 192.168.1.0/24 # ARP scan — fastest method on local LAN $ sudo nmap -sn -PR 192.168.1.0/24 # If ICMP is blocked, try TCP SYN ping to common ports $ sudo nmap -sn -PS22,80,443 192.168.1.0/24 # UDP ping $ sudo nmap -sn -PU53,161 192.168.1.0/24 # List targets without sending any packets (passive) $ nmap -sL 192.168.1.0/24 # Disable host discovery, treat all as alive (use when ping is blocked) $ nmap -Pn 192.168.1.10
💡 Why -Pn matters: Many modern hosts and firewalls drop ICMP echo requests, making them appear "down" to nmap's default ping. If you know a host exists but nmap reports it as down, add -Pn to skip discovery and scan it anyway. This is essential when scanning external targets.

Port Scanning: What's Open?

Once you know hosts are alive, you scan their ports. Nmap supports several scan types, each with different tradeoffs between speed, stealth, and accuracy.

FlagScan TypeBest For
-sSTCP SYN (Stealth)Default for pentesting (requires root). Fast and relatively quiet.
-sTTCP ConnectWhen you don't have root. Completes the full TCP handshake.
-sUUDPFinding DNS, SNMP, NTP services. Very slow.
-sATCP ACKMapping firewall rules (filtered vs unfiltered).
-sN / -sF / -sXNULL / FIN / XmasEvading basic firewalls/IDS. Often unreliable on Windows targets.

The default scan

Terminal — Basic port scan
# Default: top 1000 TCP ports, SYN scan if root, connect scan otherwise $ sudo nmap 192.168.56.102 PORT STATE SERVICE 21/tcp open ftp 22/tcp open ssh 23/tcp open telnet 25/tcp open smtp 80/tcp open http 139/tcp open netbios-ssn 445/tcp open microsoft-ds 3306/tcp open mysql

Specifying ports

Terminal — Port specification
# Single port $ nmap -p 22 192.168.1.10 # Multiple specific ports $ nmap -p 22,80,443,3306 192.168.1.10 # Port range $ nmap -p 1-1000 192.168.1.10 # All 65535 TCP ports (slow but thorough) $ nmap -p- 192.168.1.10 # Top N ports by frequency $ nmap --top-ports 100 192.168.1.10 # Mix TCP and UDP ports in one scan $ sudo nmap -sS -sU -p T:22,80,443,U:53,161 192.168.1.10
⚠️ Don't skip -p-: A common beginner mistake is only scanning the default 1000 ports and missing services running on non-standard ports (think SSH on port 2222, web admin on 8080, custom apps on 5000+). On any real engagement, do a full -p- scan to catch what's hiding.

UDP scanning (-sU)

Everything so far scans TCP ports, but plenty of important services run over UDP — DNS (53), SNMP (161), DHCP (67), NTP (123), and more. TCP scans miss them completely. The catch is that UDP scanning is slow: UDP is connectionless, so an open port often just stays silent, and nmap has to wait and retry before deciding. A full UDP port scan can take hours or even days, which is why you almost always limit it to the common ports.

Terminal — UDP scanning
# Scan the most common UDP ports (the practical default) $ sudo nmap -sU --top-ports 100 192.168.56.102 # A single specific UDP port (e.g. SNMP) $ sudo nmap -sU -p 161 192.168.56.102 # Combine TCP and UDP in one command (T: = TCP, U: = UDP) $ sudo nmap -sS -sU -p T:22,80,443,U:53,161 192.168.56.102
ℹ️ Why UDP ports show as open|filtered: UDP scans frequently report this state instead of a clean open. It means nmap got no response and can't tell whether the port is open or simply firewalled — and it's completely normal for UDP. Confirm the interesting ones with a version scan (-sV), which sends a real protocol probe and forces a clearer answer.

Service & Version Detection

Knowing port 80 is open isn't very useful by itself. You need to know what's running on it. The -sV flag tells nmap to probe each open port and identify the service and version.

Terminal — Service detection
# Identify services and versions on open ports $ sudo nmap -sV 192.168.56.102 PORT STATE SERVICE VERSION 21/tcp open ftp vsftpd 2.3.4 22/tcp open ssh OpenSSH 4.7p1 Debian 8ubuntu1 80/tcp open http Apache httpd 2.2.8 ((Ubuntu) DAV/2) 3306/tcp open mysql MySQL 5.0.51a-3ubuntu5 # More aggressive version detection (slower, more accurate) $ sudo nmap -sV --version-intensity 9 192.168.56.102 # Light version detection (faster but less accurate) $ sudo nmap -sV --version-light 192.168.56.102

Service version output is gold for pentesters. vsftpd 2.3.4 in the output above is the famous backdoored version with a known exploit in Metasploit. OpenSSH 4.7 is ancient and has multiple known vulnerabilities.

OS Detection

The -O flag tells nmap to fingerprint the target's operating system based on subtle quirks in how it responds to crafted packets. It needs root and at least one open and one closed port to work reliably.

Terminal — OS fingerprinting
# OS detection (requires root) $ sudo nmap -O 192.168.56.102 Running: Linux 2.6.X OS CPE: cpe:/o:linux:linux_kernel:2.6 OS details: Linux 2.6.9 - 2.6.33

The Aggressive Scan: Everything at Once

Most of the time, you want everything: OS, version, default scripts, and traceroute. The -A flag combines them all.

Terminal — Aggressive scan
# -A = OS detection + version detection + default scripts + traceroute $ sudo nmap -A 192.168.56.102 # Equivalent to: $ sudo nmap -O -sV -sC --traceroute 192.168.56.102
⚠️ Aggressive isn't subtle: The -A flag is loud. It triggers nearly every IDS/IPS signature, fills the target's logs, and can crash fragile services. Use it on lab targets and authorized engagements where stealth doesn't matter. For real-world testing where stealth matters, build the scan up gradually instead.

NSE: Nmap's Scripting Engine

The Nmap Scripting Engine (NSE) is what transforms nmap from "port scanner" into "lightweight vulnerability scanner." NSE ships with over 600 scripts written in Lua, organized into categories like safe, discovery, vuln, brute, exploit, and intrusive.

Common script usage

Terminal — NSE basics
# Run "default" scripts (the safe and discovery categories) $ sudo nmap -sC 192.168.56.102 # Run all vulnerability detection scripts $ sudo nmap --script vuln 192.168.56.102 # Run a specific script $ sudo nmap --script http-title -p 80 192.168.56.102 # Run multiple scripts $ sudo nmap --script "http-title,ssl-cert,smb-os-discovery" 192.168.56.102 # Run scripts by category combination $ sudo nmap --script "safe and discovery" 192.168.56.102 # Pass arguments to a script $ sudo nmap --script http-brute --script-args userdb=users.txt,passdb=pass.txt -p 80 192.168.56.102

NSE script categories

CategoryWhat It DoesRisk
safeWon't crash or overload the targetLow
discoveryService banners, info gatheringLow
defaultRun by -sC, common quick checksLow-Medium
versionRefines version detectionLow
vulnKnown vulnerability detection (CVEs)Medium
bruteBrute-force credentialsHigh
exploitActually exploits vulnerabilitiesVery High
intrusiveMay crash services or generate alertsHigh
dosCauses denial of serviceCritical — never on production

The most useful NSE scripts

Out of the 600+ available, here are the ones I actually use most often:

Terminal — Useful NSE scripts
# HTTP enumeration $ nmap --script http-enum,http-headers,http-methods -p 80,443 target # SSL/TLS configuration check $ nmap --script ssl-enum-ciphers,ssl-cert -p 443 target # SMB enumeration (Windows shares) $ nmap --script smb-os-discovery,smb-enum-shares,smb-enum-users -p 445 target # Check for EternalBlue (MS17-010) $ nmap --script smb-vuln-ms17-010 -p 445 target # Heartbleed $ nmap --script ssl-heartbleed -p 443 target # DNS zone transfer attempt $ nmap --script dns-zone-transfer -p 53 dns.target.com # MySQL info gathering (no auth required) $ nmap --script mysql-info -p 3306 target # Search all installed scripts $ ls /usr/share/nmap/scripts/ | grep -i smb
ℹ️ The vulners script: Install vulners.nse from GitHub for live CVE database matching. After running -sV, vulners will cross-reference detected service versions against published CVEs and tell you exactly which vulnerabilities apply. Combined with --script-args mincvss=7.0, it filters to high-severity issues only.

Timing & Performance

Nmap has six timing templates (-T0 through -T5) that control scan speed. Faster scans get noticed by IDS systems; slower scans take forever.

TemplateNameUse Case
-T0ParanoidIDS evasion. Wait 5+ minutes between probes. Hours per host.
-T1SneakyIDS evasion. Wait 15s between probes.
-T2PoliteReduces bandwidth use. Useful on fragile networks.
-T3NormalDefault. Reasonable speed.
-T4AggressiveFast and reliable on stable networks. Common for CTFs.
-T5InsaneMaximum speed, sacrifices accuracy. May miss results.
Terminal — Timing
# Aggressive timing for lab work $ sudo nmap -T4 -A 192.168.56.102 # Sneaky scan to evade detection $ sudo nmap -T1 -sS 192.168.1.10 # Fine-grained timing controls (more powerful than templates) $ sudo nmap --min-rate 1000 --max-retries 2 192.168.1.10

Saving and Reading Results

Nmap can save scan results in multiple formats simultaneously. The most useful is -oA ("output all"), which saves three files at once.

Terminal — Output formats
# Normal output (human-readable) $ nmap -oN scan.txt 192.168.56.102 # XML output (for tools like Metasploit) $ nmap -oX scan.xml 192.168.56.102 # Grepable output (great for grep/awk pipelines) $ nmap -oG scan.gnmap 192.168.56.102 # All three formats at once (most common) $ nmap -oA scan_results 192.168.56.102 # Creates scan_results.nmap, scan_results.xml, scan_results.gnmap # Quick grep for open ports across multiple hosts $ grep "open" scan_results.gnmap | awk '{print $2}'
💡 Workflow tip: Always save your scans with -oA. You'll thank yourself later when you need to import findings into Metasploit (it parses the XML), grep through results, or compare what's changed between scans with ndiff.

Firewall & IDS Evasion

If you're scanning targets behind firewalls, basic scans often get blocked. Nmap has several evasion options — most have legitimate uses in authorized testing where you're checking whether IDS/IPS catches your activity.

Terminal — Evasion techniques
# Fragment packets (-f sends 8-byte fragments) $ sudo nmap -f 192.168.1.10 # Decoy scan — make it look like the scan came from multiple IPs $ sudo nmap -D RND:10 192.168.1.10 # Specific decoys (mix real with fake) $ sudo nmap -D 10.0.0.1,10.0.0.2,ME,10.0.0.4 192.168.1.10 # Spoof source port (some firewalls allow port 53 outbound freely) $ sudo nmap --source-port 53 192.168.1.10 # Slow scan (timing template T1 = sneaky) $ sudo nmap -T1 -sS 192.168.1.10 # Random target order (not sequential) $ nmap --randomize-hosts 192.168.1.0/24 # MAC address spoofing $ sudo nmap --spoof-mac Cisco 192.168.1.10

A Real-World Workflow

How I use Nmap on a typical CTF or lab engagement. The pattern: start broad and fast, then narrow and deep.

Terminal — Typical workflow
# Step 1: Discover live hosts (fast, no port scan) $ sudo nmap -sn 192.168.56.0/24 -oN hosts.txt # Step 2: Quick top-1000 scan to identify interesting targets $ sudo nmap -T4 --top-ports 1000 -iL live-hosts.txt -oA quickscan # Step 3: Full TCP scan on the targets that look interesting $ sudo nmap -T4 -p- -oA fullscan 192.168.56.102 # Step 4: Targeted version + script scan on found ports $ sudo nmap -sV -sC -p 21,22,80,3306 -oA deepscan 192.168.56.102 # Step 5: Vulnerability scan on the most promising service $ sudo nmap --script vuln -p 21 -oA vulnscan 192.168.56.102 # Step 6: UDP scan (slow, save for last) $ sudo nmap -sU --top-ports 100 -oA udpscan 192.168.56.102

This workflow catches the most exploitable services first while still ensuring you don't miss anything. The full -p- scan in step 3 is critical — it catches services on non-standard ports that the top-1000 scan misses.

Lessons From The Field

Things I've learned from years of scanning:

  1. Always run -p- at some point. The top 1000 ports miss a surprising amount. SSH on 2222, web admin on 8443, custom apps on weird ports — they're all somewhere in 1-65535.
  2. UDP scans take forever. A full UDP scan can take literal days. Use --top-ports 100 for UDP unless you have a specific reason to scan more.
  3. Service version output is gold. "Apache 2.2.8 from 2008" tells you 99% of what you need to know about a target. Always run -sV on anything interesting.
  4. Save everything with -oA. You'll forget what you scanned. The XML output also feeds directly into Metasploit and other tools.
  5. Don't run vuln scripts blindly on production. Some are aggressive and can cause outages. Read the script description before running it.
  6. nmap is a starting point, not an ending point. A "Apache 2.2.8" doesn't tell you whether the actual app is vulnerable. Use nmap output to guide your manual investigation, not replace it.

The flip side of all this: everything nmap reveals about a target is exactly what an attacker sees on your boxes. If you run servers, my Linux server hardening guide is the defensive counterpart — it closes the doors a scan like this would otherwise find open.

When To Use Something Else

Nmap is the right tool 90% of the time, but a few situations call for alternatives:

Frequently Asked Questions

Is using Nmap legal?

Installing and running Nmap is legal everywhere. Using it against systems you don't own or have authorization to test is illegal in most jurisdictions — under the CFAA in the US, the Computer Misuse Act in the UK, and equivalent laws worldwide. Practice on your own VMs, intentionally vulnerable targets like Metasploitable, or authorized platforms like TryHackMe and HackTheBox.

Why does my scan say all ports are filtered?

"Filtered" means a firewall is dropping your packets without telling you whether the port is open or closed. Try: (1) adding -Pn to skip the host discovery ping (some firewalls drop ICMP), (2) using -sT instead of -sS if you don't have root, (3) trying different scan types like -sA to map firewall rules, or (4) slowing down the scan with -T2.

What's the difference between -sS and -sT?

-sS (SYN/stealth scan) sends a SYN packet, gets a SYN/ACK response, and then sends RST instead of completing the handshake — so the connection never fully establishes. It requires root. -sT (TCP connect) completes the full three-way handshake using the OS's connect() syscall — it works without root but is slower and more visible in logs. Use -sS when you can.

How long should a full -p- scan take?

On a fast LAN with -T4, a single host's -p- scan finishes in 2-5 minutes. Across a slow internet link or with -T3, expect 15-30 minutes. UDP -p- can take many hours — always limit UDP to --top-ports.

Should I use Nmap or Zenmap?

Zenmap is the official GUI for Nmap and ships with Kali. It has a nice topology view and pre-built scan profiles. But every command Zenmap runs is just nmap with flags — once you're comfortable with the CLI, you'll find it faster. I recommend learning CLI nmap first; Zenmap is fine if you prefer GUIs.

What's the safest NSE script category?

The safe category. Scripts in this category are guaranteed not to crash the target, brute-force credentials, or use bandwidth abusively. Run nmap --script "safe and discovery" for low-risk reconnaissance.

How do I know which Nmap version I have?

Run nmap --version. As of mid-2026, Nmap 7.95 is the current stable release with new NSE scripts and IPv6 improvements. Update on Kali with sudo apt update && sudo apt upgrade nmap.

Can Nmap scan IPv6 networks?

Yes — add -6 to any nmap command. Many flags work the same way: nmap -6 -sn fe80::/64 for ping scanning a local IPv6 subnet, nmap -6 -sV [target] for IPv6 service detection. Nmap 7.95 has notably improved IPv6 host discovery and OS detection.

How do I scan UDP ports with Nmap?

Use the -sU flag, almost always limited to the common ports with --top-ports because UDP scanning is slow: sudo nmap -sU --top-ports 100 [target]. UDP scans need root, and ports frequently show as open|filtered because UDP is connectionless and silent services give nmap no clear answer. Confirm the interesting ones with -sV, which sends a real protocol probe.

How do I feed Nmap results into Metasploit?

Save your scan as XML with -oX (or -oA, which includes XML), then run db_import scan_results.xml from the msfconsole prompt. Metasploit reads the hosts, ports, and service versions straight into its database, so you can search for matching exploits without retyping anything. This is exactly why saving every scan with -oA pays off.