Mastering Nmap: Essential Commands and Examples for Network Security
Tags: pentesting, hacking, security, cybersecurity
Published: 2024-01-05 16:17:18

---
title: Mastering Nmap: Essential Commands and Examples for Network Security
published: true
date: 2023-11-05 06:51:33 UTC
tags: pentesting,hacking,security,cybersecurity
canonical_url: 
---

Discover the Power of Nmap Scanning and Enumeration Techniques to Strengthen Your Network Defense

![](https://cdn-images-1.medium.com/max/540/1*Mvmx0GkCTkCR-qN_zj96vg.jpeg)

### What is Nmap?

> Nmap stands for Network Mapped (Nmap) and is a network scanning and host detection tool that is very useful during several steps of penetration testing.

> **Nmap is open source and can be used to:**

> _Detect the live host on the network (host discovery)_

> _Detect the open ports on the host (port discovery or enumeration)_

> _Detect the software and the version to the respective port (service discovery)_

> _Detect the operating system, hardware address, and the software version_

> _Detect the vulnerability and security holes (Nmap scripts)_

### Nmap Syntax:

```
nmap [scan type] [options] [target specification]
```

### Nmap Scan types:

- TCP SCAN
- UDP SCAN
- SYN SCAN
- ACK SCAN
- FIN SCAN
- NULL SCAN
- XMAS SCAN
- RPC SCAN
- IDLE SCAN

> **Before delving into advanced Nmap concepts, let’s first explore the fundamentals of NSlookup. NSlookup is a command-line tool used to query DNS servers and retrieve information about domain names. To illustrate, consider the following example:**

**NSlookup** is a command-line tool for querying DNS servers to retrieve information about domain names, such as their associated IP addresses.

**Example:** To find the IP address of a domain, you can use NSlookup like this:

```
nslookup google.com
```

![](https://cdn-images-1.medium.com/max/1024/1*pvBSrkdEJUTigID0p6yXFQ.png)
_O/P_

> **Following our exploration of NSlookup, we’ll now transition to Nmap, an advanced network scanning tool. We’ll begin by discussing Nmap’s core concepts and provide an example to illustrate its functionality.**

### Nmap — Advanced Scanning (Best practices)

#### 1. Scanning and Logging Network Data with Nmap

In the provided Nmap command, several options and parameters are used to perform a network scan and save the results:

1. nmap: This is the command itself, invoking the Nmap tool.
2. -oG -: This option instructs Nmap to generate output in the "grepable" format and sends it to the standard output (stdout).
3. 192.168.29.238: This is the target IP address (or hostname) you want to scan. Nmap will perform its scanning and testing on this target.
4. -vv: The -v option stands for "verbose." Using it twice (-vv) increases the verbosity level, providing more detailed information during the scan.
5. > Desktop/results: The > symbol is used to redirect the output of the Nmap command to a file named "results" on the desktop. This will create a file containing the scan results in the current user's Desktop directory.

```
nmap -oG - <ip> -vv > Desktop/results
```

![](https://cdn-images-1.medium.com/max/1024/1*xJFd1ueXRtivLPvZ4Gcrxw.png)
_O/P_

#### 2. Scanning Particular with Nmap

This Nmap command is designed to perform an extensive network scan targeting a range of IP addresses and specifically focusing on particular port services:

1. nmap: This is the Nmap command to initiate network scanning.
2. -oG -: The -oG option instructs Nmap to generate output in the "grepable" format, while the hyphen - indicates that the output should be sent to the standard output (stdout).
3. 192.168.29.0-255: This specifies a range of IP addresses from 192.168.29.0 to 192.168.29.255. The scan will be conducted on all IP addresses within this range.
4. -p 22: The -p option is used to specify the port number to scan, and in this case, it's set to 22. Port 22 is the default port for SSH (Secure Shell), a protocol used for secure remote access to system.
5. -vv: The -v option is for "verbose" mode, and using it twice (-vv) increases the verbosity, providing detailed information during the scan.
6. > Desktop/results: The > symbol is used to redirect the output of the Nmap command to a file named "results" on the desktop.

```
 nmap -oG - <ip>-<range> -p 22 -vv > Desktop/results
```

![](https://cdn-images-1.medium.com/max/1024/1*L-mH5sEd9Om23ZHXtS9OCA.png)
_O/P_

### Nmap — Aggressive Scanning

1. This Nmap command performs an “Aggressive” scan on the target “scanme.nmap.org.” The -A option in the command instructs Nmap to enable version detection, script scanning, and traceroute to provide a more detailed and comprehensive assessment of the target system. "scanme.nmap.org" is a service provided by Nmap that allows users to test their Nmap scanning skills on a safe and controlled target. The result of this scan will include information about open ports, services, operating system details, and potential vulnerabilities, making it an extensive reconnaissance effort.

```
nmap -A scanme.nmap.org
```

![](https://cdn-images-1.medium.com/max/1024/1*GGJ8gMlGFnqSto757XZ1UQ.png)
_-A (aggressive scan)_

**2.** The Nmap below command is used to perform a version detection scan on the target "scanme.nmap.org." Here's an explanation of the command:

- -sV: The -sV option is used to enable version detection during the scan. When this option is included, Nmap attempts to determine the version of the services running on the target by analyzing their responses to various probes. This can help identify not only the service but also the specific version of the service (e.g., Apache 2.4.7).

```
nmap -sV scanme.nmap.org
```

![](https://cdn-images-1.medium.com/max/1024/1*ZAV8uladB_JeeIQnrPMgYA.png)
_-sV (Services)_

**3.** The Nmap below command is used to perform a fast scan on the target "scanme.nmap.org." Here's an explanation of the command:

- -F: The -F option is a shorthand for the "fast" scan mode. When you use this option, Nmap performs a quick scan focused on identifying the most common open ports and their associated services. This is also known as a "fast scan" or a "top 1000 ports" scan, and it's designed to be less time-consuming than a comprehensive scan.

```
nmap -F scanme.nmap.org
```

![](https://cdn-images-1.medium.com/max/1024/1*njXj1kivl-rYDudQnATVfQ.png)
_-F (fast mode)_

4. The Nmap below command is used to scan the target "[www.google.com](http://www.google.com/)" while displaying only the open ports. Here's an explanation of the command:

- --open: The --open option instructs Nmap to display only the open ports and services discovered during the scan. This means that it will filter out closed or filtered ports from the scan results, providing a concise list of the open ports that are actively accepting connections.
- www.google.com: This is the target hostname or domain name, in this case, "[www.google.com](http://www.google.com/)." The scan is performed on Google's web servers.

```
nmap --open www.google.com
```

![](https://cdn-images-1.medium.com/max/1024/1*vX7MIDshEG4xXUsdVb7SNw.png)
_— open (shows open ports)_

### Resources:

- [Download the Free Nmap Security Scanner for Linux/Mac/Windows](https://nmap.org/download.html)
- [HackerSploit Blog](https://hackersploit.org/)