Last updated: 28 October 2026. Sources are listed at the end.

Nmap is usually the first tool a security tester runs against a network, so it makes sense to run it yourself first. This guide covers the nmap commands for admins who want to know what their own network exposes: which hosts are up, which ports are open, and what software answers on them.

Companion download. The Nmap Admin Pack (₹49) packs this guide into a two-page cheat sheet, a weekly scan script that diffs against last week’s results, and a findings tracker spreadsheet.

It is written for sysadmins and developers who look after a small or mid-size office network or a few servers. We ran every scan below in an Ubuntu 24.04 lab container with Nmap 7.94 from the Ubuntu repositories. All lab scans targeted 127.0.0.1 only. For LAN examples we use the documentation range 192.0.2.0/24, so replace it with your own subnet.

The short answer

  • Scan only networks you own or have written permission to test.
  • Start with nmap -sn for host discovery, then nmap --top-ports 100 for a quick look.
  • Run a full nmap -p- at least once, because the fast scans skip most ports.
  • Add -sV -sC to see versions and run the default safe scripts.
  • Save every scan with -oA and compare runs with ndiff.
  • Run as root (or with sudo) for SYN scans and OS detection; without root, Nmap falls back to a slower connect scan.

Before you scan: permission and the law

Scan only systems you own or manage, or ones you have written permission to test. A port scan is usually harmless. However, an aggressive scan can crash old printers, VoIP phones or industrial devices. It can also trigger your provider’s abuse team.

In India, the Information Technology Act, 2000 is the main law here. Section 43 covers accessing or securing access to a computer system or network without the owner’s permission, and it carries civil compensation. Section 66 makes the same acts a criminal offence when done dishonestly or fraudulently, with up to three years in prison, a fine up to five lakh rupees, or both. This is general information and not legal advice. So for client work, get the scope and permission in writing first, as we describe in our guide to web application VAPT scope, steps and report.

Root or not: why it changes the scan

Several nmap commands behave differently with and without root. For example, Nmap picks a different TCP scan type depending on your privileges. As root, it sends raw packets and runs a SYN scan (-sS). As a normal user, it uses the operating system’s connect() call instead (-sT), which completes the full handshake and shows up in more application logs.

We tested both in the lab. First, as the unprivileged nobody user:

$ nmap -d -p 2222,8088 127.0.0.1
Initiating Connect Scan at 07:02
Completed Connect Scan at 07:02, 0.00s elapsed (2 total ports)

Then, as root, the same command printed Initiating SYN Stealth Scan instead.

OS detection is stricter. Without root, Nmap refuses to run it:

$ nmap -O -p 2222 127.0.0.1
TCP/IP fingerprinting (for OS scan) requires root privileges.
QUITTING!

Host discovery: who is on the network?

Host discovery finds out which IP addresses are alive. The -sn option skips the port scan and only checks for live hosts.

sudo nmap -sn 192.0.2.0/24

On a local Ethernet or Wi-Fi segment, Nmap run as root uses ARP requests for discovery. ARP works even when a host’s firewall blocks ping. Without root, Nmap tries TCP connections to ports 80 and 443 instead, which can miss hosts.

Behind routers or firewalls that drop ICMP, live hosts can look dead. In that case, use -Pn to skip discovery and treat every address as up:

sudo nmap -Pn --top-ports 100 192.0.2.10

-Pn is slower on large ranges, because Nmap scans every address, including empty ones. Use it on specific hosts you know exist.

Port scanning nmap commands for admins

Step 1: A fast top-ports scan

This scan checks the 100 most common TCP ports. We tested it in our lab against 127.0.0.1, where we had started a test SSH server on port 2222, a Python web server on 8088 and an OpenSSL TLS server on 8443.

# nmap -T4 --top-ports 100 127.0.0.1
PORT     STATE SERVICE
8443/tcp open  https-alt

Nmap done: 1 IP address (1 host up) scanned in 0.07 seconds

The fast scan found only one of our three services. Ports 2222 and 8088 are not in the top 100 list, so Nmap never checked them. nmap -F gave the same result.

Step 2: A full TCP scan with -p-

This command checks all 65,535 TCP ports. We ran it in the same lab.

# nmap -p- -T4 127.0.0.1
Not shown: 65529 closed tcp ports (reset)
PORT      STATE SERVICE
2024/tcp  open  xinuexpansion4
2222/tcp  open  EtherNetIP-1
8088/tcp  open  radan-http
8443/tcp  open  https-alt
40383/tcp open  unknown
43689/tcp open  unknown

Now all three test services appear. The other three ports belonged to the lab container’s own tooling, and a full scan is how you find services like these. Also note the SERVICE column. Without -sV, Nmap only guesses the service from a port-number table, so “EtherNetIP-1” on 2222 is wrong.

Step 3: Service and version detection with -sV

-sV connects to each open port and probes it to identify the software and version. We tested it in our lab.

# nmap -sV -p 2222,8088,8443 127.0.0.1
PORT     STATE SERVICE  VERSION
2222/tcp open  ssh      OpenSSH 9.6p1 Ubuntu 3ubuntu13.20 (Ubuntu Linux; protocol 2.0)
8088/tcp open  http     SimpleHTTPServer 0.6 (Python 3.13.18)
8443/tcp open  ssl/http OpenSSL s_server -www httpd (command line: s_server -accept 127.0.0.1:8443 -cert cert.pem -key key.pem -www -quiet)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

The OpenSSL test server leaked its full command line, including file names, to anyone who can reach the port. Version scans are slower, though: this one took about 40 seconds for three ports.

Step 4: OS detection with -O

OS detection (sudo nmap -O 192.0.2.10) needs root and works best when it finds at least one open and one closed port. In our lab, nmap -O -p 2222,8088 127.0.0.1 warned that results may be unreliable and returned a list of guesses from “Linux 5.0 – 5.7 (96%)” down to an AXIS network camera. Treat OS guesses as hints; the -sV banner is often more precise.

Default scripts and safe NSE checks

The Nmap Scripting Engine (NSE) runs Lua scripts against open ports. -sC runs the “default” category, which the Nmap project treats as safe and useful. Pair it with -sV so the scripts know what service is on a non-standard port.

# nmap -sC -p 2222,8088 127.0.0.1
PORT     STATE SERVICE
2222/tcp open  EtherNetIP-1
| ssh-hostkey: 
|_  256 bd:de:31:6b:ad:55:42:f2:43:4f:15:b8:de:44:05:47 (ED25519)
8088/tcp open  radan-http
|_http-title: Directory listing for /

The http-title result is worth a look: our test web server was showing a directory listing. A few single scripts are also worth running on their own. We tested each one in the lab.

Check SSH key exchange, ciphers and MACs. Use the result alongside our SSH hardening checklist for Ubuntu 24.04:

# nmap -p 2222 --script ssh2-enum-algos 127.0.0.1
|   kex_algorithms: (12)
|       sntrup761x25519-sha512@openssh.com
|       curve25519-sha256
...
|   mac_algorithms: (10)
...
|       hmac-sha1

The default OpenSSH 9.6p1 server still offers hmac-sha1 MACs. This is common and not urgent, although a hardened config can drop them.

Check TLS versions and cipher grades:

# nmap -p 8443 --script ssl-enum-ciphers 127.0.0.1
|   TLSv1.2: 
|     ciphers: 
|       TLS_DHE_RSA_WITH_AES_128_CBC_SHA (dh 2048) - A
...
|_  least strength: A

For web servers, --script http-headers,http-title shows response headers such as Server:, which on our test server gave away the Python version.

On networks with Windows file shares, smb-security-mode and smb2-security-mode report whether SMB signing is required. We had no SMB server in the lab, so we did not run them.

UDP basics: slow but worth it

UDP services such as DNS, SNMP and NTP are easy to forget. Scan the top 20 UDP ports first:

sudo nmap -sU --top-ports 20 192.0.2.10

On loopback this took 0.14 seconds. On a real network it is much slower, because many hosts rate-limit the ICMP “port unreachable” replies that Nmap relies on. Linux, for example, limits them to about one per second by default. Also, an open UDP port often sends no reply, so Nmap reports open|filtered. We saw this with a small Python UDP listener on port 9999:

# nmap -sU -p 9998,9999 127.0.0.1
PORT     STATE         SERVICE
9998/udp closed        distinct32
9999/udp open|filtered distinct

Adding -sV sends protocol-specific probes and can turn open|filtered into open, at the cost of more time.

How to read open, closed and filtered

StateWhat it meansWhat to do
openA service accepts connections on the portConfirm it should be there and who owns it
closedThe host replied, but nothing listensUsually fine; a firewall could still drop it
filteredNo reply, or an ICMP error; a firewall is likely in the wayCheck the firewall rule is intended
open or filteredNmap cannot tell which (common for UDP)Retry with -sV or check the host directly

Timing: be gentle on production

Nmap’s default timing is -T3. -T4 is faster and usually fine on modern wired networks, while -T5 is best avoided. For fragile networks or a busy WAN link, cap the packet rate:

sudo nmap -sS -p- -T3 --max-rate 300 192.0.2.0/24

--max-rate 300 means at most 300 packets per second. Run heavy scans outside business hours and tell your team first, because an IDS may alert on them.

Save results and compare scans with ndiff

-oA name writes three files at once: normal text (.nmap), grepable (.gnmap) and XML (.xml). The XML file is what ndiff compares.

Ndiff was not installed in our Ubuntu 24.04 lab. It is a separate package in the universe repository, so we installed it:

sudo apt install ndiff

We then took two scans with the same options. Between them, we stopped the web server on 8088 and started one on 9090:

# ndiff scan-before.xml scan-after.xml
 localhost (127.0.0.1):
 PORT     STATE  SERVICE    VERSION
-8088/tcp open   http       SimpleHTTPServer 0.6 (Python 3.13.18)
+8088/tcp closed radan-http
-9090/tcp closed zeus-admin
+9090/tcp open   http       SimpleHTTPServer 0.6 (Python 3.13.18)

Lines with - come from the old scan and lines with + from the new one. Ndiff exits with 0 when nothing changed, 1 when something changed and 2 on error. We confirmed all three exit codes in the lab.

A weekly inventory diff routine

This script scans your ranges, saves the result with today’s date, and diffs it against the previous scan. We tested it in our lab against 127.0.0.1 with a short port list, running it twice with a new listener started in between. Save it as /usr/local/sbin/nmap-weekly.sh.

#!/usr/bin/env bash
# Weekly inventory scan + diff. Run as root (SYN scan) from cron.
set -euo pipefail

TARGETS="${TARGETS:-192.0.2.0/24}"          # your own ranges only
OUTDIR="${OUTDIR:-/var/lib/nmap-inventory}"
PORTS="${PORTS:-1-65535}"
STAMP="$(date +%F)"

mkdir -p "$OUTDIR"
cd "$OUTDIR"

nmap -sS -sV -p "$PORTS" -T3 --max-rate 300 --open \
  -oA "scan-$STAMP" $TARGETS > /dev/null

PREV="$(ls -1 scan-*.xml | grep -v "scan-$STAMP.xml" | tail -n 1 || true)"

if [ -n "$PREV" ]; then
  if ndiff "$PREV" "scan-$STAMP.xml" > "diff-$STAMP.txt"; then
    echo "No changes since $PREV"
  else
    echo "Changes since $PREV:"
    cat "diff-$STAMP.txt"
  fi
else
  echo "First run: baseline saved as scan-$STAMP.xml"
fi

On the second run, it printed +9090/tcp open http for the listener we had added. Next, schedule it in root’s crontab for Monday at 02:30, and mail yourself the output:

30 2 * * 1 TARGETS="192.0.2.0/24" /usr/local/sbin/nmap-weekly.sh 2>&1 | mail -s "nmap weekly diff" admin@example.com

The mail command needs a configured mail setup, which we did not test. A full -p- -sV scan of a /24 at 300 packets per second can take hours, so start with a smaller range and time it.

What to do with findings

Every open port should have an owner and a reason. For each unexpected one, work through these steps:

  1. Find the process. On Linux, sudo ss -ltnp shows which program listens on each TCP port.
  2. Stop and disable the service if nobody needs it.
  3. Bind it to 127.0.0.1 or an internal interface if only local access is needed.
  4. Restrict it with a firewall rule (ufw, nftables or your perimeter firewall) if a few hosts need it.
  5. Patch it if -sV shows an old version, then re-scan to confirm.

Treat an old version string from -sV as a lead to check. Ubuntu backports security fixes without changing the upstream version number, so check the package changelog before you panic.

Nmap commands cheat sheet

GoalCommandNeeds root?
Find live hostsnmap -sn 192.0.2.0/24No, but ARP discovery on a LAN needs root
Scan a host that blocks pingnmap -Pn 192.0.2.10No
Quick common portsnmap -T4 --top-ports 100 192.0.2.10No (root gives SYN scan)
All TCP portsnmap -p- 192.0.2.10No (root gives SYN scan)
Service versionsnmap -sV 192.0.2.10No
Default safe scriptsnmap -sV -sC 192.0.2.10No
OS detectionnmap -O 192.0.2.10Yes
SSH algorithmsnmap -p 22 --script ssh2-enum-algos 192.0.2.10No
TLS ciphersnmap -p 443 --script ssl-enum-ciphers 192.0.2.10No
Top 20 UDP portsnmap -sU --top-ports 20 192.0.2.10Yes
Gentle scannmap -T3 --max-rate 300 192.0.2.0/24No
Save all formatsnmap -oA weekly 192.0.2.0/24No
Compare two scansndiff old.xml new.xmlNo

Zenmap and current Nmap versions

Zenmap is the official graphical front end for Nmap. It shows the command line it builds, which helps when you are learning the options, and it can compare saved scans. On Ubuntu 24.04 it is in the universe repository as the zenmap package. We did not test it in our headless lab.

Ubuntu 24.04 ships Nmap 7.94, which is what we used. At the time of writing, the nmap.org changelog lists Nmap 7.992 (15 October 2026) as the newest release. The options in this guide are long-standing, but we only tested 7.94. If you need newer NSE scripts or fingerprints, nmap.org offers source code and RPM packages. Nmap also comes preinstalled on Kali, which we cover in our introduction to Kali Linux.

Quick checklist

Use this list to turn the nmap commands above into a routine.

  • ☐ Written permission or ownership confirmed for every range you scan
  • ☐ Host discovery run with -sn (as root on the LAN for ARP)
  • ☐ At least one full -p- TCP scan per network
  • ☐ -sV -sC run on all open ports
  • ☐ SSH and TLS checked with ssh2-enum-algos and ssl-enum-ciphers
  • ☐ Top 20 UDP ports scanned
  • ☐ Scans saved with -oA and compared with ndiff
  • ☐ Weekly diff scheduled, rate-limited, outside business hours
  • ☐ Every open port has an owner, or it is closed, firewalled or patched

Regular nmap commands show what is exposed, but a full assessment also tests whether those services can be broken into. For that, our VAPT services team can help. You can also run a quick public check with the free website safety check or browse more utilities in our tools directory.

Related guides

Sources

Need help finding and fixing exposed systems? Our VAPT services find unpatched and exposed systems before attackers do, and our free website safety check grades your site in seconds. Contact us for a quote.

Post author avatar

Bhaskar Soni

Bhaskar Soni is a Security Engineer and the founder of Youngster Company, based in Ahmedabad, Gujarat. He works hands-on with Linux server hardening, vulnerability assessment and penetration testing (VAPT), ISO 27001 compliance and OSINT investigations. He writes practical, tested guides for IT professionals and Indian businesses, and every article on this site is written or reviewed by him.

Leave a Reply