Skip to main content
How To

Install nmap on Ubuntu

Learn to install the latest version of namp on Ubuntu. Also learn the basic usage of nmap in this tutorial.

Sagar Sharma

If you are into network security or you just want to get started with networks, nmap is one of the most basic networking commands that you should know.

And in this tutorial, I will show you two ways of installing nmap:

  • Using apt
  • Using snap (to get the latest version)

Install nmap in Ubuntu

The nmap is available in the default repository of Ubuntu.

But you may get a slightly older version so if you don't care about having the latest version, it can easily be installed with the given command:

sudo apt install nmap

Once done, you can check the installed version using the following command:

nmap -v

And as you can see, the apt gave me the nmap version 7.80.

Need the most recent one? You can check the next method.

Removing nmap

If the given version of nmap is too old for you or it is not relevant anymore for you, it can be easily removed by the given command:

sudo apt remove nmap

You can check the installed version of nmap and it will give you an error saying No such file or directory:

nmap -v
remove namap from ubuntu

Install the latest version of nmap in Ubuntu

If you want the most recent (stable) release of nmap, using snap packages is the best choice you can opt for.

As snap comes pre-configured with Ubuntu, the nmap can easily be installed with one single command:

sudo snap install nmap

And as you can see, it gave me the nmap version 7.93.

To have a seamless experience with nmap (snap version), you will have to grant network access by the following command:

sudo snap connect nmap:network-control

How to remove nmap from Ubuntu

To remove the snap package of nmap, all you have to do is execute the following command:

sudo snap remove nmap
remove nmap snap from ubuntu

Using nmap

✍️
I'll be using scanme.nmap.org, a target made available by nmap itself, for the demonstration. 

Here, I will be sharing some practical examples of how you can use nmap to search for vulnerabilities on your network.

Search open ports on the network using the nmap command

To search for open TCP ports on your network, all you have to do is append the target IP or domain with the sT flag:

nmap -sT scanme.nmap.org
search open ports on network using the nmap command

Once you find open ports, you should close them.

Don't know how to? Here's the guide:

How to Close Open Ports in Linux
Troubleshooting networks? Here’s how to find the open ports and close those open ports in the Linux command line.

Similarly, to search for open UDP ports, you can use the -sU flag:

sudo nmap -sU scanme.nmap.org
search for open udp ports using the nmap command on ubuntu

Scan specific ports using nmap

To search for a specific port, you will have to append the port number to the -p flag.

For example, if I want to search for port 443 (one of the most common networking ports used for HTTPS), I will be using the following command:

nmap -p 443 scanme.nmap.org
search for specif port using nmap on ubuntu

As you can see, the port of 443 is closed!

Scan multiple ports using the nmap command

With a slight change in format to the above command, you can scan multiple ports.

All you have to do is append multiple port numbers separated by comma ( , ) and that's it.

For example, here, I searched for port no. 22,80 and 443:

nmap -p 22,80,443 scanme.nmap.org
scan multiple ports using nmap on ubuntu

That's it from my side.

But you can do a lot more with nmap. Here's the detailed guide on port scanning with the nmap command:

Scanning All or Specified Ports With Nmap
Nmap is an open source utility for network discovery and security auditing. Learn how to scan specific or multiple or all ports with nmap.

New to networks? Start with basics

If you are new to networks, you should start with some basic networking commands and their use:

21 Basic Linux Networking Commands You Should Know
A list of basic Linux networking commands that will help you troubleshoot network issues, monitor packets, connect devices, and much more.

I hope you will find this guide helpful.

And if you have any queries related to this or any other topic, let me know in the comments.

Sagar Sharma