The Nmap (Network Mapper) command is one of the most powerful and widely used tools in the Linux environment for network exploration and security auditing. nmap
is often used for tasks like discovering hosts and services on a computer network, managing network inventory, and conducting security assessments. This tool can scan a range of IP addresses and provide valuable information, such as open ports, services running, and their versions.

In this article, we will cover the nmap
command in detail, discussing its syntax, options, use cases, and practical examples. Whether you’re a network administrator, a cybersecurity enthusiast, or someone who just wants to explore the depths of their network, nmap
will be a valuable tool in your arsenal.
Prerequisites
Before using the Nmap command, ensure the following prerequisites are met:
- Linux Distribution:
nmap
is available on all major Linux distributions, such as Ubuntu, CentOS, Fedora, and Debian. - Root Privileges: Some
nmap
scans require elevated privileges (root access) to function effectively, especially when performing scans that involve sending raw packets. - Nmap Installed: Most Linux distributions provide
nmap
through their package managers.
The nmap
command Syntax
The basic syntax of the nmap
command is as follows:
nmap [options] [target]
Where:
- [options]: Various flags and options that modify the scan.
- [target]: The IP address, IP range, or hostname you wish to scan.
Most Common nmap
Command Options
Option | Description |
---|---|
-p | Specifies the ports to scan. You can specify individual ports, ranges, or comma-separated lists. |
-sS | Performs a TCP SYN scan (stealth scan), which is faster and more discreet. |
-sU | Performs a UDP scan, which scans open UDP ports. |
-O | Enables operating system detection by analyzing TCP/IP stack behavior. |
-v | Enables verbose mode, providing detailed output about the scan process and results. |
-A | Performs an aggressive scan, including OS detection, version detection, script scanning, and traceroute. |
-T | Specifies the timing template for scan speed (0 to 5). Higher values increase speed but reduce stealth. |
--script | Executes nmap scripts to automate tasks like vulnerability detection. |
-oN | Outputs scan results to a normal (plain text) file. |
-sV | Enables service version detection to determine the version of services running on open ports. |
-oX | Outputs scan results in XML format for further processing. |
-oG | Outputs scan results in a “grepable” format, suitable for further parsing with grep or other tools. |
-iL | Specifies an input file containing a list of IP addresses or hostnames to scan. |
--exclude | Excludes specific hosts from the scan. |
-Pn | Skips host discovery, assuming the target is online (useful for blocking ICMP requests). |
--disable-arp | Disables ARP discovery, which is useful for scanning in environments with a lot of ARP noise. |
-6 | Forces nmap to scan IPv6 addresses. |
-h | Displays help information about nmap and its options. |
--traceroute | Traces the route to the target host to determine the path of packets. |
Install Nmap on Ubuntu, Debian, CentOS, RHEL, Fedora
To use nmap
, you must first install it on your Linux system. If you don’t have it installed, you can easily install it. Here’s how you can install nmap
on various Linux distributions:
- On Ubuntu/Debian:
Update your package list:
sudo apt update
Install Nmap on Ubuntu/Debian:
sudo apt install nmap
- On CentOS/RHEL:
Install Nmap on CentOS/RHEL:
sudo yum install nmap
- On Fedora:
Install Nmap on Fedora:
sudo dnf install nmap
Once installed, you can check that nmap
is correctly set up by running:
nmap --version
This will display the installed version of Nmap.
namp Command in Linux: Practical Examples
- Basic Port Scan
To scan a target IP (e.g., www.youstable.com
) for the 1,000 most common ports:
nmap www.youstable.com
Output:
Starting Nmap 7.93 ( https://nmap.org ) at 2025-06-08 14:00 UTC
Nmap scan report for www.youstable.com (192.168.1.1)
Host is up (0.0010s latency).
rDNS record for 192.168.1.1: www.youstable.com
PORT STATE SERVICE VERSION
80/tcp open http Apache httpd 2.4.41
443/tcp open https Apache httpd 2.4.41
8080/tcp open http-proxy Apache httpd 2.4.41
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Nmap done: 1 IP address (1 host up) scanned in 5.46 seconds
Now let’s scan using the IP Address.
nmap 192.168.1.1
Output:
Starting Nmap 7.93 ( https://nmap.org ) at 2025-06-08 14:10 UTC
Nmap scan report for 192.168.1.
Host is up (0.0010s latency).
Not shown: 997 filtered ports
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 5.12 seconds
- Scanning Multiple IP Addresses
If you want to scan a range of IPs or a subnet, use the following command:
nmap 192.168.1.1-50
This will scan IP addresses from 192.168.1.1
to 192.168.1.50
.
- Operating System and Version Detection
To detect the operating system and the version of the services running on a target:
nmap -A 192.168.1.1
This aggressive scan will also give you detailed information about the target system’s OS and running services.
- Scan Specific Ports
If you are only interested in scanning for HTTP and HTTPS services, you can specify ports 80 and 443:
nmap -p 80,443 192.168.1.1
- Saving Output to a File
To save the scan results to a file:
nmap -oN output.txt 192.168.1.1
This will store the results in the output.txt
file for later reference.
Additional Tips and Best Practices
- Stealth Scanning: Use the
-sS
(SYN Scan) option to avoid detection by firewalls or intrusion detection systems (IDS). It’s a stealthier method as it doesn’t complete the TCP handshake. - Scan Exclusions: You can exclude certain IP addresses or ranges from your scan using the
--exclude
option. - Service Version Detection: Use
-sV
to detect the version of services running on open ports.
nmap -sV 192.168.1.1
- Timing Control: When scanning large networks, controlling the timing with the
-T
option can help reduce the time taken for a scan. Be cautious, as high timing values can increase the likelihood of detection.
Conclusion
The nmap
command in Linux is a versatile and essential tool for network scanning and security auditing. With its wide range of options and scanning techniques, you can tailor your scans to fit specific needs, whether you’re performing a quick check of open ports or a deep dive into operating systems and services. By mastering the Nmap command, you can enhance both your network management and cybersecurity skills.