Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

nmap

The network mapper: find hosts, open ports, running services and versions, and check TLS — to audit your own network.

Level
DevSecOps service
Group
Security scanning and hardening
Needs root
For changes
Package
nmap

What it does

nmap sends probes to hosts and ports and reports which ports are open, closed or filtered. With -sV it detects service versions, with -O the OS, and the NSE scripts add checks (TLS ciphers, HTTP headers, SSH algorithms, known CVEs). DevSecOps use: check that only the ports you expect are open after a deployment, find forgotten services, and verify firewall rules from the outside.

Scan only networks you own or are allowed to test.

How to write it

nmap [SCAN TYPE] [OPTIONS] TARGETS

Main parts

Scan types

-sS
TCP SYN scan (default as root; fast, half-open).
-sT
TCP connect scan (default as normal user).
-sU
UDP scan (slow).
-sn
Host discovery only, no ports.
-sV
Detect service versions.
-O
Detect the OS.
-A
-O -sV -sC --traceroute together.
-sC / --script NAME
Default / chosen NSE scripts.

Options 10

Most used

Options

-p PORTS / -p-
Ports (22,80,443 / 1-65535 / all).
--top-ports N
The N most common ports.
-Pn
Skip ping (hosts that block ICMP).
-T0 … -T5
Timing (T3 default, T4 faster).
-oN / -oX / -oG / -oA FILE
Output: normal, XML, grepable, all.
--open
Show only open ports.
-iL FILE
Targets from a file.
--exclude HOSTS
Skip hosts.
-6
IPv6.
--reason
Why a port has its state.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Which hosts are up in the lab?

    nmap -sn 192.168.122.0/24
  2. 2Open ports and versions on one server

    sudo nmap -sS -sV --open 192.168.122.11
  3. 3All TCP ports

    sudo nmap -p- --open -T4 192.168.122.11
  4. 4Check what the internet sees (run from outside)

    nmap -Pn --top-ports 100 --open shop.example.com
  5. 5TLS versions and ciphers

    nmap --script ssl-enum-ciphers -p 443 shop.example.com
  6. 6SSH algorithms

    nmap --script ssh2-enum-algos -p 22 192.168.122.11
  7. 7HTTP security headers and title

    nmap --script http-security-headers,http-title -p 80,443 shop.example.com
  8. 8UDP services (DNS, NTP, SNMP)

    sudo nmap -sU -p 53,123,161 192.168.122.1
  9. 9Compare two scans after a change

    sudo nmap -sS -p- -oX before.xml 192.168.122.11
    sudo nmap -sS -p- -oX after.xml 192.168.122.11
    ndiff before.xml after.xml
  10. 10Scan a list of servers and save all formats

    sudo nmap -sV -iL servers.txt -oA weekly-$(date +%F)

Watch out

  • Scanning networks without permission can be illegal and can trigger security alerts.
  • "filtered" means a firewall drops the probes — not that the port is safe.

Files

/usr/share/nmap/scripts/
NSE scripts.

Tips to remember

  • Put a weekly nmap + ndiff of your public IPs into a pipeline and alert on new open ports.

Exit codes

0Success.
1Error.