Table of Contents
In this article, I will take you through the steps to install Nmap on Ubuntu 20.04 LTS (Focal Fossa). Nmap is a free and powerful port scanner tool to scan hosts on a network. It is well around for over past two decades and loved over by millions of security testers, penetration testers, developers, programmers and by many other around the world due to the wide variety of features it provides.
Not just that, the release Nmap Scripting Engine(NSE) elevated the role of Nmap from a simple networking tool to a fully robust and customizable vulnerability engine. More on official website. It is also very easy to install in Linux and Widows based system. Here we will see the steps to install Nmap on Ubuntu 20.04 LTS based systems.
How to Install Nmap on Ubuntu 20.04 LTS (Focal Fossa)
Also Read: How to Install Filezilla on Ubuntu 20.04 LTS (Focal Fossa)
Step 1: Prerequisites
a) You should have a running Ubuntu 20.04 LTS
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 System.
Step 2: Update Your Server
Before going through the steps to install Nmap on your System, it is absolutely necessary to update your System with the latest available versions from default Ubuntu repo and then upgrade all the required packages as well by using sudo apt update && sudo apt upgrade
command as shown below.
cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade
[sudo] password for cyberithub:
Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 https://dl.winehq.org/wine-builds/ubuntu focal InRelease
Get:3 https://dl.google.com/linux/chrome/deb stable InRelease [1,811 B]
Hit:4 https://repo.nordvpn.com//deb/nordvpn/debian stable InRelease
Hit:5 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal InRelease
Hit:6 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:7 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:8 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:9 http://ppa.launchpad.net/wireshark-dev/stable/ubuntu focal InRelease
Hit:10 https://apt.boltops.com stable InRelease
Get:11 https://dl.google.com/linux/chrome/deb stable/main amd64 Packages [1,118 B]
Get:12 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:13 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [40.7 kB]
Get:14 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [92.9 kB]
Get:15 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [745 kB]
Get:16 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [2,464 B]
Get:17 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [2,196 kB]
Get:18 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [275 kB]
Get:19 http://in.archive.ubuntu.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [405 kB]
Get:20 http://in.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [944 B]
Get:21 http://in.archive.ubuntu.com/ubuntu focal-backports/main amd64 DEP-11 Metadata [7,976 B]
Get:22 http://in.archive.ubuntu.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [30.5 kB]
Fetched 4,136 kB in 4s (995 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
4 packages can be upgraded. Run 'apt list --upgradable' to see them.
N: Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'https://apt.boltops.com stable InRelease' doesn't support architecture 'i386'
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
filezilla-common libfilezilla0 libpugixml1v5
...............................................
Step 3: Install Nmap
In the next step, you can download and install Nmap 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.
cyberithub@ubuntu:~$ sudo apt install nmap [sudo] password for cyberithub: Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: filezilla-common libfilezilla0 libpugixml1v5 Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: liblinear4 lua-lpeg nmap-common Suggested packages: liblinear-tools liblinear-dev ncat ndiff zenmap The following NEW packages will be installed: liblinear4 lua-lpeg nmap nmap-common 0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded. Need to get 5,412 kB of archives. After this operation, 25.8 MB of additional disk space will be used. Do you want to continue? [Y/n] Y ...................................................
Step 4: Verify Installation
After successful installation, you can verify the installed files by using dpkg -L nmap
command as shown below.
cyberithub@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
You can also verify the installed version by using nmap --version
command as shown below.
cyberithub@ubuntu:~$ nmap --version Nmap version 7.80 ( https://nmap.org ) Platform: x86_64-pc-linux-gnu Compiled with: liblua-5.3.3 openssl-1.1.1d nmap-libssh2-1.8.2 libz-1.2.11 libpcre-8.39 libpcap-1.9.1 nmap-libdnet-1.12 ipv6 Compiled without: Available nsock engines: epoll poll select
Step 6: Scan using Nmap
Now that Nmap is successfully installed, you can use it to scan target by using nmap <options><target_ip>
syntax. In our case, we are scanning our local system of IP address 192.168.0.108
using nmap 192.168.0.108
command as shown below. In the scan results, you can see that it is detecting an open SSH Port 22
.
cyberithub@ubuntu:~$ nmap 192.168.0.108 Starting Nmap 7.80 ( https://nmap.org ) at 2022-11-03 09:43 IST Nmap scan report for harbor.example.com (192.168.0.108) Host is up (0.000073s latency). Not shown: 999 closed ports PORT STATE SERVICE 22/tcp open ssh Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds
Step 7: Check all Available Options
You can check all the options available with nmap tool using nmap -h
command as shown below.
cyberithub@ubuntu:~$ nmap -h
Nmap 7.80 ( 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 with Nmap, you can choose to uninstall it from the System by using sudo apt remove nmap
command as shown below. But please check for any unwanted package removal before running below command as sometimes it uninstall some packages which are used by some other active running application. So that might cause a disaster especially when you are performing below step in a production or critical system.
cyberithub@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: filezilla-common libfilezilla0 liblinear4 libpugixml1v5 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 0 not upgraded. After this operation, 4,499 kB disk space will be freed. Do you want to continue? [Y/n] Y (Reading database ... 272631 files and directories currently installed.) Removing nmap (7.80+dfsg1-2build1) ... Processing triggers for man-db (2.9.1-1) ...