Advanced
Searching inInstall guides
How to search
  • Paste an error message in quotes, e.g. "permission denied", to find the fix table that explains it.
  • Choose an area and a part of the guide (install, first settings, daily use, security, fixes) to go straight to the right step.
  • "two words" finds the exact phrase.
  • Plain words find names, texts and examples.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search
Try:

Guide 69Nmap · Security

Install and use Nmap (network scanner)

Nmap answers the first question of every security check: what is out there, and what is open? It finds live hosts, open ports, the services and versions behind them, TLS settings and much more with its script engine. Admins use it to check their own firewalls from the outside, to build inventories, and to verify that a change really closed a port. This guide installs Nmap on RHEL and Ubuntu, explains the main scan types, shows the commands you need every day, and how to compare scans over time.

  • 10 Lessons
  • 7 Commands

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

69.1

Know it before you install

Nmap sends packets and reads the answers. A port is open (a service answers), closed (the host answers "no"), or filtered (a firewall drops the packets — no answer). Root rights allow faster and more precise scans (raw packets).

ItemValue
Packagenmap (plus nmap-ncat / ncat)
Programsnmap, ncat, ndiff (compare scans)
ScriptsNSE scripts in /usr/share/nmap/scripts/
Outputnormal, XML (-oX), grepable (-oG); -oA writes all three

Watch out

Scan only networks and hosts you own or have written permission to scan. In many countries and companies an unauthorized scan is illegal or a policy violation. Tell the network/security team before big scans.

Commands in this lesson

69.2

Install on RHEL, Rocky, Alma and Fedora

dnf -y install nmap nmap-ncat
nmap --version

69.3

Install on Ubuntu and Debian

apt-get update
apt-get install -y nmap ncat ndiff
nmap --version

Commands in this lesson

69.4

First steps: discover and scan

Find live hosts in your network (no port scan):

nmap -sn 10.0.1.0/24
Nmap scan report for web1.lab (10.0.1.11)
Host is up (0.00041s latency).
…
Nmap done: 256 IP addresses (14 hosts up) scanned in 2.10 seconds

Scan the most common ports with service versions:

nmap -sS -sV --top-ports 1000 -T4 10.0.1.11
PORT     STATE    SERVICE  VERSION
22/tcp   open     ssh      OpenSSH 9.9 (protocol 2.0)
80/tcp   open     http     nginx
443/tcp  open     ssl/http nginx
5432/tcp filtered postgresql
OptionMeaning
-snHost discovery only (ping scan).
-sSSYN scan (fast, needs root). -sT = full connect scan (no root).
-sVDetect service and version.
-p 22,80,443 / -p-These ports / all 65,535 ports.
--top-ports 1000The 1,000 most common ports (default).
-sUUDP scan (slow — choose ports, for example -sU -p 53,123,161).
-OGuess the operating system (root).
-PnSkip host discovery — treat the host as up (when ping is blocked).
-T4Faster timing (use -T3, the default, on fragile networks).
-oA nameSave normal, XML and grepable output.

Commands in this lesson

69.5

Scripts (NSE): TLS, HTTP and more

nmap --script ssl-enum-ciphers -p 443 shop.example.com
nmap --script ssl-cert -p 443 shop.example.com
nmap -sV --script http-title,http-headers -p 80,443 10.0.1.11
nmap -sC -sV -p 22 10.0.1.11
nmap --script ssh2-enum-algos -p 22 10.0.1.11
ls /usr/share/nmap/scripts | grep -c nse

ssl-enum-ciphers grades the TLS versions and ciphers (A–F) — great to check a web server after hardening. -sC runs the safe default scripts.

69.6

Daily use: audits and comparisons

Check your firewall from the outside (for example from a cloud VM), and save the result:

nmap -sS -sV -p- -T4 -oA scans/web1-$(date +%F) 203.0.113.10
nmap -sU -p 53,123,161,500 203.0.113.10
ndiff scans/web1-2026-11-01.xml scans/web1-2026-11-17.xml
-Nmap 7.95 scan initiated … as: nmap -sS -sV -p- …
 203.0.113.10:
-5432/tcp filtered postgresql
+5432/tcp open     postgresql

ndiff shows what changed between two scans — a port that was opened by mistake stands out at once. Quick checks with ncat:

ncat -zv 10.0.1.21 5432
ncat -l 9000

Real uses at work:

  • Verify firewall changes: "is 3306 really closed from the internet now?"
  • Asset inventory: what is on this subnet, which versions run.
  • TLS and SSH crypto checks after hardening; weekly external scans compared with ndiff.

69.7

Make it safe

Security checklist:

  • Written permission and scope (which IPs, which time) before every scan.
  • Start gently (-T3, top ports) on production networks; avoid aggressive scripts there.
  • Keep scan results private — they are a map for attackers.
  • Scan from the right place: from outside for internet exposure, from inside for internal exposure.
  • Keep Nmap updated (new service fingerprints and scripts).

69.8

Update and remove

dnf -y upgrade nmap
apt-get install --only-upgrade -y nmap
dnf -y remove nmap

Commands in this lesson

69.9

Fix common problems

ProblemCauseFix
Note: Host seems down. If it is really up, but blocking our ping probes, try -PnPing/ICMP blocked.Add -Pn.
You requested a scan type which requires root privileges-sS, -O or -sU without root.Use sudo, or -sT (connect scan).
All ports filteredA firewall drops everything (or the wrong IP).Check the target IP; scan from another network; compare with ncat -zv.
UDP scan is very slowUDP has no clear answer for closed ports.Scan only needed UDP ports; --max-retries 1.
Results differ from inside and outsideNAT, cloud security groups, host firewall.Normal — scan from both sides and compare.
The IDS/WAF blocks youThe scan looks like an attack.Agree on scanner IPs with the security team; slower timing.

Commands in this lesson

69.10

Next steps

1What is the difference between closed and filtered?

Closed = the host answers that nothing listens. Filtered = no answer, a firewall drops the packets.

2How do you see which ports changed since last week's scan?

Save both scans as XML (-oA) and compare them with ndiff.

All commands in this chapter