Kali Linux
About Lesson

What is NMAP

Network Mapped (Nmap) is a network scanning and host detection tool that is very useful during several steps of penetration testing. Nmap is not limited to merely gathering information and enumeration, but it is also powerful utility that can be used as a vulnerability detector or a security scanner. So Nmap is a multipurpose tool, and it can be run on many different operating systems including Windows, Linux, BSD, and Mac. Nmap is a very powerful utility that can be used to:

  • Detect the live host on the network (host discovery)
  • Detect the open ports on the host (port discovery or enumeration)
  • The software and the version to the respective port (service discovery)
  • Detect the operating system, hardware address, and the software version
  • Detect the vulnerability and security holes (Nmap scripts)

How NMAP Works

Nmap is a very common tool, and it is available for both the command line interface and the graphical user interface. The objective of this article is to create a handbook that contains all of the necessary information about Nmap and its usage. To provide an overview of the article, in this piece

How to use Nmap? You might have heard this question many times before, but in my opinion, this is not the right question to ask. The best way to start off exploring Nmap is to ask: How can I use Nmap effectively? This article was written in an effort to answer that question.

Nmap uses different techniques to perform scanning including: TCP connect() scanning, TCP reverse ident scanning, FTP bounce scanning and so on. All these types of scanning have their own advantages and disadvantages, and we will discuss them as we go on.

How to Use Nmap Effectively

The usage of Nmap depends on the target machine because there is a difference between simple (basic) scanning and advance scanning. We need to use some advanced techniques to bypass the firewall and intrusion detection/preventative software to get the right result. Below are the examples of some basic commands and their usage:

If you want to scan a single system, then you can use a simple command

# nmap target 
# nmap target.com
# nmap 

If you want to scan the entire subnet, then the command is

# nmap target/cdir
# nmap 

It is very easy to scan a multiple targets, all you need to do is to separate each target via space:

# nmap target target1 target2
# nmap 

Let’s suppose you want to scan a range of IP addresses, but not the entire subnet. In this scenario, use this command:

# nmap target-100
# nmap 

Let suppose you have a list of a target machines. You can make Nmap scan for the entire list:

# nmap -iL target.txt         Make sure to put the file on the same directory

If you want to see the list of all the hosts that you are scanning, then use the command with an -sL parameter:

# nmap -sL target/cdir
# nmap -sL 

In some cases we need to scan the entire subnet but not a specific IP addresses because it might be dangerous for us. In this scenario, use the Nmap command with the excluding parameter:

# nmap – -exclude

If you have a file that contains the list of IP addresses that you want to exclude, then you can call the file in the exclude parameter:

# nmap –exclude file target.txt

If you want to scan a specific port on the target machines (for example, if you want to scan the HTTP, FTP, and Telnet port only on the target computer), then you can use the Nmap command with the relevant parameter:

# nmap -p80,21,23 It scan the target for port number 80,21 and 23.

You now have a basic understanding of Nmap scanning techniques, but for the purposes of this article, we need to explore more in depth.

Nmap Scanning Techniques

There are so many scanning techniques available on Nmap, including the TCP connect scanning method discussed earlier, so in this section, I will discuss the most popular scanning technique in detail.

TCP SYN Scan (-sS)

It is a basic scan, and it is also called half-open scanning because this technique allows Nmap to get information from the remote host without the complete TCP handshake process, Nmap sends SYN packets to the destination, but it does not create any sessions, As a result, the target computer can’t create any log of the interaction because no session was initiated, making this feature an advantage of the TCP SYN scan.

If there is no scan type mentioned on the command, then avTCP SYN scan is used by default, but it requires the root/administrator privileged.

 # nmap -sS 

TCP connect() scan (-sT)

This the default scanning technique used, if and only if the SYN scan is not an option, because the SYN scan requires root privilege. Unlike the TCP SYN scan, it completes the normal TCP three way handshake process and requires the system to call connect(), which is a part of the operating system. Keep in mind that this technique is only applicable to find out the TCP ports, not the UDP ports.

 # nmap -sT

UDP Scan (-sU)

As the name suggests, this technique is used to find an open UDP port of the target machine. It does not require any SYN packet to be sent because it is targeting the UDP ports. But we can make the scanning more effective by using -sS along with –sU. UDP scans send the UDP packets to the target machine, and waits for a response—if an error message arrives saying the ICMP is unreachable, then it means that the port is closed; but if it gets an appropriate response, then it means that the port is open.

 # nmap -sU

FIN Scan (-sF)

Sometimes a normal TCP SYN scan is not the best solution because of the firewall. IDS and IPS scans might be deployed on the target machine, but a firewall will usually block the SYN packets. A FIN scan sends the packet only set with a FIN flag, so it is not required to complete the TCP handshaking.

root@bt:~# nmap -sF
Starting Nmap 5.51 ( http://nmap.org ) at 2012-07-08 19:21 PKT
Nmap scan report for
Host is up (0.000026s latency).
Not shown: 999 closed ports
111/tcp open|filtered rpcbind

The target computer is not able to create a log of this scan (again, an advantage of FIN). Just like a FIN scan, we can perform an xmas scan (-sX) and Null scan (-sN). The idea is same but there is a difference between each type of scan. For example, the FIN scan sends the packets containing only the FIN flag, where as the Null scan does not send any bit on the packet, and the xmas sends FIN, PSH, and URG flags.

Ping Scan [-sP]

Ping scanning is unlike the other scan techniques because it is only used to find out whether the host is alive or not, it is not used to discover open ports. PS require root access s ICMP packets can be sent, but if the user does not have administrator privilege, then the ping scan uses connect() call.

# nmap -sP

Version Detection (-sV)

Version detection is the right technique that is used to find out what software version is running on the target computer and on the respective ports. It is unlike the other scanning techniques because it is not used to detect the open ports, but it requires the information from open ports to detect the software version. In the first step of this scan technique, version detection uses the TCP SYN scan to find out which ports are open.

# nmap -sV

Idle Scan (-sI)

Idle scan is one of my favorite techniques, and it is an advance scan that provides complete anonymity while scanning. In idle scan, Nmap doesn’t send the packets from your real IP address—instead of generating the packets from the attacker machine, Nmap uses another host from the target network to send the packets. Let’s consider an example to understand the concept of idle scan:

# nmap -sI zombie_host target_host
# nmap -sI 

The idle scan technique (as mentioned above) is used to discover the open ports on while it uses the zombie_host ( to communicate with the target host. So this is an ideal technique to scan a target computer anonymously.

There are many other scanning techniques are available like FTP bounce, fragmentation scan, IP protocol scan. and so on; but we have discussed the most important scanning techniques (although all of the scanning techniques can important depending on the situation you are dealing with).

In the next section of this article, I will discuss Nmap’s operating system (OS) detection and discovery techniques.

OS Detection Nmap

One of the most important feature that Nmap has is the ability to detect remote operating systems and software. It is very helpful during a penetration test to know about the operating system and the software used by the remote computer because you can easily predict the known vulnerabilities from this information.

Nmap has a database called nmap-os-db, the database contains information of more than 2,600 operating systems. Nmap sends TCP and UDP packets to the target machine and then it examines the response by comparing the result with the database. The Nmap operating system discovery technique is slightly slower then the scanning techniques because OS detection involves the process of finding open ports.

Initiating SYN Stealth Scan at 10:21
Scanning localhost ( [1000 ports]
Discovered open port 111/tcp on
Completed SYN Stealth Scan at 10:21, 0.08s elapsed (1000 total ports)
Initiating OS detection (try #1) against localhost (
Retrying OS detection (try #2) against localhost (

The example above clearly demonstrates that the Nmap first discovers the open ports, then it sends the packets to discover the remote operating system. The OS detection parameter is -O (capital O).

Nmap OS fingerprinting technique discovers the:

  • Device type (router, work station, and so on)
  • Running (running operating system)
  • OS details (the name and the version of OS)
  • Network distance (the distance in hops between the target and attacker)

Suppose that the target machine has a firewall, IDS, and IPS all enabled. You can use the command -PN to ensure that you do not ping to find the remote operating system. The -PN tells Nmap not to ping the remote computer, since sometimes firewalls block the request.

# nmap -O -PN

The command informs the sender every host on the network is alive so there is no need to send a ping request as well. In short, it bypasses the ping request and goes on to discover the operating system.

The Nmap OS detection technique works on the basis of an open and closed port. If Nmap fails to discover the open and closed port, then it gives the error:

Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port

This is an undesirable situation, and it is good to limit the operating system scans if Nmap is not sure about the OS. If Nmap is not sure about the OS, then there is no need to detect by using –osscan_limit.

On the off chance that it is extremely hard for Nmap to distinguish the remote OS precisely, you have the alternative of utilizing Nmap’s theory highlight:, – osscan-surmise finds the closest match of the objective working framework.

# nmap -O --osscan-guess



Nmap is an extremely useful asset and it has capacity to cover the absolute first parts of entrance testing, which incorporate data social affair and specification. This article was written in an effort to discuss Nmap from the beginner level to the advanced level. There are so many other things that you can do with the Nmap, and we will discuss them in the future articles.

Hope this article helpful for you. Thank You

If You Appreciate What We Do Here On Hackonology, You Should Consider:

Hackonology is the fastest growing and most trusted community site where you can find lots of courses, articles about Technology/Hacking/Cracking. Millions of people visit Hackonology! to search or browse the thousands of published articles available FREELY to all.

Let's be a part of Hacker's Community! Join our Hacking Team

We Are Indian We Are Great