Ready to Start Your Career?

29 Useful Commands in Nmap (Plus a Bonus)

cardangi 's profile image

By: cardangi

August 17, 2016

#1: Scan a single host or an IP address (IPv4)

### Scan a single ip address###nmap ## Scan a host name###nmap ## Scan a host name with more info###nmap -v
Sample outputs:
Fig.01: nmap outputFig.01: nmap output

#2: Scan multiple IP address or subnet (IPv4)

nmap works with same subnet i.e.,2,3
You can scan a range of IP addresses too:
You can scan a range of IP address using a wildcard:
nmap 192.168.1.*
Finally, you scan an entire subnet:

#3: Read list of hosts/networks from a file (IPv4)

The -iL option allows you to read the list of target systems using a text file. This is useful to scan a large number of hosts/networks. Create a text file as follows:

cat > /tmp/test.txt

Sample outputs:
The syntax is:
nmap -iL /tmp/test.txt

#4: Excluding hosts/networks (IPv4)

When scanning a large number of hosts/networks, you can exclude hosts from a scan:
nmap --exclude --exclude,
OR exclude list from a file called /tmp/exclude.txt
nmap -iL /tmp/scanlist.txt --excludefile /tmp/exclude.txt

#5: Turn on OS and version detection scanning script (IPv4)

nmap -A -v -A -A -iL /tmp/scanlist.txt

#6: Find out if a host/network is protected by a firewall

nmap -sA -sA

#7: Scan a host when protected by the firewall

nmap -PN -PN

#8: Scan an IPv6 host/address

The -6 option enable IPv6 scanning. The syntax is:
nmap -6 IPv6-Address-Herenmap -6 server1.cyberciti.biznmap -6 2607:f0d0:1002:51::4nmap -v A -6 2607:f0d0:1002:51::4

#9: Scan a network and find out which servers and devices are up and running

This is known as host discovery or ping scan:
nmap -sP
Sample outputs:
Host is up (0.00035s latency).MAC Address: BC:AE:C5:C3:16:93 (Unknown)Host is up (0.0038s latency).MAC Address: 74:44:01:40:57:FB (Unknown)Host is up.Host nas03 ( is up (0.0091s latency).MAC Address: 00:11:32:11:15:FC (Synology Incorporated)Nmap done: 256 IP addresses (4 hosts up) scanned in 2.80 second

#10: How do I perform a fast scan?

nmap -F

#11: Display the reason a port is in a particular state

nmap --reason --reason

#12: Only show open (or possibly open) ports

nmap --open --open

#13: Show all packets sent and received

nmap --packet-trace --packet-trace

14#: Show host interfaces and routes

This is useful for debugging (ip command or route command or netstat command like output using Nmap)
nmap --iflist
Sample outputs:
Starting Nmap 5.00 ( ) at 2012-11-27 02:01 IST************************INTERFACES************************DEV    (SHORT)  IP/MASK          TYPE        UP MAClo     (lo)      loopback    upeth0   (eth0)   ethernet    up B8:AC:6F:65:31:E5vmnet1 (vmnet1) ethernet    up 00:50:56:C0:00:01vmnet8 (vmnet8) ethernet    up 00:50:56:C0:00:08ppp0   (ppp0)    point2point up **************************ROUTES**************************DST/MASK         DEV    GATEWAY10.0.31.178/32   ppp0209.133.67.35/32 eth0    eth0192.168.121.0/0  vmnet1192.168.179.0/0  vmnet8169.254.0.0/0    eth010.0.0.0/0       ppp00.0.0.0/0        eth0

#15: How do I scan specific ports?

nmap -p [port] hostName## Scan port 80nmap -p 80 ## Scan TCP port 80nmap -p T:80 ## Scan UDP port 53nmap -p U:53 ## Scan two ports##nmap -p 80,443 ## Scan port ranges##nmap -p 80-200 ## Combine all options##nmap -p U:53,111,137,T:21-25,80,139,8080 -p U:53,111,137,T:21-25,80,139,8080 server1.cyberciti.biznmap -v -sU -sT -p U:53,111,137,T:21-25,80,139,8080 ## Scan all ports with * wildcard##nmap -p "*" ## Scan top ports i.e. scan $number most common ports##nmap --top-ports 5 --top-ports 10
Sample outputs:
Starting Nmap 5.00 ( ) at 2012-11-27 01:23 ISTInteresting ports on     STATE  SERVICE21/tcp   closed ftp22/tcp   open   ssh23/tcp   closed telnet25/tcp   closed smtp80/tcp   open   http110/tcp  closed pop3139/tcp  closed netbios-ssn443/tcp  closed https445/tcp  closed microsoft-ds3389/tcp closed ms-term-servMAC Address: BC:AE:C5:C3:16:93 (Unknown) Nmap done: 1 IP address (1 host up) scanned in 0.51 seconds

#16: The fastest way to scan all your devices/computers for open ports ever

nmap -T5

#17: How do I detect remote operating system?

You can identify a remote host apps and OS using the -O option:
nmap -O -O  --osscan-guess -v -O --osscan-guess
Sample outputs:
Starting Nmap 5.00 ( ) at 2012-11-27 01:29 ISTNSE: Loaded 0 scripts for scanning.Initiating ARP Ping Scan at 01:29Scanning [1 port]Completed ARP Ping Scan at 01:29, 0.01s elapsed (1 total hosts)Initiating Parallel DNS resolution of 1 host. at 01:29Completed Parallel DNS resolution of 1 host. at 01:29, 0.22s elapsedInitiating SYN Stealth Scan at 01:29Scanning [1000 ports]Discovered open port 80/tcp on open port 22/tcp on SYN Stealth Scan at 01:29, 0.16s elapsed (1000 total ports)Initiating OS detection (try#1) against OS detection (try#2) against OS detection (try#3) against OS detection (try#4) against OS detection (try#5) against is up (0.00049s latency).Interesting ports on shown: 998 closed portsPORT   STATE SERVICE22/tcp open  ssh80/tcp open  httpMAC Address: BC:AE:C5:C3:16:93 (Unknown)Device type: WAP|general purpose|router|printer|broadband routerRunning (JUST GUESSING) : Linksys Linux 2.4.X (95%), Linux 2.4.X|2.6.X (94%), MikroTik RouterOS 3.X (92%), Lexmark embedded (90%), Enterasys embedded (89%), D-Link Linux 2.4.X (89%), Netgear Linux 2.4.X (89%)Aggressive OS guesses: OpenWrt White Russian 0.9 (Linux 2.4.30) (95%), OpenWrt 0.9 - 7.09 (Linux 2.4.30 - 2.4.34) (94%), OpenWrt Kamikaze 7.09 (Linux 2.6.22) (94%), Linux 2.4.21 - 2.4.31 (likely embedded) (92%), Linux 2.6.15 - 2.6.23 (embedded) (92%), Linux 2.6.15 - 2.6.24 (92%), MikroTik RouterOS 3.0beta5 (92%), MikroTik RouterOS 3.17 (92%), Linux 2.6.24 (91%), Linux 2.6.22 (90%)No exact OS matches for host (If you know what OS is running on it, see ).TCP/IP fingerprint:OS:SCAN(V=5.00%D=11/27%OT=22%CT=1%CU=30609%PV=Y%DS=1%G=Y%M=BCAEC5%TM=50B3CAOS:4B%P=x86_64-unknown-linux-gnu)SEQ(SP=C8%GCD=1%ISR=CB%TI=Z%CI=Z%II=I%TS=7OS:)OPS(O1=M2300ST11NW2%O2=M2300ST11NW2%O3=M2300NNT11NW2%O4=M2300ST11NW2%O5OS:=M2300ST11NW2%O6=M2300ST11)WIN(W1=45E8%W2=45E8%W3=45E8%W4=45E8%W5=45E8%WOS:6=45E8)ECN(R=Y%DF=Y%T=40%W=4600%O=M2300NNSNW2%CC=N%Q=)T1(R=Y%DF=Y%T=40%SOS:=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%ROS:D=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=OS:0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=N)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RIDOS:=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40%CD=S)Uptime guess: 12.990 days (since Wed Nov 14 01:44:40 2012)Network Distance: 1 hopTCP Sequence Prediction: Difficulty=200 (Good luck!)IP ID Sequence Generation: All zerosRead data files from: /usr/share/nmapOS detection performed. Please report any incorrect results at .Nmap done: 1 IP address (1 host up) scanned in 12.38 seconds           Raw packets sent: 1126 (53.832KB) | Rcvd: 1066 (46.100KB)
See also: Fingerprinting a web-server and a dns server command line tools for more information.

#18: How do I detect remote services (server / daemon) version numbers?

nmap -sV
Sample outputs:
Starting Nmap 5.00 ( ) at 2012-11-27 01:34 ISTInteresting ports on shown: 998 closed portsPORT   STATE SERVICE VERSION22/tcp open  ssh     Dropbear sshd 0.52 (protocol 2.0)80/tcp open  http?1 service unrecognized despite returning data.

#19: Scan a host using TCP ACK (PA) and TCP Syn (PS) ping

If a firewall is blocking standard ICMP pings, try the following host discovery methods:
nmap -PS -PS 80,21,443 -PA -PA 80,21,200-512

#20: Scan a host using IP protocol ping

nmap -PO

#21: Scan a host using UDP ping

This scan bypasses firewalls and filters that only screen TCP:
nmap -PU -PU 2000.2001

#22: Find out the most commonly used TCP ports using TCP SYN Scan

### Stealthy scan###nmap -sS ### Find out the most commonly used TCP ports using  TCP connect scan (warning: no stealth scan)###  OS Fingerprinting###nmap -sT ### Find out the most commonly used TCP ports using TCP ACK scannmap -sA ### Find out the most commonly used TCP ports using TCP Window scannmap -sW ### Find out the most commonly used TCP ports using TCP Maimon scannmap -sM

#23: Scan a host for UDP services (UDP scan)

Most popular services on the Internet run over the TCP protocol. DNS, SNMP and DHCP are three of the most common UDP services. Use the following syntax to find out UDP services:
nmap -sU nas03nmap -sU
Sample outputs:
Starting Nmap 5.00 ( ) at 2012-11-27 00:52 ISTStats: 0:05:29 elapsed; 0 hosts completed (1 up), 1 undergoing UDP ScanUDP Scan Timing: About 32.49% done; ETC: 01:09 (0:11:26 remaining)Interesting ports on nas03 ( shown: 995 closed portsPORT     STATE         SERVICE111/udp  open|filtered rpcbind123/udp  open|filtered ntp161/udp  open|filtered snmp2049/udp open|filtered nfs5353/udp open|filtered zeroconfMAC Address: 00:11:32:11:15:FC (Synology Incorporated) Nmap done: 1 IP address (1 host up) scanned in 1099.55 seconds

#24: Scan for IP Protocol

This type of scan allows you to determine which IP protocols (TCP, ICMP, IGMP, etc.) are supported by target machines:
nmap -sO

#25: Scan a firewall for security weakness

The following scan types exploit a subtle loophole in the TCP and good for testing security of common attacks:
## TCP Null Scan to fool a firewall to generate a response#### Does not set any bits (TCP flag header is 0)##nmap -sN ## TCP Fin scan to check firewall#### Sets just the TCP FIN bit##nmap -sF ## TCP Xmas scan to check firewall#### Sets the FIN, PSH, and URG flags, lighting the packet up like a Christmas tree##nmap -sX
See how to block Xmas packkets, syn-floods and other conman attacks with iptables.

#26: Scan a firewall for packets fragments

The -f option causes the requested scan (including ping scans) to use tiny fragmented IP packets. The idea is to split up the TCP header over several packets to make it harder for packet filters, intrusion detection systems and other annoyances to detect what you're doing.
nmap -f -f -f 15 Set your own offset size with the --mtu option ##nmap --mtu 32

#27: Cloak a scan with decoys

The -D option it appear to the remote host that the host(s) you specify as decoys are scanning the target network too. Thus, their IDS might report 5-10 port scans from unique IP addresses, but they won’t know which IP was scanning them and which were innocent decoys:
nmap -n -Ddecoy-ip1,decoy-ip2,your-own-ip,decoy-ip3,decoy-ip4 remote-host-ipnmap -n -D192.168.1.5,,,

#28: Scan a firewall for MAC address spoofing

### Spoof your MAC address##nmap --spoof-mac MAC-ADDRESS-HERE ### Add other options###nmap -v -sT -PN --spoof-mac MAC-ADDRESS-HERE  ### Use a random MAC address###### The number 0, means nmap chooses a completely random MAC address###nmap -v -sT -PN --spoof-mac 0

#29: How do I save output to a text file?

The syntax is:
nmap > output.txtnmap -oN /path/to/filename -oN output.txt

BONUS -#30: Not a fan of command line tools?

Try zenmap the official network mapper front end:
Zenmap is the official Nmap Security Scanner GUI. It is a multi-platform (Linux, Windows, Mac OS X, BSD, etc.) free and open source application which aims to make Nmap easy for beginners to use while providing advanced features for experienced Nmap users. Frequently used scans can be saved as profiles to make them easy to run repeatedly. A command creator allows interactive creation of Nmap command lines. Scan results can be saved and viewed later. Saved scan results can be compared with one another to see how they differ. The results of recent scans are stored in a searchable database.
You can install zenmap using the following apt-get command:

$ sudo apt-get install zenmap

Sample outputs:

[sudo] password for vivek:Reading package lists... DoneBuilding dependency treeReading state information... DoneThe following NEW packages will be installed:  zenmap0 upgraded, 1 newly installed, 0 to remove and 11 not upgraded.Need to get 616 kB of archives.After this operation, 1,827 kB of additional disk space will be used.Get:1 squeeze/main zenmap amd64 5.00-3 [616 kB]Fetched 616 kB in 3s (199 kB/s)Selecting previously deselected package zenmap.(Reading database ... 281105 files and directories currently installed.)Unpacking zenmap (from .../zenmap_5.00-3_amd64.deb) ...Processing triggers for desktop-file-utils ...Processing triggers for gnome-menus ...Processing triggers for man-db ...Setting up zenmap (5.00-3) ...Processing triggers for python-central ...
Type the following command to start zenmap:

$ sudo zenmap

Sample outputs:

Fig.02: zenmap in action
Reference Website:

Want to learn more about NMAP? Get started today using our FREE courses:

Schedule Demo