December 3, 2021
How to install and using nmap on Linux Ubuntu 20.04

How To Install and Use nmap Command Line on Linux

On this tutorial we will learn how to install and using nmap command line on Linux Ubuntu 20.04 LTS operating system.

Introduction

Nmap (Network Mapper) is a free and open-source powerful network and serucity tool for network discovery and security auditing. It is widely used by Unix/Linux users community for troubleshooting network connectivity issues and port scanning. Nmap works by sending data packets on a specific target (by IP) and the incoming packets will be interpreted to determine what ports are open/closed, what services are running on the scanned system, whether firewalls or filters are set up and enabled, and finally what operating system is running. On this tutorial, we will learn how to install and use nmap command line on Linux environment (Ubuntu 20.04 LTS operating system).

namp Installation on Linux (Ubuntu 20.04)

Nmap can be installed on all major operating systems. It was initially released as a Linux-only tool, and later it was ported to other systems such as BSD, Windows, and macOS. The nmap installation will be as follow :

1. Update Ubuntu System

By updating our system, it will refresh the local list of available packages software to the newer stable version. To update Ubuntu 20.04 system repositories, we will use the command line: sudo apt-get update.

ramans@otodiginet:~$ sudo apt-get update
[sudo] password for ramans: 
Hit:1 http://mirror.telkomuniversity.ac.id/ubuntu focal InRelease
Get:3 http://mirror.telkomuniversity.ac.id/ubuntu focal-updates InRelease [114 kB]                                    
Get:4 https://download.docker.com/linux/ubuntu focal InRelease [57.7 kB]                                              
Get:5 https://dl.yarnpkg.com/debian stable InRelease [17.1 kB]                                                        
Get:6 https://packages.microsoft.com/ubuntu/20.04/mssql-server-2019 focal InRelease [10.4 kB]                         
Get:7 https://packages.microsoft.com/ubuntu/20.04/prod focal InRelease [10.5 kB]                                      
Get:8 http://mirror.telkomuniversity.ac.id/ubuntu focal-backports InRelease [101 kB]    

2. Installing nmap utility

Install nmap utility command line by typing command line : sudo apt-get install nmap.

ramans@otodiginet:~$ sudo apt-get 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 297 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

After installation is completed done, then we will verify its version by typing command line : nmap --version.

ramans@otodiginet:~$ 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

Using nmap Command Line

The most basic use of nmap is to scan a single target (IP Address) without specifying any options amd produce information about the given host. The nmap usage:

nmap [option] [ip_target ...]

In this section, we will try to explain the use of nmap including some examples.

1. nmap Basic Command for Port Scanning

Without any options, nmap reveals open services and open ports on the given target (IP Address or hostname). Nmap also can be used to scan multiple target.

ramans@otodiginet:~$ nmap otodiginet.com
Starting Nmap 7.80 ( https://nmap.org ) at 2021-10-17 19:19 PDT
Nmap scan report for otodiginet.com (127.0.1.1)
Host is up (0.00011s latency).
rDNS record for 127.0.1.1: otodiginet
Not shown: 998 closed ports
PORT     STATE SERVICE
80/tcp   open  http
1433/tcp open  ms-sql-s

Using nmap for scanning multiple host/target, as shown below.

ramansah@app01:~$ nmap otodiginet.com google.com
Starting Nmap 7.80 ( https://nmap.org ) at 2021-10-22 03:09 PDT
Nmap scan report for otodiginet.com (107.167.92.221)
Host is up (0.049s latency).

PORT      STATE    SERVICE
1/tcp     open     tcpmux
3/tcp     open     compressnet
4/tcp     open     unknown
6/tcp     open     unknown
7/tcp     open     echo
9/tcp     open     discard
...
64623/tcp open  unknown
64680/tcp open  unknown
65000/tcp open  unknown
65129/tcp open  unknown
65389/tcp open  unknown

Nmap done: 2 IP addresses (2 hosts up) scanned in 17.08 second

2. nmap For Retrieving target’s OS information

By add the -O option on our nmap command, we can discover the operating system information of the hosts that are targeted. The -A flag can be used in combination with other Nmap commands. nmap -O [target].

ramansah@otodiginet:~$ sudo nmap -O 192.168.19.137
[sudo] password for ramansah: 
Starting Nmap 7.80 ( https://nmap.org ) at 2021-10-24 19:16 PDT
Nmap scan report for 192.168.19.137
Host is up (0.00071s latency).
All 1000 scanned ports on 192.168.19.137 are closed
MAC Address: 00:0C:29:50:20:E0 (VMware)
Too many fingerprints match this host to give specific OS details
Network Distance: 1 hop

OS detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 14.82 seconds

3. nmap for Detecting Firewall

By using -sA option, we could detect the firewall settings across the given hosts. Whether a firewall is active on the host or noet. This uses an ACK scan to receive the information. It is useful for troubleshooting or scanning for vulnerabilities.

ramansah@otodiginet:~$ sudo nmap -sA 192.168.19.137
Starting Nmap 7.80 ( https://nmap.org ) at 2021-10-24 19:18 PDT
Nmap scan report for 192.168.19.137
Host is up (0.000095s latency).
All 1000 scanned ports on 192.168.19.137 are unfiltered
MAC Address: 00:0C:29:50:20:E0 (VMware)

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

4. For Retrieving Target’s Service Information

By using-sV option, we will kown the information regarding the services across the given host. The command line syntax is : nmap -sV [target].

ramansah@otodiginet:~$ sudo nmap -sV 192.168.19.137
Starting Nmap 7.80 ( https://nmap.org ) at 2021-10-24 19:18 PDT
Nmap scan report for 192.168.19.137
Host is up (0.00019s latency).
All 1000 scanned ports on 192.168.19.137 are closed
MAC Address: 00:0C:29:50:20:E0 (VMware)

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 13.54 seconds

5. namp For Scanning Specified port

nmap basic utilities is for Port scanning .is one of the basic utilities that Nmap offers and consequently, there are a few ways that this command can be customized. The command line syntax is : nmap -p <port_a>,<port_a> … [target].

amansah@otodiginet:~$ sudo nmap -p 443,80 192.168.19.137
Starting Nmap 7.80 ( https://nmap.org ) at 2021-10-24 20:23 PDT
Nmap scan report for 192.168.19.137
Host is up (0.00043s latency).

PORT    STATE  SERVICE
80/tcp  closed http
443/tcp closed https
MAC Address: 00:0C:29:50:20:E0 (VMware)

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

6. nmap for Identiying Host

By adding -sL option, we perform a host discovery through Nmap. The command line syntax is : nmap -SL [target].

ramansah@otodiginet:~$ sudo nmap -sL 192.168.19.137
Starting Nmap 7.80 ( https://nmap.org ) at 2021-10-24 19:23 PDT
Nmap scan report for 192.168.19.137
Nmap done: 1 IP address (0 hosts up) scanned in 13.00 seconds

7. nmap with Verbos Scanning

By using -v option we will got the scanning report in Verbos, node.

ramansah@otodiginet:~$ sudo nmap -v 192.168.19.137
Starting Nmap 7.80 ( https://nmap.org ) at 2021-10-24 19:23 PDT
Initiating ARP Ping Scan at 19:23
Scanning 192.168.19.137 [1 port]
Completed ARP Ping Scan at 19:23, 0.03s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 19:23
Completed Parallel DNS resolution of 1 host. at 19:24, 13.01s elapsed
Initiating SYN Stealth Scan at 19:24
Scanning 192.168.19.137 [1000 ports]
Completed SYN Stealth Scan at 19:24, 0.08s elapsed (1000 total ports)
Nmap scan report for 192.168.19.137
Host is up (0.00033s latency).
All 1000 scanned ports on 192.168.19.137 are closed
MAC Address: 00:0C:29:50:20:E0 (VMware)

Conclusion

On this article we have shown you how to install nmap command line on Ubuntu 20.04 LTS operating system, and we have took several example in executing nmap command line.

Share this article via :

Leave a Reply

Your email address will not be published. Required fields are marked *