Nmap command is a useful tool for discovering devices, checking open ports, and understanding how computers communicate over a network. System administrators and IT professionals use it to troubleshoot connections, identify running services, and check network security.
If you are new to networking, Nmap might seem complicated at first. However, you can perform many useful checks with just a few simple commands.
In this guide, you will learn what Nmap is, how it works, and how to use its most common options.
What Is the Nmap Command?
Nmap stands for Network Mapper. It is a free, open-source command-line tool for network discovery and security auditing.
It helps you find information about computers, servers, and other devices connected to a network.
You can use Nmap to:
- Discover active devices on a network.
- Check which ports are open.
- Identify services running on a server.
- Detect service versions.
- Troubleshoot network connectivity.
- Find potentially unnecessary network services.
For example, if a web server is not responding, Nmap can help you check whether its HTTP or HTTPS port is accessible.
Unlike Netstat or the SS command, which inspect connections and sockets on a computer, Nmap examines how a target responds to network probes.
Important: Only scan devices and networks you own or have explicit permission to test.
How Does the Nmap Command Work?
Nmap command sends network packets to a target and analyzes the responses.
Depending on the scan type, it can determine whether a device is reachable, which ports accept connections, and what services might be running.
For example, a server may use:
- Port 22: SSH for remote access.
- Port 53: DNS queries.
- Port 80: HTTP web traffic.
- Port 443: HTTPS secure web traffic.
You can learn more about these in our article on port numbers in networking.
Nmap does not automatically prove that an open port is a security vulnerability. It simply provides information that helps you investigate your network.
How to Install Nmap
Nmap works on Windows, Linux, and macOS.
Install Nmap on Linux
On Ubuntu or Debian, run:
sudo apt update
sudo apt install nmap
On Fedora, use:
sudo dnf install nmap
Install Nmap on macOS
If you use Homebrew, run:
brew install nmap
Install Nmap on Windows
Download the installer from the official Nmap website and follow the installation instructions.
After installation, open your terminal or Command Prompt and enter:
nmap –version
If Nmap displays version information, you are ready to start.
Basic Nmap Command Syntax
The basic syntax is:
nmap [options] [target]
The target can be an IP address or domain name.
For example:
nmap 127.0.0.1
This scans your own computer using its loopback address.
By default, Nmap checks the 1,000 most common TCP ports. The exact scanning technique depends on your operating system and available privileges.
Let’s explore several useful examples.
1. Scan a Specific IP Address
To scan your own computer, run:
nmap 127.0.0.1
Nmap checks common TCP ports and reports their states.
This is a good starting point because you can practice without scanning another device.
2. Check a Specific Port
Sometimes you only need to check one port.
Use the -p option:
nmap -p 80 127.0.0.1
This checks TCP port 80 on your computer.
To check several ports, separate them with commas:
nmap -p 22,80,443 127.0.0.1
You can also specify a range:
nmap -p 20-100 127.0.0.1
This checks TCP ports 20 through 100.
Targeted port scanning is useful when troubleshooting a particular application.
3. Discover Active Devices
Nmap can help you identify devices connected to a network you manage.
Use the -sn option:
nmap -sn 192.168.1.0/24
This performs host discovery without running a port scan.
The /24 identifies a subnet containing 256 IP addresses. Replace the example subnet with your own authorized network range.
Nmap reports devices it detects as active. However, firewalls and network settings may prevent some devices from responding.
4. Identify Running Services
An open port tells you that a service may be accessible, but it does not always identify the application.
Use -sV to request service version detection:
nmap -sV -p 80,443 127.0.0.1
Nmap probes accessible services and attempts to identify their software and versions.
For example, it might recognize a web server running on port 80.
Keep in mind that version detection is not always accurate. Some services hide or modify their version information.
5. Scan UDP Ports
Nmap normally focuses on TCP ports. However, some important services use UDP.
For example, traditional DNS commonly uses UDP port 53.
To check a UDP port on your own computer, run:
sudo nmap -sU -p 53 127.0.0.1
The -sU option enables UDP scanning.
UDP scanning often takes longer than TCP scanning because many UDP services do not respond to unexpected packets.
You may also see an open|filtered result, which means Nmap cannot determine whether the port is open or a firewall is filtering the traffic.
How to Read Nmap Results
Understanding the output is just as important as running the command.
Here is a simplified example:
PORT STATE SERVICE
22/tcp open ssh
80/tcp closed http
443/tcp filtered https
The three main columns are:
PORT: Shows the port number and protocol.
STATE: Indicates whether the port is open, closed, or filtered.
SERVICE: Shows the service commonly associated with that port or one identified through probing.
The most common port states are:
- Open: An application accepts connections on the port.
- Closed: The port is reachable, but no application is accepting connections.
- Filtered: Nmap cannot determine whether the port is open because filtering blocks its probes or responses.
The example above is illustrative. Your actual results will depend on your computer and network configuration.
Nmap vs Ping: What’s the Difference?
Both tools help with network troubleshooting, but they serve different purposes.
The Ping command checks whether a device responds to network probes and measures response times.
Nmap command goes further by checking ports, discovering services, and providing additional information about a target.
For example, a device might respond to Ping while its web server remains unavailable. Nmap can help you investigate whether the expected web port is accessible.
Neither tool alone can identify every possible network problem.
Nmap and DNS Troubleshooting
Nmap can also support DNS troubleshooting.
For example, you can check whether a DNS server you manage responds on TCP or UDP port 53. However, an accessible port does not guarantee that DNS queries work correctly.
To inspect actual DNS records, you need a DNS-specific tool.
The Dig command guide explains how to query DNS records, while the Nslookup command provides another way to investigate domain resolution.
Conclusion
The Nmap command is a practical tool for understanding network activity and troubleshooting connectivity problems.
You can use it to discover active devices, inspect ports, identify services, and investigate network configurations.
If you are a beginner, start by scanning your own computer and checking individual ports. Once you understand the output, explore other options as needed.
With a little practice, Nmap can become a valuable part of your everyday networking toolkit.

Hi, I’m Bella, a technology enthusiast who enjoys making complex tech topics clear, practical, and easy to understand. Outside of writing, I love trail running, biking, traveling, and photography.


