NMap 101

NMap short for Network Mapper is as the name suggests a tool used for mapping a network, but one of the great features is that it shows all the open ports, what services are running on the ports and all sorts of custom outputs.

Most versions of Linux I have used already have had nmap install by default, if not then you can easly install it by using the following command straight in your terminal.

sudo apt-get install nmap

To find out what version of nmap your running type this.

nmap --version

There is also a version of nmap with a GUI called Zenmap, this can just as easly be installed by typing.

sudo apt-get install zenmap

The most basic nmap command goes as so.


This shows the ports found, the state of that port open/closed and what service it thinks is running on that port.

nmap ports

Scanning for multiple targets

You can scan multiple targets by adding each individual target one after the other leaving a space between each.


or you can put the same command like this.


or you can set a range of addresses.

nmap - 100

This will scan all ips on different subnets for example – and then move onto – and so on until in this example its -

nmap 192.168.6-100.*

This will scan all ips in the current subnet.


you can create a list of ip addresses and put them in a text file and get nmap to scan the list.

to create the list echo the required IP address into a text file.

echo > list.txt
>  Replace contents of file.
>> Amend file this will leave any previous contents of the file in place.

to see the contents of your list.txt use the cat command.

cat list.txt

now use that list in conjunction with nmap as below.

nmap -il list.txt


Scanning Networks while Excluding Certain Targets.

You scan a specified amount of random hosts using the -iR command and then the number of hosts.

nmap -iR 3

If you want to scan an entire subnet excluding a certain pc.

nmap --exclude

This command below is the same as the one above but its excluding a range of addresses.

nmap --exclude

You can also use a use a text file with a list of ips to exclude.

nmap -- excludefile list.txt


Scanning Networks for Open Ports to access

The -A command does a Aggressive scan this will run some of the most popular commands like OS detection, version detection, script scanning and traceroute.

nmap -A

Say you find a open Telnet port on a print server as below.

open telnet port

you can use either telnet or a program like Netcat to connect to this port and gain access to the service.

if you want more information on connecting to ports with Netcat see my Netcat 101 tutorial


Using Alternative Packets

Use the -PN to scan a host when its protected with a firewall this will scan a host,nmap not doing a ping scan first and will do a deep scan of the target

nmap -PN

This next command is a simple ping scan -sP this will simply just ping the server and wont tell you the names or the open ports.

nmap -sP

To change the scan to a Syn scan instead of a ICMP scan.

nmap -PS

if you want to check specific ports in your Syn scan type your command like so.

nmap -PS 22,80,443

To change the scan to use ACK packets instead of ICMP

nmap -PA

To change the scan to use UDP instead of ICMP

nmap -PU

To do a SCTP scan instead of ICMP

nmap -PW

This is the default scan and what is used if no other scan is specified.

nmap -PE

you can use ICMP timestamping for getting around firewalled targets.

nmap -PP

another good command for getting around firewalls is ICMP address mask ping.

nmap -PM


Discovery Options

You can use the command below to do a IP protocol ping this sends packets with the specified protocol to the target. If no protocols are specified, the default protocols 1 (ICMP), 2(IGMP) and 4 (IP-in-IP) are used.

nmap -PO

The -PR option is used to perform an arp ping scan, it cant be used of the target is not on your local subnet.

nmap -PR

The -traceroute parameter can be used to trace the network path to the specified host

nmap --traceroute www.google.com

The -R parameter instructs Nmap to always perform a reverse DNS resolution on the target IP address. this is useful when performing reconnaissance on a block of IP addresses, as Nmap will try to resolve the reverse DNS information of every IP address.

nmap -R

The –system-dns option instructs Nmap to use the host systems DNS resolver instead of its own internal method.

nmap --system-dns

You can also manually specify DNS servers to be queried with the –dns-servers this will bypass the local dns servers on your system to what ever you specified.

nmap --DNS-servers

the -sL option will display a list and performs a reverse DNS lookup of the specified IP addresses

nmap -sL


Advanced Scanning Techniques

Syn scan is the most popular scan option. It can scan thousands of ports per secound on a fast network not hampered by restrictive firewalls. it is also relatively unobtrusive and stealthy, since it never completes TCP connections.

nmap -sS

TCP connect scan is the default scan and is very noisy on the network.

nmap -sT

Use the command below to use UDP scanning. UDP scanning is generally slower and more difficult than TCP

nmap -sU

TCP null scan tricks a target to think its probing with TCP

nmap -sN

TCP fin scan is used on a target behind a firewall.

nmap -sF

Xmas scan sets the FIN, PSH and URG flags, lighting the packet up like a christmas tree.

nmap -sX

This option specifies which TCP flags should be set in the TCP packet this is normally used to evade Firewalls or and IDS.

nmap --scanflags ackpsh

There are 8 different flags you can use:-

  • CWR (congestion Windows Reduced)
  • ECN (Explicit Congestion Notification)
  • URG (Urgent)
  • ACK (Acknowledgement)
  • PSH (Push)
  • RST (Reset)
  • SYN (Synchronize)
  • FIN (Finish)

TCP ACK scan this scan is different than the others discussed so far in that it never determines open or even open | filtered ports. It is used to map out firewall rule sets, determining whether they are stateful or not and which ports are filtered.

nmap -sA

IP protocol scan this will show just the protocol and the state of the service.

nmap -sO

Scan using raw ethernet packets

nmap --send-eth

Scan using raw ip packets

nmap  --send-ip


Port Scanning Options

nmap will normally scan the top 1000 ports by default but if you want to scan other ports you can use these commands.

Fast scan will just scan the top 100 ports

nmap -F

Scan just the specified port.

nmap -p 80

This next command is the same as above but uses a comma to sperate the ports also you can do a range of ports.

nmap -p 80,23,140-200

If you cant remember the port number you can always use the name of the port.

nmap -p http

This will scan for any service with sm in the name the * is a wildcard and the quotes ” ” tell the OS its a nmap scan and not a linux terminal scan.

nmap -p "sm*"

this next command specifies UDP and TCP on ports udp 53 tcp 25

nmap -sU -sT -p U:53,T:25

You can use a * as a wildcard to scan for every thing.

nmap -p "*"

Run through the top 54 ports, The 54 can be any number.

nmap --top-ports 54

By default  nmap randomizes the scanned port order. This randomization is normally desirable but you can specify -r for sequential port scanning instead.

nmap -r

Add -v to any scan to get more a verbose output as its scanning.

Operating System Detection

Nmap has the power to tell what operating system and services are running on a remote machine this process is called tcp/ip fingerprinting.

This will figure out what Operating system is running, use -v to get even more info.

nmap -O

This will scan a host with nmaps best guess of what the OS is if the above command is not working.

nmap -O --osscan-guess

Same as the above but a easyer command.

nmap -O --fuzzy

This shows the service versions the target is running.

nmap -sV

Use the –Version-trace if the above command is not giving the output you thought you would be getting this prints out extensive debugging info.

nmap -sV --Version-trace

To do a RPC scan

nmap -sR

Timing Options

Sometimes speeding up or slowing down your nmap scan can give you better results for example if you are on a slow network you might want to slow down your scan.

Time in nmap is in ms milliesecounds so if you type 100 it will be 100ms or 100s for secounds 1m for min or 1h for hours.

Remember there is 1000ms to a secound so if i wanted to type 1000ms you could just type 1s and would get the same result.

Avoid firewall and IDS alerts  using -T0. T stands for timing and the zero 0 is its slowest setting

nmap -T0

Same as above but with the 5 its extreamly fast.

nmap -T5

You can set how meany probes nmap uses to help with port scanning and host discovery.

This command will scan with just 4 probes at the same time.

nmap --max-parallelism 4

Scan with 100 probes at the same time this may result with a faster less acurate scan.

nmap --min-parallelism 100

Tell nmap to scan a specified number of hosts at the same time in the specified range.

nmap --min-hostgroup 10

Same as above but will tell nmap the maximum number of hosts to scan at the same time.

nmap --max-hostgroup 10

Increase or decrease the time nmap times out.

nmap --initial-rtt-timeout 6000

same as above but you are setting the max time out.

nmap --max-rtt-timeout 6000

The default rtt timeout in nmap is 10s.

You can set the amount of retries the scan does, good for slow networks.

nmap --max-retries 3

Set the ttl (time to live) of your scan .

nmap --ttl 100

This will stop nmap trying a host after a given time.

nmap --host-timeout 1m

Create a delay between scan probes very slow but very accurate.

nmap --scan-delay 10s

Same as above but is a lot faster but is less accurate.

nmap --max-scan-delay 10s

Set the minimum amount of packets per secound

nmap --min-rate 50

This command is the same as above but you are setting the maximum amount of packets  per secound good for going undetected on a network but very slow.

nmap --max-rate 10

This will defeat the rst packets (reset packets) probaley wont ever need to use this command as its built into nmap by default

nmap --defeat-rst-ratelimit


Fun with Firewalls

Send smaller 8byte probes instead of a whole packet can also be done with nmap –send-eth to do the same thing

nmap -f

Specify the MTU size of your scan, can only us multiples of 8 when setting the size.

nmap --mtu 8

The decoy option will scan using multiple decoy ip addresses -D is for decoy RND generates the number random ip addresses specified after the colon : .

nmap -D RND:10 this is

Specify which pcs to uses as a decoy in this example its .52 and .100

nmap -D,

Idol zombie scan this will scan a pc pretending to be any idol PC.

nmap -sI

specify what port number the nmap scans from, also can be done with a -g command.

nmap --source-port 54

Add random data to probe packets to help try and evade the firewall, the size is in bytes.

nmap --data-length  25

Randomize your target scan order

nmap --randomize-hosts

spoof the mac address in your scan the 0 tells nmap to make a random mac address

nmap -sT -PN --spoof-mac 0

send packets with incorrect checksums.

nmap --badsum


How to Output to a file

Scan your network and output to a file called scan.txt

nmap -oN scan.txt

Scan the network outputting the results to a xml file called scan.xml.

nmap -oX scan.xml

make a grep-able file

nmap -oG scan.txt

then u can grep the file( grep “Microsoft” scan.txt )and it will pull out all the info with Microsoft on.

This next command will output a txt file a xml and a grep-able file with the name of scan.

nmap -oA scan

Force your scan to give you info every  2 seconds, you can use m for min or h for hours.

nmap --stats-every 2s

Save a file called scan.txt and changes the output into l33t speak.

nmap -oS scan.txt


How to Troubleshoot Scans

To bring up help type

nmap -h

Nmap manual

man nmap

Nmap Version

nmap -v

Debug output, to get even more output you can use d1 upto d9 d1 being the fastest

nmap -d

Port state reason codes added to your scan. if a port does not give you a reason code its either closed or behind a firewall.

nmap --reason

this will show just the open ports.

nmap --open

Shows the packets sent and received during a scan, you can output the info to a textfile by using nmap –packet-trace > trace.txt

nmap --packet-trace

Show you the network interfaces and routes that are configured on your local network.

nmap --iflist

-e lets you specifies the network interface wlan0, eth0 or what ever your network interfaces are called to run your scan from.

nmap -e wlan0


Nmap Scripting Engine

nmap comes with a ton of scripts but there are over 400 that can be downloaded from https://nmap.org/nsedoc and they are normally saved to /home/usr/share/nmap/scripts/… you have to navigate to the scripts folder to be able to run a script.

Nmap needs to be atlest version 5.0 to run a script.

This script does a banner grab of any open tcp ports.

nmap --script banner

This is a wildcard and will run any script with http in the name and output any info its able to use.

nmap --script "http*"

This next command does eaxctly the same as -sC as well as default you can use all, auth, Discovery, external, intrusive, safe or vun.

nmap --script default

This command shows troubleshooting info for a specific script.

nmap --script banner --script-trace

update your scripts folder using this command.

nmap --script-updatedb



ndiff allows you to compaire to different xml files

ndiff test1.xml test2.xml

the – sign is for test 1 and the + sign for test 2

you can also use -v for verbose mode

Buttons you can click when a nmap scan is running (runtime interaction)

v verbose mode
d debugging
p packet tracing
? help

13 thoughts on “NMap 101”

  1. I must thank you for the efforts you have put in writing this website.
    I really hope to see the same high-grade blog posts by you later on as well.
    In fact, your creative writing abilities has inspired me to get my own, personal blog now 😉

  2. Hi there! Quick question that’s completely off topic. Do you
    know how to make your site mobile friendly? My blog looks weird when viewing from my iphone.

    I’m trying to find a theme or plugin that might be able to correct this problem.
    If you have any suggestions, please share.


  3. Good blog! I really love how it is simple on my eyes and the data are well written. I am wondering how I might be notified when a new post has been made. I’ve subscribed to your RSS which must do the trick! Have a nice day!

    1. I’m not sure the RSS feed is working as of yet best option is to keep checking back as new content will be posted all the time.

  4. Can I simply say what a comfort to discover someone that really knows what they’re discussing over the internet. You actually realize how to bring an issue to light and make it important. More and more people really need to read this and understand this side of the story. It’s surprising you aren’t more popular given that you surely have the gift.|

  5. I do not even know the way I finished up here, however I believed this submit was great.
    I do not recognise who you’re but definitely you’re going to
    a well-known blogger if you happen to aren’t already.


    1. Hi Tai (nanos gigantum humeris insidentes) i am a dwarf standing on the shoulders of giants, there really are some great people doing hacking research at the min. If you have any question dont hesitate to drop me a message and ill try and help you ….


Leave a Reply

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