Nmap can be used to:
3 Top 12 Nmap Commands
- Create a complete computer network map.
- Find remote IP addresses of any hosts.
- Get the OS system and software details.
- Detect open ports on local and remote systems.
- Audit server security standards.
- Find vulnerabilities on remote and local hosts.
How To Use NmapNmap is pretty easy to use if you’re familiar with command-line interfaces. As it’s already installed on most Linux/Unix-based distributions, you just have to execute the ‘nmap’ command from any terminal, and that’s it. It will display several options for you. Advanced users will also be able to use Nmap along with other system scripts and automated tasks in order to maximize the powers of this tool. Nmap port scan command One of the most basic Nmap commands for a scan is the Nmap port scan command:
nmap -p 80 X.X.X.XThat’s how you use Nmap.
Top 12 Nmap Commands
1. Basic Nmap Scan against IP or host
nmap 22.214.171.124Now, if you want to scan a hostname, simply replace the IP for the host, as you see below:
nmap kalilinuxtutorial.comThis kind of scan, such as the Nmap scan host is perfect for your first steps when starting with Nmap.
2. Nmap Ping Scan
nmap -sp 192.168.5.0/24The most famous type of scan is the Nmap ping scan (so-called because it’s often used to perform Nmap ping sweeps), and it’s the easiest way to detect hosts on any network. The drawback of this ICMP-only type of scan is that remote hosts often block IP-based ping packets, so if you’re unable to get solid results, we recommend switching to ARP-based requests for your scan.
3. Scan specific ports
nmap -p 1-65535 localhostIn this example, we scanned all 65535 ports for our localhost computer. Nmap is able to scan all possible ports, but you can also scan specific ports, which will report faster results. See below: nmap -p 80,443 126.96.36.199
4. Scan multiple IP addressesLet’s try to scan multiple IP addresses. For this you need to use this syntax:
nmap 188.8.131.52 184.108.40.206You can also scan consecutive IP addresses:
nmap 220.127.116.11,2,3,4This will scan 18.104.22.168, 22.214.171.124, 126.96.36.199, and 188.8.131.52.
5. Scan IP rangesYou can also use Nmap to scan entire CIDR IP ranges, for example:
nmap 184.108.40.206/28This will scan 14 consecutive IP ranges, from 220.127.116.11 to 18.104.22.168. An alternative is to simply use this kind of range:
nmap 22.214.171.124-14You can even use wildcards to scan the entire C class IP range, for example:
nmap 8.8.8.*This will scan 256 IP addresses from 126.96.36.199 to 188.8.131.526. If you ever need to exclude certain IPs from the IP range scan, you can use the “–exclude” option, as you see below: nmap -p 8.8.8.* –exclude 184.108.40.206
6. Scan the most popular portsUsing “–top-ports” parameter along with a specific number lets you scan the top X most common ports for that host, as we can see:
nmap --top-ports 20 192.168.1.106
7. Scan hosts and IP addresses reading from a text fileIn this case, Nmap is also useful to read files that contain hosts and IPs inside. Let’s suppose you create a list.txt file that contains these lines inside:
192.168.1.106 cloudflare.com microsoft.com kalilinuxtutorial.comThe “-iL” parameter lets you read from that file, and scan all those hosts for you:
nmap -iL list.txt
8. Save your Nmap scan results to a fileOn the other hand, in the following example we will not be reading from a file, but exporting/saving our results into a text file:
nmap -oN output.txt kalilinuxtutorial.comNmap has the ability to export files into XML format as well, see the next example:
nmap -oX output.xml kalilinuxtutorial.com
9. Disabling DNS name resolutionIf you need to speed up your scans a little bit, you can always choose to disable reverse DNS resolution for all your scans. Just add the “-n” parameter. [[email protected]:~]nmap -p 80 -n 220.127.116.11
10. Scan + OS and service detection with fast executionUsing the “-A” parameter enables you to perform OS and service detection, and at the same time we are combining this with “-T4” for faster execution. See the example below: nmap -A -T4 cloudflare.com
11. Detect service/daemon versionsThis can be done by using -sV parameters nmap -sV localhost
12. Scan using TCP or UDP protocolsOne of the things we love most about Nmap is the fact that it works for both TCP and UDP protocols. And while most services run on TCP, you can also get a great advantage by scanning UDP-based services.
TCP scanning results using “-sT” parameter
UDP scanning results using “-sU” parameter:
ConclusionIn this article, we covered the top 12 Nmap commands to scan remote hosts, but there’s a lot more to discover if you’re starting to use Nmap in your OSINT strategy.
IMPORTANT THINGS TO REMEMBER
- This article was written only for educational purposes.
- The author can not be held any responsibility for damage caused by the use of these resources.
- You will not use this information to gain unauthorized access or any other legal activity.