How to Install Nmap on Ubuntu 24.04, 22.04 or 20.04

This guide will demonstrate how to install Nmap on Ubuntu 24.04, 22.04, or 20.04 LTS utilizing the command-line terminal. Options include using Ubuntu’s default APT repository for convenience or downloading and compiling Nmap for the latest version.

Nmap, short for Network Mapper, is a powerful and versatile cybersecurity and network administration tool. It excels at network discovery and security auditing. Nmap allows users to identify what devices are running on their networks, discover open ports, and detect security risks. With its flexible and robust capabilities, Nmap serves as an essential tool for network administrators, security professionals, and IT enthusiasts looking to gain insights into their network’s infrastructure.

Engaging with Nmap enhances your understanding of network security landscapes and equips you with the knowledge to mitigate potential threats. Its adaptability across network types and operating systems makes it a valuable resource. When installing Nmap on Ubuntu, users have the flexibility to choose between the stability and ease of the default APT repository or the cutting-edge features of the latest compiled version.

Key Benefits of Using Nmap Include:

  • Efficient Network Mapping: Quickly identifies all devices connected to a network.
  • Port Scanning Capabilities: Discovers open ports and assesses network security.
  • Versatile Toolset: Offers a range of options for deep network analysis.
  • Security Auditing: Helps identify vulnerabilities within the network.
  • Customizable Scripts: Enhances functionality with NSE (Nmap Scripting Engine).
  • Cross-Platform: Runs on Linux, Windows, and macOS.
  • Free and Open Source: Ensures accessibility and continuous improvement by the community.
  • Active Community: Provides extensive support and resources for users.

Transitioning into the technical how-to segment makes the process straightforward and manageable.

Install Nmap on Ubuntu via APT

Update Ubuntu System Before Nmap Installation

Before embarking on installing any new software, it’s essential to ensure your Ubuntu system is up-to-date. This step ensures the smooth installation of new packages and fortifies your system’s security by applying the latest patches and fixes.

Let’s initiate the system update by executing the following command in the terminal. This command performs an update check for all packages and then upgrades those packages to their latest version:

sudo apt update && sudo apt upgrade

The sudo command allows you to run the update as a superuser, ensuring you have the necessary permissions to execute these operations. apt update fetches the package information from all configured sources – essentially, it ensures it has the latest list of packages from each repository. Following the &&, apt upgrade installs new versions of packages you’ve already installed, effectively updating your system.

Install Nmap on Ubuntu via APT Command

Now that your Ubuntu system is fully updated, you can install Nmap on Ubuntu 22.04 or 20.04. Thankfully, Ubuntu includes Nmap in its primary software repositories, meaning you can install Nmap directly without adding any additional repositories or compiling any source code.

You can initiate the installation of Nmap by running the following command:

sudo apt install nmap

This command will fetch Nmap from the repository, resolve any dependencies, and proceed with the installation.

Verifying the Installation of Nmap

After installation, it’s crucial to verify that Nmap is correctly installed and ready to use. One straightforward method to confirm this is by checking the Nmap version installed on your system.

Use the following command to check the version of Nmap:

nmap --version

The command nmap --version will provide output detailing the installed version and build of Nmap. This confirms that Nmap is installed correctly and ensures you’re working with the most recent version.

Install Nmap on Ubuntu via Source

In some cases, users might require the latest version of Nmap or the pre-packaged version provided in Ubuntu’s repositories might not meet their specific needs. Compiling Nmap from source provides a solution for such users, ensuring you have the latest features and updates. This method involves extra steps, and you would need to check for updates and re-compile regularly, but it could provide benefits for advanced users or specific requirements.

Install Nmap Initial Packages

Before delving into the source code world, we must prepare our system with the right tools. The package ‘build-essential’ contains an informational list of packages considered essential for building Ubuntu packages, including the gcc compiler, make, and other required tools. This package will allow us to compile and build Nmap from the source. To install ‘build-essential,’ open your terminal and enter:

sudo apt install build-essential libssh2-1-dev libssl-dev python3-distutils

Download Nmap Source Archive on Ubuntu

The next step is to download the Nmap source code. This can be obtained from the official Nmap download page. We will download the latest stable release using the wget command. Please note that at the time of this guide, the latest stable release is 7.93, but this may vary. Always check the download page for the newest version number and link, and adjust the command accordingly.

To download the Nmap source code, use the following:

wget https://nmap.org/dist/nmap-7.93.tar.bz2

Note: Ensure you download the latest version of Nmap. Commands for Nmap v7.93 may be outdated, so always use commands compatible with the most recent version you’ve downloaded.

Extracting the Nmap Source Code

Having downloaded the Nmap source code, we now need to extract the files from the archive. To do this, use the following commands:

bzip2 -cd nmap-7.93.tar.bz2 | tar xvf -
cd nmap-7.93

Configure the Nmap Build

We’re now ready to start the configuration process. This prepares the Nmap source code for compilation on your specific system, ensuring compatibility and optimized performance. To configure the build, run the following:

./configure

Alternatively, you may prefer to install with localdirs:

./configure --with-localdirs
Configuring Nmap build on Ubuntu for versions 24.04, 22.04, and 20.04.
Configuration steps for Nmap build on Ubuntu.

Compile Nmap on Ubuntu

With the build configured, we can now compile the source code. This is done using the ‘make’ command, which reads the ‘Makefile’ in the Nmap source directory and compiles the source code accordingly:

make
Terminal output of the 'make' command during Nmap installation on Ubuntu.
Terminal showing the ‘make’ process for Nmap.

Install Nmap on Ubuntu via make install Command

We can install Nmap after we’ve successfully compiled the source code. This step places the compiled program in appropriate directories on your system. To install Nmap, use the following:

make install

Verifying the Compiled Nmap Installation

After installation, it’s crucial to confirm that Nmap has been correctly installed from the source and it’s the latest version. To check this, use the command:

nmap --version

This command will display the installed version of Nmap, which should correspond to the version of the source code you downloaded. With this, you’ve successfully compiled and installed the latest version of Nmap from source on your Ubuntu system.

Successful Nmap installation confirmation on Ubuntu versions 24.04, 22.04, 20.04.
Confirmation of Nmap’s successful installation.

Basic Nmap Commands with Ubuntu

Nmap offers a multitude of commands that provide powerful and varied functionality, but it’s essential to start with the basics. Understanding these fundamental commands will form a solid foundation for building more complex network scanning and mapping strategies. This section explores some of these basic commands and their respective functions.

Note: Additionally, visit our post “Nmap Commands for Beginners: Simple Scanning Tips” to learn more about basic Nmap commands.

Performing a Basic Scan with Nmap

A simple ping scan is the most straightforward scan you can perform with Nmap. This scan tests whether a host is reachable and responsive. This is achieved by sending Internet Control Message Protocol (ICMP) echo request packets to the target hosts and waiting for a response.

Execute the following command to perform a simple ping scan:

nmap -sn 192.168.1.0/24

The above command, -sn instructs Nmap to perform a ping scan. The 192.168.1.0/24 specifies the range of IP addresses to be scanned – in this case, it’s all IP addresses from 192.168.1.1 to 192.168.1.254 inclusive.

Scanning Specific Ports with Nmap

Nmap can also be directed to scan specific ports on a host. This can be useful when investigating a particular service or suspect a specific port may be vulnerable.

Use the following command to scan a specific port:

nmap -p 80 192.168.1.1

In this command, -p followed by 80 tells Nmap to scan port 80 (typically used for HTTP web services). The 192.168.1.1 is the IP address of the target host.

Scanning Multiple Ports with Nmap

In situations where you want to scan more than one port simultaneously, Nmap provides an easy way to do this. You need to list the ports separated by commas.

Execute the following command to scan multiple ports:

nmap -p 80,443 192.168.1.1

Here, -p followed by 80,443 instructs Nmap to scan port 80 and port 443 (commonly used for HTTPS services).

Performing a Full Port Scan with Nmap

Sometimes, you may need to scan all 65535 ports comprehensively. While this type of scan is time-consuming, it gives you the most complete view of the open ports on a host.

Here’s the command to perform a full port scan:

nmap -p- 192.168.1.1

In this case, -p- instructs Nmap to scan all ports on the host 192.168.1.1.

Closing Thoughts

Wrapping up, this guide walked you through installing Nmap on Ubuntu, giving you the choice between the simplicity of the APT repository and the freshness of compiling from source. Remember, Nmap is your go-to for keeping tabs on your network’s pulse, from spotting open ports to uncovering vulnerabilities. If you’re serious about network security, make Nmap part of your toolkit. And hey, don’t forget to keep it updated for the latest features and security patches. Stay curious, keep learning, and happy scanning!

Leave a Comment


Your Mastodon Instance
Share to...