{"id":4620,"date":"2021-02-18T09:04:38","date_gmt":"2021-02-18T09:04:38","guid":{"rendered":"https:\/\/linuxways.net\/?p=4620"},"modified":"2021-02-18T09:07:13","modified_gmt":"2021-02-18T09:07:13","slug":"15-mostly-used-nmap-commands-for-scanning-remote-hosts","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/15-mostly-used-nmap-commands-for-scanning-remote-hosts\/","title":{"rendered":"15 Mostly Used Nmap Commands for Scanning Remote Hosts"},"content":{"rendered":"<p>Network mapper, abbreviated as Nmap, is an open-source network scanning tool that scans remote hosts and probes for a wealth of information such as open ports, OS versions, and versions of services listening on the open ports. Depending on the arguments used, Nmap also reveals underlying system vulnerabilities associated with outdated vulnerabilities based on CVSS (Common Vulnerability Scanning System). For this reason, Nmap is a valuable reconnaissance tool for penetration testing and revealing loopholes that can be exploited by hackers. In fact, it comes pre-installed in Kali and Parrot OS which are operating systems dedicated to penetration testing and digital forensics.<\/p>\n<p>In this article, we highlight some of the useful Nmap commands that help you gather useful information about remote hosts.<\/p>\n<h2><strong>Basic Nmap syntax<\/strong><\/h2>\n<p>The most basic Nmap command involves scanning a single host and requires only the IP address or the hostname of the remote target as the argument.<\/p>\n<pre><strong>$ nmap hostname <\/strong><\/pre>\n<p><strong>Or<\/strong><\/p>\n<pre><strong>$ nmap remote-host-ip<\/strong><\/pre>\n<p>Let\u2019s now delve into some Nmap use cases. In this guide, we will scan remote hosts using Kali Linux.<\/p>\n<h2><strong>Scan a single remote host<\/strong><\/h2>\n<p>Scanning a single host is pretty straightforward. All you need is to pass the remote host IP address or domain name as the argument. For example,<\/p>\n<pre><strong>$ nmap 192.168.2.103<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"751\" height=\"288\" class=\"wp-image-4621\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-307.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-307.png 751w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-307-300x115.png 300w\" sizes=\"auto, (max-width: 751px) 100vw, 751px\" \/><\/strong><\/p>\n<p>The Nmap scan report includes details such as the open ports, state of the port, and the services listening on the ports.<\/p>\n<h2><strong>Scan multiple remote hosts<\/strong><\/h2>\n<p>In a scenario where you have multiple remote hosts, simply pass their IP addresses on a single line as shown.<\/p>\n<pre><strong>$ nmap 192.168.2.103 192.168.2.1<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"757\" height=\"437\" class=\"wp-image-4622\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-308.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-308.png 757w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-308-300x173.png 300w\" sizes=\"auto, (max-width: 757px) 100vw, 757px\" \/><\/p>\n<p>If you wish to scan consecutive remote host IP address, simply suffix the address as follows:<\/p>\n<pre><strong>$ nmap 192.168.2.1,2,3,4<\/strong><\/pre>\n<p>The command above scans the remote hosts <strong>192.168.2.1, 192.168.2.2, 192.168.2.3, <\/strong>and<strong> 192.168.2.4<\/strong><\/p>\n<h2><strong>Scan a range of remote hosts<\/strong><\/h2>\n<p>If you have remote hosts in a range of IP addresses, you can specify the range separated by a hyphen.<\/p>\n<pre><strong>$ nmap 192.168.2.100-105 <\/strong><\/pre>\n<p>This will scan all the remote hosts from <strong>192.168.2.100 <\/strong>to <strong>192.168.2.105 <\/strong>range.<\/p>\n<h2><strong>Scan a subnet<\/strong><\/h2>\n<p>You can scan an entire subnet by making use of the CIDR notation. For instance, the command below scans all the remote hosts in the <strong>192.168.2.0<\/strong> subnet.<\/p>\n<pre><strong>$ nmap 192.168.2.0\/24<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"745\" height=\"570\" class=\"wp-image-4623\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-309.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-309.png 745w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-309-300x230.png 300w\" sizes=\"auto, (max-width: 745px) 100vw, 745px\" \/><\/strong><\/p>\n<h2><strong>Port scanning using Nmap<\/strong><\/h2>\n<p>You can instruct Nmap to explicitly scan open ports on a target host using the <strong>-p <\/strong>flag followed by the port number. In the example below, we are scanning for port 80 on the remote host.<\/p>\n<pre><strong>$ nmap -p 80 192.168.2.100<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"751\" height=\"298\" class=\"wp-image-4624\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-310.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-310.png 751w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-310-300x119.png 300w\" sizes=\"auto, (max-width: 751px) 100vw, 751px\" \/><\/strong><\/p>\n<p>To specify multiple ports, you can list them using commas as shown below.<\/p>\n<pre><strong>$ nmap -p 80,135,139 192.168.2.100<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"751\" height=\"286\" class=\"wp-image-4625\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-311.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-311.png 751w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-311-300x114.png 300w\" sizes=\"auto, (max-width: 751px) 100vw, 751px\" \/><\/strong><\/p>\n<p>To scan all open ports on a target, use the <strong>&#8211;open <\/strong>flag. Here, we are scanning Metasploitable Linux which is an intentionally vulnerable virtual instance for penetration testing.<\/p>\n<pre><strong>$ nmap --open 192.168.2.107<\/strong><\/pre>\n<h2><strong>Scan for active remote hosts<\/strong><\/h2>\n<p>If you just want to know which remote hosts are alive in your subnet, pass the <strong>-sn<\/strong> flag as shown. The output will be nothing fancy, just a brief summary of the active hosts.<\/p>\n<pre><strong>$ nmap -sn 192.168.2.0\/24<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"752\" height=\"323\" class=\"wp-image-4626\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-312.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-312.png 752w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-312-300x129.png 300w\" sizes=\"auto, (max-width: 752px) 100vw, 752px\" \/><\/strong><\/p>\n<h2><strong>OS fingerprinting<\/strong><\/h2>\n<p>The -O flag enables you to even detect the host\u2019s operating system to a certain degree. However, this does not give you the exact version of the target\u2019s OS. In the example below, we are scanning a host that runs on Windows 10, but the OS guesses suggest that the remote host is likely to be Windows XP SP2 or Windows Server 2008 \/ 2008 R2.<\/p>\n<pre><strong># nmap -O 192.168.2.103<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"671\" height=\"471\" class=\"wp-image-4627\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-313.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-313.png 671w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-313-300x211.png 300w\" sizes=\"auto, (max-width: 671px) 100vw, 671px\" \/><\/strong><\/p>\n<h2><strong>Service detection<\/strong><\/h2>\n<p>You can get down to the nitty-gritty of the services listening on associated ports using the <strong>-sV <\/strong>flag. Common services include SSH ( port 22), HTTP ( port 80), and DNS ( port 53 ). Service detection is one of the most critical scanning tasks. It helps in pointing out outdated service versions that may leave the system prone to exploits and attacks.<\/p>\n<pre><strong>$ nmap -sV 192.168.2.107<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"809\" height=\"567\" class=\"wp-image-4628\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-314.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-314.png 809w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-314-300x210.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-314-768x538.png 768w\" sizes=\"auto, (max-width: 809px) 100vw, 809px\" \/><\/strong><\/p>\n<h2><strong>Perform a stealth scan using Nmap<\/strong><\/h2>\n<p>A stealth scan, also abbreviated as SYN scan, is an unobtrusive kind of scan that quickly scans multiple ports within the shortest time possible. A SYN packet is sent to the remote target and when the response is received, Nmap is able to report on whether the port is open, filtered, or closed.<\/p>\n<pre><strong>$ nmap -sS 192.168.2.107<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"806\" height=\"565\" class=\"wp-image-4629\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-315.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-315.png 806w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-315-300x210.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-315-768x538.png 768w\" sizes=\"auto, (max-width: 806px) 100vw, 806px\" \/><\/strong><\/p>\n<h2><strong>Perform a detailed scan<\/strong><\/h2>\n<p>The <strong>-A <\/strong>flag performs a deep inspection of the remote target\u2019s ports and gives finer details about the version of running services and also points out any vulnerabilities with the service.<\/p>\n<pre><strong>$ nmap -A 192.168.2.107<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"812\" height=\"415\" class=\"wp-image-4630\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-316.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-316.png 812w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-316-300x153.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-316-768x393.png 768w\" sizes=\"auto, (max-width: 812px) 100vw, 812px\" \/><\/strong><\/p>\n<h2><strong>Perform firewall identification<\/strong><\/h2>\n<p>The Nmap can also perform firewall identification to check if the ports are filtered or not. The <strong>-sA <\/strong>option checks whether the firewall is enabled and needs to be combined with the -p flag and port number. \u2018Unfiltered\u2019 implies that the port is not behind a firewall while \u2018filtered\u2019 means it\u2019s opened on a firewall that is enabled.<\/p>\n<pre><strong>$ nmap -sA 192.168.2.107 -p 21 <\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"812\" height=\"319\" class=\"wp-image-4631\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-317.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-317.png 812w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-317-300x118.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-317-768x302.png 768w\" sizes=\"auto, (max-width: 812px) 100vw, 812px\" \/><\/strong><\/p>\n<h2><strong>Scan TCP or UDP protocols <\/strong><\/h2>\n<p>If you want to scan TCP ports only, use the <strong>-sT <\/strong>flag as shown.<\/p>\n<pre><strong>$ nmap -sT 192.168.2.107<\/strong><\/pre>\n<p>If you choose to scan to reveal UDP protocols only, use the <strong>-sT <\/strong>option.<\/p>\n<pre><strong># nmap -sU 192.168.2.107<\/strong><\/pre>\n<h2><strong>Using Nmap scripts to scan vulnerabilities<\/strong><\/h2>\n<p>Nmap Scripting Engine, abbreviated as NSE, provides Nmap scripts that extend Nmap\u2019s functionalities. Nmap scripts are mostly used in probing vulnerability and malware detection. These scripts come preinstalled on Kali Linux and are located in the <strong>\/usr\/share\/nmap\/scripts <\/strong>path. They have a unique .nse file extension.<\/p>\n<p>For example, to check if a remote host can be brute-forced using SSH use the Nmap script below.<\/p>\n<pre><strong>$ nmap --script=ssh-brute.nse 192.168.2.107<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"811\" height=\"278\" class=\"wp-image-4632\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-318.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-318.png 811w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-318-300x103.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-318-768x263.png 768w\" sizes=\"auto, (max-width: 811px) 100vw, 811px\" \/><\/strong><\/p>\n<h2><strong>Save Nmap scan results <\/strong><\/h2>\n<p>If you are in a hurry and want to save the results of a Nmap scan for later review, you can use the redirection greater than sign &gt; as shown.<\/p>\n<pre><strong>$ nmap -sT 192.168.2.103 &gt; myscans.txt<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"815\" height=\"129\" class=\"wp-image-4633\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-319.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-319.png 815w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-319-300x47.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-319-768x122.png 768w\" sizes=\"auto, (max-width: 815px) 100vw, 815px\" \/><\/strong><\/p>\n<h2><strong>Scan hosts from a text file<\/strong><\/h2>\n<p>Alternatively, you can scan your remote hosts which are defined in a text file. To read the file, use the &#8211;<strong>iL<\/strong> option.<\/p>\n<pre><strong>$ nmap -A iL hosts.txt<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"814\" height=\"347\" class=\"wp-image-4634\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-320.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-320.png 814w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-320-300x128.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-320-768x327.png 768w\" sizes=\"auto, (max-width: 814px) 100vw, 814px\" \/><\/strong><\/p>\n<h3>Conclusion<\/h3>\n<p>We have listed 15 Nmap commands that you can use to get started with scanning your remote hosts. There are hundreds upon hundreds of Nmap commands and <a href=\"https:\/\/nmap.org\/book\/man-nse.html\">Nmap scripts<\/a> that are used for scanning hosts and probing for any vulnerabilities. We hope you now have the basics of Nmap and running commands to reveal information about remote targets. If you are considering scanning an organization\u2019s assets, ensure that you seek permission from the management lest you get into trouble.<\/p>","protected":false},"excerpt":{"rendered":"<p>Network mapper, abbreviated as Nmap, is an open-source network scanning tool that scans remote hosts and probes for a wealth of information such as open ports, OS versions,&hellip;<\/p>","protected":false},"author":36,"featured_media":4636,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,5,83,165,2],"tags":[203,201,202],"class_list":["post-4620","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-debian","category-mint","category-opensuse","category-red-hat","category-ubuntu","tag-host-scanning","tag-nmap","tag-port-scanning"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/4620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=4620"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/4620\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/4636"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=4620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=4620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=4620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}