$ run as a normal user# run as root (or with sudo)
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).
| Item | Value |
|---|---|
| Package | nmap (plus nmap-ncat / ncat) |
| Programs | nmap, ncat, ndiff (compare scans) |
| Scripts | NSE scripts in /usr/share/nmap/scripts/ |
| Output | normal, 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.
Install on RHEL, Rocky, Alma and Fedora
Install on Ubuntu and Debian
apt-get update
apt-get install -y nmap ncat ndiff
nmap --versionFirst 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 secondsScan 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| Option | Meaning |
|---|---|
-sn | Host discovery only (ping scan). |
-sS | SYN scan (fast, needs root). -sT = full connect scan (no root). |
-sV | Detect service and version. |
-p 22,80,443 / -p- | These ports / all 65,535 ports. |
--top-ports 1000 | The 1,000 most common ports (default). |
-sU | UDP scan (slow — choose ports, for example -sU -p 53,123,161). |
-O | Guess the operating system (root). |
-Pn | Skip host discovery — treat the host as up (when ping is blocked). |
-T4 | Faster timing (use -T3, the default, on fragile networks). |
-oA name | Save normal, XML and grepable output. |
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 nsessl-enum-ciphers grades the TLS versions and ciphers (A–F) — great to check a web server after hardening. -sC runs the safe default scripts.
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 postgresqlndiff 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 9000Real 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.
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).
Update and remove
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn | Ping/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 filtered | A firewall drops everything (or the wrong IP). | Check the target IP; scan from another network; compare with ncat -zv. |
| UDP scan is very slow | UDP has no clear answer for closed ports. | Scan only needed UDP ports; --max-retries 1. |
| Results differ from inside and outside | NAT, cloud security groups, host firewall. | Normal — scan from both sides and compare. |
| The IDS/WAF blocks you | The scan looks like an attack. | Agree on scanner IPs with the security team; slower timing. |
Next steps
- Quick how-tos: Test if a remote port is open, Find which process uses a port, Check the TLS settings of a website, Find open ports on your servers.
- Command page: nmap, Command page: ss.
- At work: Nmap — what is open?.
- Close what Nmap finds: firewalld, UFW. Harden SSH: OpenSSH. TLS: Nginx.
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.