NMAP Commands Cheat Sheet & Tutorial with Examples (Download PDF) (2024)

Written By Harris Andrea

NMAP (Network Mapper) is the de facto open source network scanner used by almost all security professionals to enumerate open ports and find live hosts in a network (and much more really).

NMAP Commands Cheat Sheet & Tutorial with Examples (Download PDF) (1)

One of my responsibilities in my job is to perform white hat penetration testing and security assessments in corporate systems to evaluate their security level.

In almost all engagements, I start first with using Nmap in order to enumerate live hosts, find what services are running on servers, what types and versions of applications and operating systems are installed etc.

This article is divided in two parts. The first part is a cheat sheet of the most important and popular Nmap commands which you can download also as a PDF file at the end of this post.

The second part is an Nmap Tutorial where I will show you several techniques, use cases and examples of using this tool in security assessment engagements.

NOTE: All information in this article is for educational purposes only. You must use Nmap only to scan systems that you have permission and for ethical reasons only (e.g in order to evaluate and enhance their security level).

Table of Contents

NMAP Cheat Sheet

So without further ado let’s start first with the most useful and important commands and switches used with NMAP. You can download the following cheat sheet in PDF format at the end of this article.

Scan IP address (Targets)

nmap a single host IP
nmap a Class C subnet range
nmap the range of IPs between up to
nmap -iL hosts.txtScan the IP addresses listed in text file “hosts.txt”
nmap the 3 specified IPs only
nmap www.somedomain.comFirst resolve the IP of the domain and then scan its IP address


Because we have not specified any other switches on the commands above (except the target IP address), the command will perform first host discovery by default and then scan the most common 1000 TCP ports by default.

Port Related Commands

On the section above we have not specified any ports which means the tool will scan the 1000 most common ports. However, in real engagements you should specify port numbers as well as shown below.

nmap -p80 only port 80 for specified host
nmap -p20-23 ports 20 up to 23 for specified host
nmap -p80,88,8000 ports 80,88,8000 only
nmap -p- ALL ports for specified host
nmap -sS -sU -p U:53,T:22 ports UDP 53 and TCP 22
nmap -p http,ssh http and ssh ports for specified host

Different Scan Types

Nmap is able to use various different techniques to identify live hosts, open ports etc. The following are the most popular scan types.

nmap -sS SYN Scan (best option)
nmap -sT TCP connect scan
nmap -sU UDP ports
nmap -sP a Ping scan only
nmap -Pn’t ping the hosts, assume they are up.

There are some more scan types supported by nmap but we have listed the most useful ones above. Here is an overview of the most popular scan types:

  • -sS: This sends only a TCP SYN packet and waits for a TCP ACK. If it receives an ACK on the specific probed port, it means the port exist on the machine. This is fast and pretty accurate.
  • -sT: This creates a full TCP connection with the host (full TCP handshake). This is considered more accurate than SYN scan but slower and noisier.
  • -sP: This is for fast checking which hosts reply to ICMP ping packets (useful if you are on the same subnet as the scanned range and want a fast result about how many live hosts are connected).

Identify Versions of Services and Operating Systems

Another important feature of NMAP is to give you a wealth of information about what versions of services and Operating Systems are running on the remote hosts.

MORE READING: How to Scan an IP Network Range with NMAP (and Zenmap)
nmap -sV detection scan of open ports (services)
nmap -O Operating System version
nmap -A combines OS detection, service version detection, script scanning and traceroute.

Scan Timings

These switches have to do with how fast or slow the scan will be performed.

nmap -T0 scan (to avoid IDS)
nmap -T1 (to avoid IDS)
nmap -T2 (10 times slower than T3)
nmap -T3 scan timer (normal)
nmap -T4 (fast and fairly accurate)
nmap -T5 Aggressive (might miss open ports)

Output Types

For each scan we recommend outputting the results in a file for further evaluation later on. Nmap supports 3 main output formats as below:

nmap -oN [filename] [IP hosts]Normal text format
nmap -oG [filename] [IP hosts]Grepable file (useful to search inside file)
nmap -oX [filename] [IP hosts]XML file
nmap -oA [filename] [IP hosts]Output in all 3 formats supported


nmap -oN scan.txt (this will scan the subnet and output the results in text file “scan.txt”)

Discover Live Hosts

There are various techniques that can be used to discover live hosts in a network with nmap. Depending on whether you are scanning from the same LAN subnet or outside of a firewall, different live host identifications can be used (we will discuss this later).

nmap -PS22-25,80 hosts by TCP SYN packets to specified ports (in our example here the ports are 22 to 25 and 80)
nmap -Pn port discovery. Treat all hosts as online.
nmap -PE ICMP Echo packets to discover hosts.
nmap -sn scan.

NSE Scripts

Did you know that nmap is not only a port scanner? Actually, there are hundreds of included scripts that you can use with nmap to scan for all sorts of vulnerabilities, brute force login to services, check for well-known weaknesses on services etc.

nmap --script="name of script"
Run the specified script towards the targets.
nmap --script="name of script" --script-args="argument=arg"
Run the script with the specified arguments.
nmap --script-updatedb
Update script database

Other Useful Commands

Some other miscellaneous but useful commands:

nmap -6 [IP hosts]Scan IPv6 hosts
nmap --proxies url1,url2
Run the scan through proxies
nmap --open
Only show open ports
nmap --script-help="script name"
Get info and help for the specified script
nmap -VShow currently installed version
nmap -S [IP address]Spoof source IP
nmap --max-parallelism [number]
Maximum parallel probes/connections
nmap --max-rate [number]
Maximum packets per second

NMAP Tutorial and Examples

This is the second part of this article where I’ll show you some examples, use cases and techniques of using nmap in practical penetration testing and security assessment engagements.

#1 My personal favourite way of using Nmap

Whenever I start a penetration test, I follow the steps below with nmap.

Step 1a: Host Discovery with well knows ports

nmap -PS21-25,80,88,111,135,443,445,3306,3389,8000-8080 -T4 -oA hostdiscovery

The above will perform host discovery to identify live hosts using some well-known ports (21-25, 80, 443 etc). The output will be 3 files (gnmap, xml, txt) with filename “hostdiscovery”. We assume the target network range is

With the above technique, if at least one of the above TCP ports is open on a target host in the IP range then nmap will know that the host is alive.

The above technique is efficient if you are scanning a large public IP range and you know there is a firewall in front and that only limited ports are visible because of the firewall. The above ports will most probably be visible on public hosts.

Step 1b: Host Discovery with ICMP

nmap -PE -oA hostdiscovery

The above is a variation of previous step (Step 1a) whereby nmap sends ICMP packets to discover live hosts.

This technique is effective if you are scanning from the same LAN subnet as the target range and there is no firewall in front of the hosts and also ICMP ping is not blocked from the hosts.

The end result is the same as the previous step. Live hosts will be recorded in filename “hostdiscovery” with several ports marked as open for each IP address.

Step 2: Filter Above Files to Create a Clean Live Hosts Lists

The filename created above (“hostdiscovery”) will contain hosts with open ports. We can filter all IP addresses in the file above that have at least one open port and create a clean list of live host IPs.

MORE READING: How I Use NMAP in Penetration Testing Engagements

I use the linux “awk” command for this task as shown below:

# awk ‘/open/{print $2}’ hostdiscovery.gnmap > livehosts.txt

From Step 1 before, there are three files created and one of them is a greppable format file with extension gnmap (“hostdiscovery.gnmap”).

We run awk to search for open ports in that file and then redirect the output to another file “livehosts.txt”. This file will only contain a list of IP addresses that correspond to live hosts in the target network.

Step 3: Perform Full Port Scan using the Live Hosts List

Now after identifying the live hosts in the whole subnet, we can perform full port scan with nmap towards these hosts only.

By doing this, we managed to be more efficient and perform scans faster than doing full port scan on the whole target range from the beginning.

nmap -p- -Pn -sS -A -T4 -iL livehosts.txt -oA fullscan

-p- : This scans all ports

-Pn : Do not perform host discovery again

-sS : Perform TCP SYN scan

-A : This combines OS detection, service version detection, script scanning and traceroute

-T4 : Pretty fast and accurate scanning

-iL livehosts.txt : Scan the IPs contained in file “livehosts.txt”

-oA : Export the results in file “fullscan”

#2 Scan network for EternalBlue (MS17-010) Vulnerability

In 2017 a huge zero-day vulnerability in Windows SMB was leaked to the public with the name “EternalBlue” (reference code MS17-010 from Microsoft). This is a critical risk vulnerability that allows easy compromise of remote Windows machines.

You must scan your networks to find out if you have Windows machines that are not patched for this and the following nmap script is very useful for this task.

nmap -Pn -p445 --script=smb-vuln-ms17-010 -oN eternalblue-scan.txt

The command above will scan the whole Class C network on port 445 (SMB port) for the EternalBlue vulnerability and will write the results in file “eternalblue-scan.txt”

#3 Find HTTP servers and then run nikto against them

The following scans the target range ( for HTTP servers (ports 80 and 443) and then pipes the result to “Nikto” for further HTTP scans. Nikto is an open source tool for identifying well known HTTP vulnerabilities.

nmap -p80,443 -oG – | nikto.pl -h –

#4 Find Servers running Netbios (ports 137,139, 445)

nmap -sV -v -p 137,139,445

#5 Find Geo Location of a specific IP address

The following command uses geolocation script “ip-geolocation-ipinfodb” to find the geographic location of a specific IP address. To use the above script you need to create a free account at https://ipinfodb.com/register.php and get an API key to use in the command as shown below (in script-args).

nmap --script=ip-geolocation-ipinfodb --script-args=ip-geolocation-ipinfodb.apikey=[APIKEY]

Nmap scan report for google-public-dns-a.google.com (
Host is up (0.0097s latency).
Not shown: 998 filtered ports
53/tcp open domain
443/tcp open https
Host script results:

| ip-geolocation-ipinfodb:
| coordinates (lat,lon): 37.406,-122.079
|_ city: Mountain View, California, United States

#6 Detect if a Website is protected by WAF

A WAF (Web Application Firewall) can be a software or hardware device in front of webservers to protect from HTTP web application attacks.

The following command uses a script to detect if the target website is protected by a Web Application Firewall (WAF). The http-waf-detect script uses two arguments to try the tool’s built-in attack vectors for evaluating if the target web domain is protected by a WAF.

# nmap -p80,443 --script http-waf-detect --script-args="http-waf-detect.aggro,http-waf-detect.detectBodyChanges" www.networkstraining.com

Nmap scan report for www.networkstraining.com (
Host is up (0.011s latency).
80/tcp open http
443/tcp open https
| http-waf-detect: IDS/IPS/WAF detected:

#7 Find well known vulnerabilities related to an open port

Let’s say you have scanned a target host and found several open services/ports running on the host. With nmap you can query public vulnerability databases to find out if there are any known published vulnerabilities related to the services running.

Step 1:

First you need to download the “nmap-vulners” script from Git and place it under the script directory of nmap:

# cd /pentest/vulnerability-analysis/nmap/scripts (or whatever the scripts directory is)

# git clone https://github.com/vulnersCom/nmap-vulners.git

Step 2:

Since the script needs to know the exact version of the remote scanned service, you must use the -sV key when using the vulners script:

# nmap -Pn -sV -p80 --script=vulners scanme.nmap.org

80/tcp open http Apache httpd 2.4.7 ((Ubuntu))
|_http-server-header: Apache/2.4.7 (Ubuntu)
| vulners:
| cpe:/a:apache:http_server:2.4.7:
| CVE-2017-7679 7.5 https://vulners.com/cve/CVE-2017-7679
| CVE-2018-1312 6.8 https://vulners.com/cve/CVE-2018-1312
| CVE-2014-0226 6.8 https://vulners.com/cve/CVE-2014-0226
| CVE-2017-15715 6.8 https://vulners.com/cve/CVE-2017-15715
| CVE-2017-9788 6.4 https://vulners.com/cve/CVE-2017-9788
| CVE-2013-6438 5.0 https://vulners.com/cve/CVE-2013-6438
| CVE-2014-0231 5.0 https://vulners.com/cve/CVE-2014-0231
| CVE-2017-9798 5.0 https://vulners.com/cve/CVE-2017-9798
| CVE-2016-8743 5.0 https://vulners.com/cve/CVE-2016-8743
| CVE-2017-15710 5.0 https://vulners.com/cve/CVE-2017-15710
| CVE-2016-0736 5.0 https://vulners.com/cve/CVE-2016-0736
| CVE-2014-3523 5.0 https://vulners.com/cve/CVE-2014-3523
| CVE-2016-2161 5.0 https://vulners.com/cve/CVE-2016-2161
| CVE-2018-17199 5.0 https://vulners.com/cve/CVE-2018-17199
| CVE-2014-0098 5.0 https://vulners.com/cve/CVE-2014-0098
| CVE-2016-4975 4.3 https://vulners.com/cve/CVE-2016-4975
| CVE-2014-0117 4.3 https://vulners.com/cve/CVE-2014-0117
| CVE-2014-8109 4.3 https://vulners.com/cve/CVE-2014-8109
| CVE-2015-3185 4.3 https://vulners.com/cve/CVE-2015-3185
| CVE-2014-0118 4.3 https://vulners.com/cve/CVE-2014-0118
| CVE-2018-1283 3.5 https://vulners.com/cve/CVE-2018-1283
|_ CVE-2016-8612 3.3 https://vulners.com/cve/CVE-2016-8612

As you can see from above, we have scanned port 80 (with -sV switch) and used the vulners script to get all known public vulnerabilities of the specific service (Apache httpd 2.4.7).


Related Posts

  • 5 Best Practices to Keep Rogue Devices at Bay
  • Cisco Talos Year in Review – Top Cyber Security Threats in 2023 and Beyond
  • How to Scan an IP Network Range with NMAP (and Zenmap)
  • What is Cisco Identity Services Engine (ISE)? Use Cases, How it is Used etc
  • What is Cisco Umbrella Security Service? Discussion – Use Cases – Features

Filed Under: Network Security

NMAP Commands Cheat Sheet & Tutorial with Examples (Download PDF) (2)

About Harris Andrea

Harris Andrea is an Engineer with more than two decades of professional experience in the fields of TCP/IP Networks, Information Security and I.T. Over the years he has acquired several professional certifications such as CCNA, CCNP, CEH, ECSA etc.

He is a self-published author of two books ("Cisco ASA Firewall Fundamentals" and "Cisco VPN Configuration Guide") which are available at Amazon and on this website as well.


  1. NMAP Commands Cheat Sheet & Tutorial with Examples (Download PDF) (3)Sandeep Yadav says

    nice blog bro

  2. NMAP Commands Cheat Sheet & Tutorial with Examples (Download PDF) (4)Nachiketh says

    Very helpful blog

  3. NMAP Commands Cheat Sheet & Tutorial with Examples (Download PDF) (5)Patra says

    I am a beginner student and this blog is very helpful! Thank you!

  4. NMAP Commands Cheat Sheet & Tutorial with Examples (Download PDF) (6)EA says

    Thank you very much. awsome informations

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

NMAP Commands Cheat Sheet & Tutorial with Examples (Download PDF) (2024)
Top Articles
Latest Posts
Article information

Author: Rev. Porsche Oberbrunner

Last Updated:

Views: 6202

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Rev. Porsche Oberbrunner

Birthday: 1994-06-25

Address: Suite 153 582 Lubowitz Walks, Port Alfredoborough, IN 72879-2838

Phone: +128413562823324

Job: IT Strategist

Hobby: Video gaming, Basketball, Web surfing, Book restoration, Jogging, Shooting, Fishing

Introduction: My name is Rev. Porsche Oberbrunner, I am a zany, graceful, talented, witty, determined, shiny, enchanting person who loves writing and wants to share my knowledge and understanding with you.