itsfosslinux

How to Install Nmap on Ubuntu/Debian

In this article, we will see how to install nmap on Ubuntu/Debian based systems. Nmap is a free and open source network scanner tool for network discovery and security auditing. It is often used by security testers, penetration testers and network testers to perform security analysis of an organization computer network. Nmap scans the network by sending packets and analyzing the response received. It is used to detect number of hosts and services independent of target systems. It is also very frequently used for network inventory, managing service upgrade schedules and monitoring host or services uptime.

The number of features of provided by Nmap makes it an ideal tool for the job. It does not only come as a command line executable tool but there is a complete GUI suite available as well to use. It includes results viewer tool like Zenmap, flexible data transfer, redirection, debugging utility tool called ncat and many more. It is also quite easy to install in almost all the famous platforms including on linux systems. Here we will see the steps to install Nmap on Ubuntu/Debian based systems.

 

How to Install Nmap on Ubuntu/Debian

How to Install Nmap on Ubuntu/Debian

Also Read: How to Update or Upgrade Packages on Ubuntu/Debian

Step 1: Prerequisites

a) You should have a running Ubuntu/Debian Server.

b) You should have sudo or root access to run privileged commands.

c) You should have apt or apt-get utility available in your Server.

d) You should have snap utility available to install nmap as snap package.

 

Step 2: Update Your Server

Before installing any new packages in the system, it is essential to check for all latest available updates and install them by using sudo apt update && sudo apt upgrade command as shown below.

itsfosslinux@ubuntu:~$ sudo apt update && sudo apt upgrade
[sudo] password for itsfosslinux:
Hit:1 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:2 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:3 https://dl.winehq.org/wine-builds/ubuntu focal InRelease
Hit:4 https://d3nt0h4h6pmmc4.cloudfront.net/ubuntu focal InRelease
Hit:5 http://ppa.launchpad.net/flatpak/stable/ubuntu focal InRelease
Hit:6 http://in.archive.ubuntu.com/ubuntu focal InRelease
Hit:7 https://ngrok-agent.s3.amazonaws.com buster InRelease
Get:8 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:9 http://ppa.launchpad.net/gencfsm/ppa/ubuntu focal InRelease
Ign:10 https://pkg.jenkins.io/debian-stable binary/ InRelease
Hit:11 https://pkg.jenkins.io/debian-stable binary/ Release
Hit:12 http://ppa.launchpad.net/juju/stable/ubuntu focal InRelease
...................................................

 

Step 3: Install Nmap

Nmap can be installed on Ubuntu/Debian based systems by using any of the below methods depending on your needs and requirements.

a) Using Apt

The easiest way to install nmap is from default Ubuntu repo by using sudo apt install nmap command as shown below. This will download and install the package along with all its dependencies.

itsfosslinux@ubuntu:~$ sudo apt install nmap
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libblas3 liblinear4 lua-lpeg nmap-common
Suggested packages:
liblinear-tools liblinear-dev ncat ndiff zenmap
The following NEW packages will be installed:
libblas3 liblinear4 lua-lpeg nmap nmap-common
0 upgraded, 5 newly installed, 0 to remove and 2 not upgraded.
Need to get 5,553 kB of archives.
After this operation, 26.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://in.archive.ubuntu.com/ubuntu focal/main amd64 libblas3 amd64 3.9.0-1build1 [142 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 liblinear4 amd64 2.3.0+dfsg-3build1 [41.7 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 lua-lpeg amd64 1.0.2-1 [31.4 kB]
Get:4 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 nmap-common all 7.80+dfsg1-2build1 [3,676 kB]
Get:5 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 nmap amd64 7.80+dfsg1-2build1 [1,662 kB]
Fetched 5,553 kB in 10s (567 kB/s)
Selecting previously unselected package libblas3:amd64.
(Reading database ... 261632 files and directories currently installed.)
Preparing to unpack .../libblas3_3.9.0-1build1_amd64.deb ...
Unpacking libblas3:amd64 (3.9.0-1build1) ...
Selecting previously unselected package liblinear4:amd64.
..............................................

b) Using snap

Another very popular way to install nmap is through snap utility. You can install nmap as a snap package from snap store by using sudo snap install nmap command as shown below.

itsfosslinux@ubuntu:~$ sudo snap install nmap
nmap 7.94 from Maximiliano Bertacchini (maxiberta) installed

 

Step 4: Verify Installation

If you installed nmap from default Ubuntu repo using apt or apt-get package manager then you can check the installed files path after installation by using dpkg -L nmap command as shown below.

itsfosslinux@ubuntu:~$ dpkg -L nmap
/.
/usr
/usr/bin
/usr/bin/nmap
/usr/bin/nping
/usr/share
/usr/share/doc
/usr/share/doc/nmap
/usr/share/doc/nmap/changelog.Debian.gz
/usr/share/doc/nmap/copyright
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/nmap
/usr/share/man
/usr/share/man/de
/usr/share/man/de/man1
/usr/share/man/de/man1/nmap.1.gz
/usr/share/man/es
/usr/share/man/es/man1
/usr/share/man/es/man1/nmap.1.gz
/usr/share/man/fr
...............................................

 

Step 5: Check Version

After successful installation, check the current installed version by using nmap --version command as shown below.

itsfosslinux@ubuntu:~$ nmap --version
Nmap version 7.94 ( https://nmap.org )
Platform: x86_64-unknown-linux-gnu
Compiled with: nmap-liblua-5.4.4 openssl-3.0.2 libssh2-1.10.0 libz-1.2.11 libpcre-8.39 libpcap-1.10.1 nmap-libdnet-1.12 ipv6
Compiled without:
Available nsock engines: epoll poll select

 

Step 6: Using Nmap

Now that nmap application is installed, you can quickly use it to scan google.com by using nmap google.com command as shown below. This will scan and show the status of port along with the service running.

itsfosslinux@ubuntu:~$ nmap google.com
Starting Nmap 7.94 ( https://nmap.org ) at 2023-10-29 21:14 IST
Nmap scan report for google.com (142.250.77.46)
Host is up (0.030s latency).
Other addresses for google.com (not scanned): 2404:6800:4009:80d::200e
rDNS record for 142.250.77.46: bom07s26-in-f14.1e100.net
Not shown: 995 filtered tcp ports (no-response)
PORT     STATE SERVICE
21/tcp   open  ftp
80/tcp   open  http
443/tcp  open  https
554/tcp  open  rtsp
1723/tcp open  pptp

Nmap done: 1 IP address (1 host up) scanned in 5.17 seconds

 

Step 7: Check all available options

You can check all the options available with nmap command using nmap --help command as shown below.

itsfosslinux@ubuntu:~$ nmap --help
Nmap 7.94 ( https://nmap.org )
Usage: nmap [Scan Type(s)] [Options] {target specification}
TARGET SPECIFICATION:
  Can pass hostnames, IP addresses, networks, etc.
  Ex: scanme.nmap.org, microsoft.com/24, 192.168.0.1; 10.0.0-255.1-254
  -iL <inputfilename>: Input from list of hosts/networks
  -iR <num hosts>: Choose random targets
  --exclude <host1[,host2][,host3],...>: Exclude hosts/networks
  --excludefile <exclude_file>: Exclude list from file
HOST DISCOVERY:
  -sL: List Scan - simply list targets to scan
  -sn: Ping Scan - disable port scan
  -Pn: Treat all hosts as online -- skip host discovery
  -PS/PA/PU/PY[portlist]: TCP SYN/ACK, UDP or SCTP discovery to given ports
  -PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes
  -PO[protocol list]: IP Protocol Ping
  -n/-R: Never do DNS resolution/Always resolve [default: sometimes]
  --dns-servers <serv1[,serv2],...>: Specify custom DNS servers
  --system-dns: Use OS's DNS resolver
  --traceroute: Trace hop path to each host
...................................................

 

Step 8: Uninstall Nmap

Once you are done using nmap utility, you can choose to uninstall it from your system by using any of the below methods depending on how you have installed it.

a) Using Apt

If you installed nmap from default ubuntu repo using apt or apt-get package manager then to uninstall you have to run sudo apt remove nmap command as shown below.

itsfosslinux@ubuntu:~$ sudo apt remove nmap
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libblas3 liblinear4 lua-lpeg nmap-common
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
nmap
0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded.
After this operation, 4,499 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 262508 files and directories currently installed.)
Removing nmap (7.80+dfsg1-2build1) ...
Processing triggers for man-db (2.9.1-1) ...

b) Using Snap

If you installed as a snap package then to uninstall you have to run sudo snap remove nmap command as shown below.

itsfosslinux@ubuntu:~$ sudo snap remove nmap
nmap removed

Leave a comment