Mastering Linux: How to Install and Use ‘Nmap’

Mastering Linux: How to Install and Use ‘Nmap’

Illustration of a Linux terminal displaying the installation of the nmap command a network mapping tool used for network discovery and security auditing

Are you looking to install nmap on your Linux system but aren’t sure where to start? Many Linux users, particularly beginners, might find the task intimidating. Yet installing nmap will make it easy to scan your network via the Linux command line. Nmap is readily available on most package management systems, making it a straightforward process once you know-how.

In this tutorial, we will guide you on how to install the nmap command on your Linux system. We will show you methods for both APT and YUM-based distributions, delve into compiling nmap from source, installing a specific version, and finally, how to use the nmap command and ensure it’s installed correctly.

So, let’s dive in and begin installing nmap on your Linux system!

TL;DR: How Do I Install and Use the ‘nmap’ Command in Linux?

In most Linux distributions, the ‘nmap’ command comes pre-installed. However, if it’s not, you can install it in Debian based distributions like Ubuntu, using the command sudo apt-get install nmap. For distributions like CentOS that use RPM package manager yum, you would run the command sudo yum install nmap.

# For Debian based distributions like Ubuntu
sudo apt-get install nmap

# For RPM based distributions like CentOS
sudo yum install nmap

# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# nmap is already the newest version (7.60-1ubuntu5).
# 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

This is just a basic way to install the nmap command in Linux, but there’s much more to learn about installing and using nmap. Continue reading for more detailed information and advanced usage scenarios.

Understanding the Nmap Command

Before we dive into the installation process, let’s understand what nmap is. The nmap command is a network scanner tool in Linux that helps you discover hosts and services on a computer network. It does so by sending packets to the host and analyzing the responses. nmap is a powerful tool for system administrators who want to audit their network for open ports, services running, and potential vulnerabilities.

Now that we understand what nmap is and why we need it, let’s get to the installation process.

Installing Nmap with APT

If you’re using a Debian-based Linux distribution, such as Ubuntu, you can use the APT package manager to install nmap. Here’s how you can do it:

sudo apt update
sudo apt install nmap

# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# The following additional packages will be installed: nmap-common
# Suggested packages: nmap-doc
# The following NEW packages will be installed: nmap nmap-common
# 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
# Need to get 4,823 kB of archives.
# After this operation, 22.3 MB of additional disk space will be used.
# Do you want to continue? [Y/n]

In this code block, we first update the package list using the sudo apt update command. Then, we install nmap using the sudo apt install nmap command. The output indicates that nmap and nmap-common will be installed.

Installing Nmap with YUM

For CentOS or other RPM-based distributions, you can use the YUM package manager to install nmap. Here’s how:

sudo yum update
sudo yum install nmap

# Output:
# Loaded plugins: fastestmirror, langpacks
# Loading mirror speeds from cached hostfile
# Resolving Dependencies
# --> Running transaction check
# ---> Package nmap.x86_64 2:6.40-19.el7 will be installed
# --> Finished Dependency Resolution
# Total download size: 4.0 M
# Installed size: 16 M
# Is this ok [y/d/N]:

In this code block, we first update the package list using the sudo yum update command. Then, we install nmap using the sudo yum install nmap command. The output indicates that nmap will be installed.

Installing Nmap from Source

Sometimes, you may want to install nmap from source. This allows you to access the latest features, even if they’re not yet available in the package repositories. Here’s how to do it:

tar xf nmap-7.91.tar.bz2
cd nmap-7.91
sudo make install

# Output:
# Configuring the source...
# Compiling...
# Installing...

In this code block, we first download the source code using the wget command. We then extract the tarball with tar xf. After navigating into the directory with cd, we prepare the build with ./configure, compile the source code with make, and then install it with sudo make install.

Installing Specific Versions of Nmap

From Source

Installing a specific version from source is similar to the general source installation method. You just need to replace the version number in the URL with the version you want. For example, to install version 7.80, you would use wget

Using Package Managers


For APT, you can use the apt-cache madison nmap command to view available versions. To install a specific version, use sudo apt install nmap=.


For YUM, you can use the yum --showduplicates list nmap command to view available versions. To install a specific version, use sudo yum install nmap-.

Version Comparison

Different versions of nmap come with different features and improvements. For instance, version 7.80 introduced new scripts and enhancements, while version 7.90 provided improvements in NSE scripts and libraries. Here’s a summary:

VersionKey Features
7.80New scripts and enhancements
7.90Improvements in NSE scripts and libraries
7.91Bug fixes and updated libraries

Basic Usage and Verification

Using Nmap

To use nmap, you can start with a simple command like nmap localhost. This will scan the localhost for open ports and services.

Verifying Installation

To verify that nmap is installed correctly, you can use the nmap -v command. This will display the version of nmap that is currently installed.

Exploring Alternative Network Scanning Methods

While nmap is a powerful tool for network scanning, it isn’t the only one available in Linux. Let’s explore some alternative methods and their respective advantages and disadvantages.

Using the ‘netstat’ Command

The netstat command is another utility for network scanning in Linux. It displays network connections, routing tables, interface statistics, and more.

netstat -a

# Output:
# Active Internet connections (servers and established)
# Proto Recv-Q Send-Q Local Address           Foreign Address         State
# tcp        0      0 localhost:domain        *:*                     LISTEN
# tcp        0      0 localhost:ipp           *:*                     LISTEN

In this example, we use netstat -a to display all active network connections. The output shows various details about these connections.

Advantages: netstat is simple to use and comes pre-installed on many Linux distributions.

Disadvantages: netstat is not as feature-rich as nmap. It’s best for basic network monitoring and not for detailed network audits.

Manual Network Scanning

Manual network scanning involves using a variety of Linux commands and utilities to gather information about the network. This could involve commands such as ping, traceroute, nslookup, and others.

ping -c 4 localhost

# Output:
# PING localhost ( 56(84) bytes of data.
# 64 bytes from localhost ( icmp_seq=1 ttl=64 time=0.045 ms
# 64 bytes from localhost ( icmp_seq=2 ttl=64 time=0.041 ms
# 64 bytes from localhost ( icmp_seq=3 ttl=64 time=0.041 ms
# 64 bytes from localhost ( icmp_seq=4 ttl=64 time=0.041 ms

In this example, we use ping -c 4 localhost to send four ICMP echo requests to the localhost. The output shows the responses from the localhost.

Advantages: Manual network scanning gives you granular control over the scanning process. You can use exactly the tools and commands you need for your specific use case.

Disadvantages: Manual network scanning can be time-consuming and complex, especially for large networks. It also requires a deep understanding of networking and Linux commands.

In conclusion, while nmap is a robust and widely used tool for network scanning in Linux, there are alternatives available. The best tool for the job depends on your specific needs and level of expertise.

Overcoming Common Nmap Challenges

While nmap is a powerful tool, it’s not without its quirks. Here are some common issues you might face while using nmap and how to solve them.

Nmap Command Not Found

If you see a ‘nmap: command not found’ error, it means nmap is not installed or not in your PATH.


# Output:
# Command 'nmap' not found, but can be installed with...

You can solve this by installing nmap as described earlier. If nmap is installed but not in your PATH, you can add it with the export PATH=$PATH:/path/to/nmap command, replacing ‘/path/to/nmap’ with the actual path to the nmap binary.

Nmap ‘Host seems down’ Error

Sometimes, nmap might report that a host seems down even if it’s up. This can happen if the host is ignoring or dropping the ICMP echo requests that nmap sends to determine if a host is up.


# Output:
# Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn

You can solve this by using the -Pn option, which tells nmap to assume the host is up.

nmap -Pn

# Output:
# Nmap scan report for
# Host is up (0.00046s latency).

Nmap ‘Filtered’ Ports

nmap might report some ports as ‘filtered’. This means nmap can’t determine whether the port is open because packet filtering is preventing its probes from reaching the port.

nmap localhost

# Output:
# 22/tcp   open     ssh
# 80/tcp   filtered http

The solution depends on the reason for the filtering. It could be a firewall, in which case you might need to adjust its rules. Or it could be that the service is not running or is configured to ignore probes.

In conclusion, while nmap is a highly useful tool, it can sometimes present challenges. Understanding these common issues and their solutions will help you use nmap more effectively.

Understanding Network Scanning in Linux

Network scanning is a vital aspect of system administration and network security. It involves probing network devices or a range of IP addresses to discover active hosts and identify the services they offer. This information is critical for both network mapping and vulnerability assessment.

The Role of the ‘nmap’ Command

In the realm of network scanning, nmap stands as a versatile tool. Short for ‘Network Mapper’, nmap is a free and open-source utility that administrators use for network discovery and security auditing. It can detect hosts on a network, the services they offer, the operating systems they run, the type of packet filters/firewalls they use, and many other attributes.

# An example of nmap command
nmap -A -T4

# Output:
# Starting Nmap 7.91 ( )
# Nmap scan report for
# Host is up (0.00046s latency).
# Not shown: 998 closed ports
# 22/tcp   open  ssh     OpenSSH 5.9p1 Debian 5ubuntu1 (Ubuntu Linux; protocol 2.0)
# 80/tcp   open  http    Apache httpd 2.2.22 ((Ubuntu))

In the above code block, we use nmap -A -T4 to scan the host at The -A option enables OS detection, version detection, script scanning, and traceroute, while -T4 sets the timing template to ‘aggressive’. The output provides information about the open ports and the services they’re running.

Network Scanning and Security

Network scanning is an essential part of maintaining a secure network. By identifying the active hosts and the services they offer, you can spot potential vulnerabilities that attackers might exploit. Regular network scanning with tools like nmap helps keep your network secure and your data safe.

Network Scanning: A Fundamental Skill in System Administration

Network scanning, as you’ve learned throughout this guide, is a crucial skill in system administration. It provides insights into the active hosts in a network, the services they offer, and potential vulnerabilities. Tools like nmap provide a comprehensive way to conduct network scanning, but they’re just the tip of the iceberg.

Delving into Firewall Configurations

Firewall configurations are a critical part of network security. They define the rules for what traffic is allowed into and out of a network. Understanding how to configure firewalls in Linux can significantly enhance your network’s security.

# An example of a firewall rule in Linux
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT

# Output:
# [sudo] password for user: 

In this code block, we use the iptables command to add a rule to the INPUT chain. The rule accepts all incoming TCP traffic on port 80, which is the standard port for HTTP.

Exploring Intrusion Detection Systems

Intrusion Detection Systems (IDS) are another critical aspect of network security. They monitor a network for suspicious activity and alert administrators when such activity is detected. Linux offers several IDS tools, each with its own strengths and weaknesses.

# An example of an IDS command in Linux
sudo snort -q -c /etc/snort/snort.conf -i eth0

# Output:
# Running in IDS mode
# --== Initializing Snort ==--
# Initializing Output Plugins!

In this code block, we use the snort command to run Snort, a popular IDS in Linux. The -q option makes Snort run in quiet mode, the -c option specifies the configuration file, and the -i option specifies the interface to listen on.

Further Resources for Network Scanning Proficiency

If you’re interested in diving deeper into network scanning and related topics, here are some resources to check out:

  1. Nmap Official Documentation: The official documentation for nmap is a comprehensive resource for understanding its capabilities and how to use them.

  2. Linux Firewalls: This tutorial series by DigitalOcean provides an in-depth look at iptables, the Linux firewall.

  3. Intrusion Detection in Linux: This article from Linux Journal offers a broad overview of Intrusion Detection Systems in Linux.

Wrapping Up: Installing the ‘nmap’ Command in Linux

In this comprehensive guide, we’ve explored the installation and usage of the ‘nmap’ command in Linux, a powerful tool for network scanning. We’ve covered everything from the basic installation process using package managers like APT and YUM, to more advanced methods such as installing from source and installing specific versions. Along the way, we’ve also delved into the basic and advanced usage of nmap, providing practical code examples to illustrate each concept.

We began with the basic installation process, showing how to install nmap on both APT and YUM-based distributions. We then moved onto more advanced installation methods, discussing the process of installing nmap from source and installing specific versions. We also showcased the basic usage of nmap and how to verify its correct installation.

Next, we looked at alternative methods for network scanning in Linux, such as the ‘netstat’ command and manual network scanning. We discussed the advantages and disadvantages of each method, providing code examples for each. We also touched on common issues you might encounter when using the ‘nmap’ command and provided solutions to help you overcome these challenges.

Here’s a quick comparison of the methods we’ve discussed:

nmapComprehensive features, widely usedMay require troubleshooting for some networks
netstatSimple to use, pre-installed on many distributionsLess feature-rich than nmap
Manual Network ScanningGranular control over the scanning processCan be time-consuming and complex

We hope this guide has given you a deeper understanding of how to install and use the ‘nmap’ command in Linux. Whether you’re a system administrator looking to audit your network, a security enthusiast interested in network scanning, or a user trying to troubleshoot network issues, mastering nmap is a valuable skill. Happy networking!