HomeBlogSecurityWhat is Nmap (Network Mapper) & How Does It Work?

What is Nmap (Network Mapper) & How Does It Work?

Published
05th Sep, 2023
Views
view count loader
Read it in
14 Mins
In this article
    What is Nmap (Network Mapper) & How Does It Work?

    In this digital environment, networks are critical in smooth communication, data exchange, and various online services. Organizations increasingly rely on interconnected networks and digital communication. With the growing complexity and sophistication of cyber threats, ensuring strong network security is essential to protect sensitive data, maintain business continuity, and protection against unauthorized access. Organizations and Individuals maintain Network Security is at its potential. So, to effectively secure a network, Nmap (Network Mapper) comes into play.

    What is Nmap?

    Nmap (Network Mapper) is a 25-year-old indispensable open-source command line tool designed to provide valuable insights into network architecture, open ports, potential vulnerabilities and auditing networks all-inclusively. The objective of this tool is to assist network administrators, security professionals, and ethical hackers in understanding and securing their networks. Nmap is using raw IP packets in unique way to determine what hosts are available on the network, and what kind of services and versions are active on those hosts, what operating systems they are running and a lot of other things.Nmap is available for various platforms, including Windows, macOS, and Linux, making it accessible to a wide range of users.To learn about Network Security, earn the IT Security training certification and see yourself recruited by the top companies.

    History of Nmap Tool

    Nmap is a powerful and widely used open-source network scanning tool. The C++ programming language was initially used to construct the tool. It was first developed by Gordon Lyon, commonly known by his pseudonym Fyodor, in the late 1990s and has been the primary developer and maintainer of the tool since then. Released in September 1997, He released the tool through Phrack Magazine under the pseudonym Fyodor Vaskovitch. Although everyone knows Lyon, he still uses the Fyodor name to identify his work within the Nmap community.

    How to Use Nmap Effectively?

    Given the significant reliance on Cyber Security, it is imperative for both businesses and individuals to adhere to precautionary measures by enrolling in the best Ethical Hacking course available. And it's important to note that Nmap should be used responsibly and within the legal and ethical boundaries of authorization and consent from the network owners in Cyber Security. Ignoring this can be illegal and may violate applicable laws and regulations. These applications highlight Nmap's versatility and value in network security, system administration and ethical hacking.

    1. Network Discovery

    Nmap can be used to discover all the hosts on a network. This is useful for network administrators to identify active hosts, verify network configurations, and ensure proper network segmentation.

    2. Port Scanning

    Nmap's port scanning capabilities allow users to scan for open ports on target hosts. This is crucial for identifying potential entry points for attackers, verifying firewall configurations, and ensuring only necessary services are exposed.

    3. Version and OS Detection

    Nmap can detect the services running on open ports and provide information about their versions. It also has the ability to determine the operating system (OS) of a remote host. This helps in understanding the software stack of target systems, identifying vulnerable services, and assessing potential security risks.

    4. Vulnerability Assessment

    Nmap can be used as a tool for initial vulnerability assessment. By combining its port scanning, service detection, and OS identification features, it helps identify potential security vulnerabilities and provides a foundation for further vulnerability scanning.

    5. Penetration Testing

    Nmap is widely used in penetration testing to assess the security of networks. By combining its scanning capabilities with custom scripts, Nmap can perform comprehensive scurity assessments, identify potential attack vectors, and help in testing the effectiveness of security controls.

    What Can You Do With Nmap?

    Mentioned features collectively make Nmap a versatile and dynamic tool for penetration testing and ethical hacking. Using Nmap enables users to gain deep insights into network infrastructure and enhance overall network security. Let us explore what all we can do with the Nmap in Cyber Security.

    1. Host Discovery

    Nmap is best at identifying live hosts on a network. It is among the very first steps in any network reconnaissance strategy. It uses a variety of techniques, such as ICMP (Internet Control Message Protocol) pings, TCP/IP (Transmission Control Protocol/Internet Protocol) stack fingerprinting, and ARP (Address Resolution Protocol) requests, to determine whether a host is active and online.Once the online hosts are determined, Nmap will proceed with the port scanning phase against those hosts.

    2. Port Scanning

    On target remote computers, Nmap can scan open ports. Numerous scan types, such as TCP SYN scan, TCP connect scan, UDP scan, and others are supported. Attackers can use this information to analyze network security and locate weak end points.

    3. Target specification

    The target specification refers to the way you define the hosts or networks you want to scan. These are some common ways to specify targets in Nmap:

    • Single IP address: You can specify a single IP address as the target.
    • Hostname: Instead of an IP address, you can use a hostname as the target. Nmap will resolve the hostname to its corresponding IP address and scan that.
    • IP range: You can define a range of IP addresses using the CIDR notation or by specifying a starting and ending IP address.
    • Subnet: You can specify an entire subnet using the network address and netmask.
    • Multiple targets: You can specify multiple targets by separating them with spaces.

    4. Discovering Service and Version

    Nmap can identify the services running on open ports and their related versions of the target system or network. By analyzing the map of information returned by a service, NMAP can provide insights into potential vulnerabilities associated with specific software versions. Nmap will show that those ports probably correspond to a web server (HTTP), mail server (SMTP), and name server (DNS) respectively. Nmap looks for information such as the service protocol, the application name, the hostname, the version number, the type of device, and the OS family.

    5. Operating System Detection

    Nmap's OS using TCP/IP stack fingerprinting detection feature allows it to discover the underlying operating system of a remote host. A freeform textual description of the OS is included in each fingerprint, along with a classification that lists the vendor (e.g., Sam), the operating system (e.g., Solaris), the OS generation (e.g., 10), and the type of device (e.g., router, switch, gaming console, etc.). If circumstances are favorable (e.g., at least one open and one closed port was found) and Nmap is unable to specify the OS of a machine, Nmap will provide a URL that can be used to submit the fingerprint if the OS running on the device is known.

    6. NSE (Nmap Scripting Engine)

    Nmap supports scripting capabilities through its NSE (Nmap Scripting Engine). It is one of Nmap's most powerful and flexible features.This feature allows users to write custom scripts to automate scanning tasks, perform advanced vulnerability checks, or gather additional information about hosts.

    7. Output and Reporting

    Nmap provides flexible output options, allowing users to generate reports in various formats, including text, XML(Extensible Markup Language) , and HTML (Hyper Text Markup Language). These reports contain detailed information about discovered hosts, open ports, detected services, and operating systems, facilitating analysis and further action.

    Examples of Nmap (The Network Mapper)

    Here are some of the Nmap usage examples, Some real IP addresses and domain names are used to make things more realistic. Remember to replace `<target IP>` with the actual IP address or hostname of the target system you want to scan. Below are some examples of Nmap commands for different scanning scenarios.

    1. TCP Port Scan

    root@kali:~#nmap -p 1-100 -sT 192.168.1.25

    This command will perform a TCP port scan on ports 1 to 100 of the target IP address.

    Explanation of the command:

    • Nmap : The command to initiate the Nmap scanning.
    • -sT : Specifies TCP port scan.
    • -p : Specifies ports range
    • <target> :Specifies the target system or IP address you want to scan.

    2. UDP Port Scan

    root@kali:~#- nmap -p 1-100 -sU 192.168.1.25

    This command will perform a UDP port scan on ports 1 to 100 of the target IP address.

    Explanation of the command:

    • Nmap : The command to initiate the Nmap scanning.
    • -sU  : Specifies UDP port scan.
    • -p : Specifies ports range
    • <target> :Specifies the target system or IP address you want to scan.

    3. Operating System Detection

    root@kali:~#nmap -O 192.168.1.2

    This command will perform a scan with operating system detection helps to help identify the operating system of the target.

    Explanation of the command:

    • Nmap : The command to initiate the Nmap scanning.
    • -O : Specifies OS of the target
    • <target> :Specifies the target system or IP address you want to scan.

    4. Service Version Detection

    root@kali:~#nmap -sV 192.168.1.25

    This command will perform a port scan with service version detection enabled to identify the services running on open ports.

    Explanation of the command:

    • Nmap : The command to initiate the Nmap scanning.
    • -sV : Specifies service version of the target
    • <target> : Specifies the target system or IP address you want to scan.

    5. port scan with service version detection

    root@kali:~#nmap -sV -p 22,53,110,143,4564 198.116.0-255.1-127

    The IP range provided is 198.116.0.1 to 198.116.255.127, indicating that Nmap will scan hosts within that range and detect the version information of services running on port 4564 or the typical ports for SSH (22), DNS (53), POP3 (110), and IMAP (143). Version detection is used to identify the application that is executing for any of these ports that are discovered to be open.

    Explanation of the command:

    • Nmap : The command to initiate the Nmap scanning.
    • -sV : Specifies service version scan.
    • -p : Specifies port(s) range
    • <target> :Specifies the target system or IP address you want to scan.

    How Nmap Works in Cyber Security?

    Network scanning is a three-step process, with Nmap taking care of the first two steps and leaving the third step to ethical hackers or pen-testers. Therefore, we will discuss these phases in order. The steps typically required when using Nmap for cybersecurity purposes are:

    Step 1 : Scan For Open Ports

    Choose the target system or network that you want to scan. It can be specified using an IP address, hostname, or IP range. Determine the scan techniques and options you want to use based on your objectives. This includes selecting the type of scan, specifying the ports to scan, and configuring other options like timing and output format. Run the Nmap command with the chosen scan technique and options. Nmap employs cutting-edge techniques to analyze raw IP packets in order to identify the hosts that are reachable on the network, the services they provide, the working frameworks they are running, the types of packet filters and firewalls that are in place, and many other characteristics.

    For Example, Let's say we want to scan the IP address range from 10.10.232.201. We will use a TCP SYN scan (-sS) to scan the target IP range, and we want verbose scan (-v) without host discovery (-Pn).

    root@kali:~# nmap -Ss -v -Pn 10.10.232.201

    Step 2 : Create Map of the Network

    You can identify a variety of system characteristics thanks to the IP addresses and a wealth of additional information that Nmap's packets provide. It collects a wealth of information that can be used to identify various system traits and create a profile or map of the network. Nmap performs,

    • Host discovery: To determine which hosts are online and reachable on the specified target network. It sends various probes, such as ICMP, ARP, or TCP SYN, to identify active hosts.
    • Port scanning: For each discovered host, Nmap performs port scanning to determine which ports are open, closed, or filtered. It sends packets to target ports and analyzes the responses to identify the port status.
    • Service and OS detection: Nmap can also perform service and OS detection to gather information about the services running on the open ports and the operating system running on the target system.

    Step 3 : Analyze Output

    The ethical hackers must use open ports and Vulnerable services of the target network/system/ Host after they obtain some information from the target's side. Gaining access to the victim machine is the third stage of ethical hacking that comes after this one. Nmap provides a detailed report of the scan results, including open ports, detected services, and potentially identified operating systems. The output can be in various formats, such as interactive console output, XML, or text files.

    Understanding Common NMAP Commands in Cyber Security

    Let’s get to know some useful command-line-based scans that can be performed using Nmap on Linux Distribution. The Linux distributions virtually all come with Nmap pre-installed. You must manually install it if it is missing. With the following command, it is simply installed:

    1. Nmap Installation on linux

    Ex: root@kali:~# apt-get install nmap

    OR

    Git Repository

    Ex: root@kali:~# git clone https://github.com/nmap/nmap.git

    2. Nmap Installation On Windows

    Once you download the installer, execute it and install it. The automated installer should take care of configuring Nmap for you in mere seconds.

    Once Nmap is installed, In cmd, run the Nmap installer with the /S option to perform a silent installation without displaying the GUI:

    Ex: nmap-<version>.exe /S

    Verify the installation:

    • Open a new command prompt window. Type "nmap" and press Enter.
    • If Nmap is installed correctly, you should see the Nmap help message and a list of available options.

    3. Nmap Installation On MacOS

    Mac users also have a full automated installer. Just run the Nmap-mpkg file to begin the installation. After a few seconds, Nmap will be ready on your MacOS.

    OR

    To install Nmap on macOS, you can use the Homebrew package manager. Here's the installation process on shell:

    • /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    • After Homebrew is successfully installed, you can install Nmap by running the following command in the terminal: 
    • brew install nmap
    • Once the installation is finished, you can verify that Nmap is installed correctly by running the command:

    nmap --version

    4. To Start Nmap

    Type “nmap” in the terminal and it’ll display the help menu with all possible options and usage information.

    Ex: root@kali:~# nmap

    5. Scan a IP Address

    Ex: root@kali:~# nmap 10.10.10.24

    6. Scan a Hostname

    Ex: root@kali:~# nmap example.com

    7. Perform a Ping Scan

    Ex: root@kali:~# nmap -sp 10.10.10.24

    8. Perform a Aggressive Scan

    Nmap has a special flag “-A” which activates an aggressive detection. Aggressive mode enables:

    OS detection option -O , Version detection option -sV , Script scanning option -sC , Traceroute option --traceroute

    Ex: root@kali:~# nmap -A 10.10.10.24

    9. Save Scan Results To a File

    Ex: root@kali:~# nmap -oN output.txt 10.10.10.24

    10. CVE Detection Using NSE (Nmap Script Engine)

    Ex: root@kali:~# nmap 10.10.10.24 -max-parallelism 800 -Pn --script http-slowloris --script-args http-slowloris.runforever=true

    Nmap has dozens of command-line flags available to make the system more powerful and flexible.

    Alternatives To NMAP

    Nmap is a popular and adaptable network scanning programme, but there are a number of rivals that provide comparable capabilities. Here are several well-known substitutions for Nmap:

    1. Masscan

    Masscan is a port scanning tool that is incredibly quick and effective. It can quickly scan the full IPv4 address space because it is made for high-speed scanning of big networks. Since Masscan is noted for its speed and scalability, it is appropriate for situations that call for quick network scanning.

    2. Zenmap

    A graphical user interface (GUI) for Nmap is Zenmap. It offers a simple user interface for viewing and interacting with Nmap's scanning findings. With a clear and simple user interface, Zenmap includes a number of capabilities like host discovery, port scanning, and service/version identification.

    3. OpenVAS

    An extensive vulnerability scanning and management system, OpenVAS (Open Vulnerability Assessment System) is. A potent scanning engine is included within it that can examine network vulnerabilities, including port scanning, service detection, and vulnerability identification. A web-based interface for managing and analyzing scan results is also offered by OpenVAS.

    4. Nessus

    A well-known vulnerability scanning tool, Nessus has a number of features, such as network scanning, vulnerability identification, and compliance monitoring. It is compatible with a number of scanning methods, including port scanning, service discovery, and vulnerability analysis. Nessus offers sophisticated options for managing and fixing vulnerabilities in addition to informative reports.

    5. ZMap

     ZMap is a fast open source network scanner primarily focused on scanning the entire Internet. It is designed to quickly and efficiently scan the entire IPv4 address space. ZMap is often used for large-scale surveys and data collection to provide insight into the global state of Internet security.

    Conclusion

    Nmap has established itself as a powerful and robust network scanning tool, offering indispensable insights into network architecture, open ports, and potential vulnerabilities. Its extensive feature set, combined with its flexibility and ease of use, makes it a valuable asset for network administrators and security professionals.

    By leveraging NMAP's capabilities and adhering to best practices, organizations can proactively identify and mitigate security risks, ensuring the protection of their networks from potential cyber threats. Enhancing your expertise in utilizing NMAP can be achieved through KnowledgeHut Cyber Security courses, providing comprehensive training to optimize the utilization of this invaluable tool.

    Frequently Asked Questions (FAQs)

    1Is Nmap difficult to learn and use?

    Nmap can be initially overwhelming for beginners due to its extensive range of features and options. However, with proper guidance and practice, it is not overly difficult to learn and use. To get started with Nmap, it is recommended to begin with the basics such as understanding the different scanning techniques, specifying target hosts or IP ranges, and interpreting the scan results.

    2Which platforms does Nmap support?

    Nmap is available for various platforms, including Windows, macOS, and Linux, making it accessible to a wide range of users. Alongside, Nmap also have the support of less popular or older operating systems like Solaris, AIX or AmigaOS. There are C, C++, Perl, Python, and Perl source code files also available.

    3Can Nmap be used for detecting and preventing network attacks?

    Nmap is a powerful tool used for both legitimate network exploration and preventing network attacks. Nmap can be used to periodically scan and monitor critical systems and services. By setting up automated scans and monitoring the results, you can receive alerts or notifications when unexpected changes or anomalies are detected, enabling you to respond quickly to potential vulnerabilities.

    4Can Nmap be used for web application scanning?

    While Nmap can provide some initial insights into web application security like detecting open ports, service version,etc. it is important to note that it is not a dedicated web application security scanner.

    Profile

    Shubham Gautam

    Blog Author

    Shubham has an experience of 6+ years in the field of cyber security and has trained more than 15,000+ students as cyber-security professionals during the last six years. He has designed course structures for cyber security for the Indian Institute of Technology (IIT), Purdue University US & the International Institute of Information Technology Bangalore (IIIT-B) and is the lead mentor for the same. Shubham is also a steering committee member of the National Information Security Council (NISC), India, and a Jury Member and scientific member at the International Association of Scientists and Researchers (IASR). He has been featured on various media platforms like ZEE News, ABP News, NewsNation, and Mirror Now - Times Now.

    Share This Article
    Ready to Master the Skills that Drive Your Career?

    Avail your free 1:1 mentorship session.

    Select
    Your Message (Optional)

    Upcoming Cyber Security Batches & Dates

    NameDateFeeKnow more
    Course advisor icon
    Course Advisor
    Whatsapp/Chat icon