Master nmap Command in Linux

The nmap command in Linux is the tool most admins reach for the moment they need to know what is actually alive and listening on a network. It scans hosts and ports, tells you what services are running, and can even guess the operating system on the other end. If you spend any time doing basic Linux networking work, learning the nmap command in Linux is one of the first skills worth getting comfortable with.

Quick Answer:

This runs a basic scan against a single host and shows you which ports are open.






LinuxTeck
linuxteck@ubuntu:~$ nmap 192.168.1.1

Nmap Usage






LinuxTeck
nmap [scan type] [options] {target}

I broke a staging server once because I ran an aggressive nmap scan against it during business hours and the intrusion detection tooling flagged it as an attack, locked the box down, and paged the whole ops channel. Lesson learned the hard way, always know what you are scanning and who needs a heads up first. Once you work through these nmap command in Linux examples, you will be comfortable running everything from a quick host check to a full service and OS fingerprint scan.


How to Install the Nmap Command in Linux

Nmap sits in the default repository on pretty much every major distro, so you will not need any third party sources for it.






LinuxTeck
# Ubuntu / Debian
sudo apt install nmap

# RHEL / Rocky Linux / Fedora
sudo dnf install nmap

# Arch Linux
sudo pacman -S nmap

Sample Output
Setting up nmap (7.94+dfsg-0ubuntu2) ...
Processing triggers for man-db (2.10.2-1) ...
nmap installed successfully

1. Scan a Single Host

This is the scan you run first, just to see what is open on one machine.






LinuxTeck
linuxteck@ubuntu:~$ nmap 192.168.1.10
Sample Output
Starting Nmap 7.94 ( https://nmap.org )
Nmap scan report for 192.168.1.10
Host is up (0.0012s latency).
Not shown: 996 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp open https
3306/tcp open mysql

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

Anything marked open is worth a second look, especially services like mysql that should never face the public internet directly. If ssh shows up here, it is a good moment to double check your SSH server hardening settings while you are at it.

2. Scan Multiple Hosts at Once

Space separated IPs let you check several machines in a single command instead of running nmap over and over.






LinuxTeck
linuxteck@ubuntu:~$ nmap 192.168.1.10 192.168.1.11 192.168.1.12
Sample Output
Nmap scan report for 192.168.1.10
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http

Nmap scan report for 192.168.1.11
PORT STATE SERVICE
22/tcp open ssh

Nmap scan report for 192.168.1.12
PORT STATE SERVICE
22/tcp open ssh
3389/tcp open ms-wbt-server

Nmap done: 3 IP addresses (3 hosts up) scanned in 2.61 seconds

3. Scan an Entire Subnet

Using CIDR notation scans every address in a range, which is the fastest way to map out a small office or home network.






LinuxTeck
linuxteck@ubuntu:~$ nmap 192.168.1.0/24
Sample Output
Nmap scan report for 192.168.1.1
Host is up (0.0008s latency).
PORT STATE SERVICE
53/tcp open domain
80/tcp open http

Nmap scan report for 192.168.1.10
Host is up (0.0011s latency).
PORT STATE SERVICE
22/tcp open ssh

Nmap done: 256 IP addresses (14 hosts up) scanned in 18.42 seconds

On a busy /24 this can take a while, so grab a coffee if you are running it against a full class C range. This kind of subnet mapping pairs well with the basics covered in our networking protocols guide if some of the service names look unfamiliar.

4. Scan a List of Targets From a File

When you have a long list of servers to check, drop the IPs or hostnames into a text file and point nmap at it with -iL.






LinuxTeck
linuxteck@ubuntu:~$ nmap -iL servers.txt
Sample Output
Nmap scan report for db01.internal (10.0.0.5)
PORT STATE SERVICE
5432/tcp open postgresql

Nmap scan report for web01.internal (10.0.0.6)
PORT STATE SERVICE
80/tcp open http
443/tcp open https

Nmap done: 2 IP addresses (2 hosts up) scanned in 3.02 seconds

5. Detect Service and Version Information

The -sV flag digs deeper than a plain port scan and tries to identify the actual software and version behind each open port.






LinuxTeck
linuxteck@ubuntu:~$ nmap -sV 192.168.1.10
Sample Output
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.9p1 Ubuntu
80/tcp open http nginx 1.24.0
443/tcp open https nginx 1.24.0

Service detection performed. Please report any incorrect results.

This is the first thing I check when a client hands over an unfamiliar server, since it tells me exactly what I am dealing with before touching anything. It is also a fast way to confirm whether a box is actually running the distro and stack the documentation claims it is.

6. Guess the Operating System

OS fingerprinting with -O requires root and works by comparing subtle differences in how the target responds to crafted packets.






LinuxTeck
root@ubuntu:~# nmap -O 192.168.1.10
Sample Output
Running: Linux 5.X
OS CPE: cpe:/o:linux:linux_kernel:5
OS details: Linux 5.4 - 5.15
Network Distance: 1 hop

Concept:

OS detection is a best guess based on packet behavior, not a guarantee. Treat the result as a strong hint, not gospel, especially on hardened or heavily firewalled hosts.

7. Run an Aggressive Scan

The -A flag bundles OS detection, version detection, script scanning, and traceroute into one command, which is handy but noisy on the wire.






LinuxTeck
root@ubuntu:~# nmap -A 192.168.1.10
Sample Output
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.9p1
80/tcp open http nginx 1.24.0
Service Info: OS: Linux

TRACEROUTE
HOP RTT ADDRESS
1 1.12 ms 192.168.1.10

8. Scan Specific Ports

Skip the default port list entirely and tell nmap exactly which ports you care about with -p.






LinuxTeck
linuxteck@ubuntu:~$ nmap -p 22,80,443 192.168.1.10
Sample Output
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp open https

9. Scan Every Port

The default nmap scan only checks the 1000 most common ports. If you want the full picture, all 65535 ports, use -p-.






LinuxTeck
linuxteck@ubuntu:~$ nmap -p- 192.168.1.10
Sample Output
Not shown: 65530 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp open https
8080/tcp open http-proxy
9090/tcp open zeus-admin

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

Production Tip:

A full port scan takes much longer than the default. If you are auditing a production box on a network you manage, this is exactly how you catch a service someone spun up on a random high port and forgot about. Cross check anything unexpected against your server hardening checklist before deciding whether it needs to stay open.

10. Scan the Most Common Ports Only

When you want speed over completeness, --top-ports checks only the N most frequently used ports based on nmap's internal frequency data.






LinuxTeck
linuxteck@ubuntu:~$ nmap --top-ports 20 192.168.1.10
Sample Output
PORT STATE SERVICE
21/tcp closed ftp
22/tcp open ssh
23/tcp closed telnet
80/tcp open http
443/tcp open https

11. Run a Stealthy SYN Scan

A SYN scan, sometimes called a half open scan, sends a SYN packet and never completes the handshake. It is faster and quieter than a full connect scan but it needs raw socket access, which means root.






LinuxTeck
linuxteck@ubuntu:~$ nmap -sS 192.168.1.10
Sample Output
You requested a scan type which requires root privileges.
QUITTING!

Common Mistake:

Running -sS as a regular user fails silently or gets rejected because crafting raw TCP packets needs elevated permissions. Prefix the command with sudo and it works exactly as expected.






LinuxTeck
root@ubuntu:~# nmap -sS 192.168.1.10
Sample Output
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
443/tcp open https

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

12. Scan UDP Ports

DNS, DHCP, and SNMP all run over UDP, so a TCP only scan will completely miss them. UDP scanning is slower because of how the protocol handles non responses, so scope it down when you can. If you also want to see what is bound and listening locally on the box itself, the ss command is the faster local equivalent.






LinuxTeck
root@ubuntu:~# nmap -sU -p 53,67,161 192.168.1.1
Sample Output
PORT STATE SERVICE
53/udp open domain
67/udp open dhcps
161/udp open snmp

13. Skip Host Discovery on Filtered Networks

Some firewalls block the ping probes nmap sends before scanning, which makes it think the host is down even when it is not. The -Pn flag skips that check and scans anyway.






LinuxTeck
linuxteck@ubuntu:~$ nmap -Pn 192.168.1.10
Sample Output
Nmap scan report for 192.168.1.10
PORT STATE SERVICE
22/tcp open ssh
443/tcp open https

14. Save Scan Results to a File

Piping results straight to the terminal is fine for a quick check, but for audits or reports you want them saved. -oN writes a normal text file and -oX writes XML you can feed into other tools.






LinuxTeck
linuxteck@ubuntu:~$ nmap -oN scan_results.txt 192.168.1.10
Sample Output
Nmap scan report for 192.168.1.10
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http

# Nmap done at Tue Aug 25 09:14:02 2026
Results saved to scan_results.txt

15. Check for Known Vulnerabilities With NSE Scripts

Nmap ships with a scripting engine called NSE. The vuln category runs a batch of scripts that check for known CVEs and misconfigurations against open services.






LinuxTeck
root@ubuntu:~# nmap --script vuln 192.168.1.10
Sample Output
PORT STATE SERVICE
80/tcp open http
| http-slowloris-check:
| VULNERABLE:
|_ Slowloris DOS attack

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

Do not run this against anything you do not own or manage. It is genuinely useful for auditing your own infrastructure but it is intrusive by design, and running it against boxes outside your control is a good way to get a call from an ISP. If you want to practice safely, spin up a throwaway VPS just for this, this comparison of DigitalOcean and Vultr is a decent starting point if you are picking a provider for a lab box. For a more complete toolkit alongside nmap, our roundup of Linux security tools is worth a read, and if you want a dedicated environment built for this kind of work, installing Kali Linux is the usual route people take.


Conclusion

These fifteen nmap command in Linux examples cover most of what you will actually reach for day to day, from a quick host check to a full vulnerability sweep. Pair nmap with a solid understanding of your firewall rules and you will start catching misconfigurations before they become incidents. Which nmap example do you find most useful? Share your experience in the comments below.

LinuxTeck, A Complete Linux Learning Blog
From your first terminal command to advanced sysadmin skills, every guide here is written in plain English with real examples you can run right now.

About Aneeshya S

Aneeshya S is a Senior Linux Trainer and System Administrator with over 10 years of experience. She actively follows emerging technologies and industry trends. Outside the terminal, she enjoys music and travel.

View all posts by Aneeshya S →

Leave a Reply

Your email address will not be published.

L