1. What Nmap Does

Nmap discovers hosts, ports, and services on a network. It sends packets and analyzes responses.

Core concepts:

  • Host: Any device with an IP address

  • Port: A numbered door into a host (65,535 total)

  • Open port: A service is listening (potential entry point)

  • Closed port: Host is reachable but nothing is listening

  • Filtered port: Firewall is blocking the probe


2. Installation

Linux:

sudo apt install nmap

Windows/Mac: Download from nmap.org


3. The Five Commands You Must Know

Command 1: Find Live Hosts

nmap -sn 192.168.1.0/24

Ping sweep. Finds what's alive. Start here.

Command 2: Scan Common Ports

nmap 192.168.1.10

Default scan. Tests 1,000 most common ports.

Command 3: Scan All Ports

nmap -p- 192.168.1.10

Scans all 65,535 ports. Takes longer but finds everything.

Command 4: Identify Services

nmap -sV 192.168.1.10

Tells you what software is running on open ports.

Command 5: The Aggressive Scan

nmap -A 192.168.1.10

Enables OS detection, version detection, scripts, and traceroute. Maximum information.


4. Port States Explained

State

Meaning

Action

open

Service is accepting connections

Investigate immediately

closed

No service listening

Low risk, host confirmed alive

filtered

Firewall blocking probe

May be open but protected


5. Scan Types (The Important Ones)

Scan

Command

Use Case

TCP SYN (stealth)

-sS

Fast, less detectable. Default.

TCP connect

-sT

When you lack root privileges

UDP scan

-sU

Finds DNS, SNMP, DHCP services

ACK scan

-sA

Maps firewall rules


6. Timing Templates

Control speed vs. stealth:

Template

Command

Speed

Paranoid

-T0

Extremely slow. Evades IDS.

Sneaky

-T1

Slow. Reasonably stealthy.

Polite

-T2

Slows to reduce bandwidth

Normal

-T3

Default. Balanced.

Aggressive

-T4

Fast. Assumes good network.

Insane

-T5

Very fast. May miss ports.

Real-world: Use -T4 for internal, -T1 or -T2 for external stealth.


7. Output Formats

Save your results:


nmap -oN normal.txt 192.168.1.10
nmap -oX scan.xml 192.168.1.10
nmap -oG grepable.txt 192.168.1.10
nmap -oA engagement 192.168.1.10

-oA saves in all three formats.


8. Practical Workflow

Step 1: Discovery

nmap -sn 192.168.1.0/24 > live_hosts.txt

Step 2: Full port scan on live hosts

nmap -p- -iL live_hosts.txt -oA full_port_scan

Step 3: Deep dive on open ports

nmap -sV -sC -p <ports> <target> -oA service_scan

Step 4: Vulnerability checks

nmap --script vuln -p <ports> <target>

9. Quick Reference Card

Task

Command

Ping sweep

nmap -sn <target>

Quick scan (top ports)

nmap <target>

Full TCP scan

nmap -p- <target>

Service versions

nmap -sV <target>

OS detection

nmap -O <target>

Aggressive scan

nmap -A <target>

UDP scan

nmap -sU <target>

Save output

nmap -oA <filename> <target>

Scan from list

nmap -iL <file>

Evade firewall

nmap -f -D RND:10 <target>


What Nmap Actually Does

Nmap (Network Mapper) is a packet-crafting tool that discovers hosts and services on a network by sending probes and analyzing responses.

The capabilities that matter:

Capability

What It Tells You

Why It Matters

Host Discovery

Which IP addresses respond to probes

Separates live assets from dead space

Port Scanning

Which ports are open on each host

Maps your entire attack surface

Service Detection

What application and version is running

Enables vulnerability correlation

OS Fingerprinting

What operating system the host runs

Informs patching and compliance

The output that matters: A complete, accurate inventory of every reachable device and every listening service on your network.


Why Nmap Is Interesting

1. It Reveals the Truth

Network diagrams lie. Documentation lies. Memory lies. Nmap does not.

u can run scans and find:

  • Critical databases exposed to the internet despite firewall rules claiming otherwise.

  • Development servers still running years after projects ended.

  • Printers and IoT devices with default credentials connected to production networks.

  • Rogue wireless access points plugged into conference room switches.

Nmap replaces assumptions with data.

2. It Shows You What Attackers See

Before an adversary attempts exploitation, they perform reconnaissance. They run Nmap. They see exactly what your external scans reveal.

When you run an external Nmap scan against your own organization, you see your network through an attacker's eyes. You discover:

  • Services exposed that should not be.

  • Version information that reveals vulnerabilities.

  • Filtered ports that indicate firewall presence.

This perspective is invaluable. You cannot defend against what you do not understand.

3. It Validates Controls

Security controls are theoretical until tested.

A firewall rule that "blocks RDP" either blocks RDP or it does not. Nmap tells you which. A network segment that "isolates PCI systems" either isolates them or it does not. Nmap confirms.

Configuration validation is not a one-time exercise. Networks change. Rules drift. Nmap provides continuous verification.


The Only Scans You Need to Know

For asset discovery:
nmap -sn 192.168.1.0/24

This finds live hosts. Nothing more. Start here.

For attack surface enumeration:
nmap -sV 192.168.1.10

This finds open ports and identifies services. This is your primary security scan.

For complete visibility:
nmap -A 192.168.1.10

This enables OS detection, version detection, script scanning, and traceroute. Use this for deep assessment.

For external validation:
nmap -sS -Pn [external IP range]

This performs a SYN stealth scan from outside your perimeter. This is what attackers run.

Top 5 Nmap Commands for Penetration Testing


1. The Initial Recon Command

Find everything. Assume nothing.

sudo nmap -Pn -sS -p- -T4 --min-rate=1000 <target>

Why this is #1: Most pentests fail because testers miss assets. This command finds hosts that ignore pings, scans all 65,535 ports, and does it fast enough to be practical.

What it does:

  • -Pn: Skip host discovery. Treat every IP as alive.

  • -sS: SYN stealth scan. Fast and evasive.

  • -p-: All TCP ports. No assumptions.

  • -T4 --min-rate=1000: Speed. Completes in minutes, not hours.

When to use it: Start of every engagement. Map the entire attack surface before focusing on specific targets.


2. The Service Enumeration Command

Open ports are just numbers. Services are vulnerabilities waiting to be found.

nmap -sV -sC -O -p <ports> <target>

Why this matters: Knowing that port 80 is open tells you nothing. Knowing that Apache 2.4.49 is running tells you exactly which exploits to try.

What it does:

  • -sV: Version detection. Identifies software and version.

  • -sC: Default scripts. Runs safe enumeration scripts (SMB shares, FTP anonymous login, etc.).

  • -O: OS fingerprinting. Identifies the operating system.

Pro tip: Always run this against the ports discovered in Command 1. The combination of full port scan + deep service enumeration finds 90% of easy wins.


3. The Firewall/IDS Evasion Command

Defenses exist. This command works around them.


sudo nmap -f --mtu 16 -D RND:10 --scan-delay 1s -sS <target>

Why this is critical: Default scans are loud. Firewalls block them. IDS alerts on them. This command gets through.

What it does:

  • -f --mtu 16: Fragments packets into tiny pieces. Some firewalls cannot reassemble.

  • -D RND:10: Uses decoys. Your scan appears to come from 10 random IPs.

  • --scan-delay 1s: Slows down the scan. Defeats threshold-based detection.

When to use it: Against well-defended targets. When you need results without triggering incident response.


4. The Vulnerability Discovery Command


nmap --script vuln -p <ports> <target>

Why this is powerful: This command runs dozens of vulnerability detection scripts automatically. It checks for:

  • EternalBlue (MS17-010)

  • Shellshock

  • SMB vulnerabilities

  • Default credentials

  • And hundreds more

Real-world impact: I have found unpatched MS17-010 boxes with this command more times than I can count. It is not a replacement for a full vulnerability scanner, but it is faster and often more direct.

Pro tip: Run this after Command 2. Feed it the open ports you already found. Let Nmap do the heavy lifting.


5. The Web Server Deep Dive Command

Web applications are the most common entry point. This command maps them.

nmap --script http-enum,http-title,http-methods,http-webdav-scan -p 80,443,8080,8443 <target>

Why this matters: Web servers expose directories, methods, and configurations that should not be public. This command finds them.

What it does:

  • http-enum: Enumerates common web directories (admin, backup, phpmyadmin).

  • http-title: Grabs page titles. Quick way to identify what the site does.

  • http-methods: Checks for dangerous HTTP methods (PUT, DELETE, TRACE).

  • http-webdav-scan: Tests for WebDAV misconfigurations.

Real-world finding: I have found exposed phpMyAdmin instances, open Jenkins dashboards, and even development backups using this command.


Bonus: The "Everything" Command (For When You Have Permission and Time)

sudo nmap -sS -sV -sC -O -p- -T4 --script=default,vuln,exploit <target> -oA full_engagement

What it does: Everything. Full ports, version detection, OS detection, default scripts, vulnerability checks, and exploit probing. Outputs to three formats for reporting.