nmap Command in Linux
Build an AI-First Career, Master the Complete Skillset
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
AI Forward Deployed Engineer Program
Full-stack engineering, production AI and client-facing consulting
+1000 moreOverview
The nmap command in Linux is a flexible, powerful, and indispensable tool used for network discovery and security auditing. Short for Network Mapper, nmap is employed by network administrators across the globe to explore networks, perform security scans, detect open ports, and so much more.
Syntax of nmap Command in Linux
The basic syntax of the nmap command in Linux is as follows:
Where:
- [Scan Type]: This part denotes the type of scan you want to perform. Different types of scans include SYN scan (-sS), TCP scan (-sT), and UDP scan (-sU), among others.
- [Options]: These are additional parameters that modify the behavior of the nmap command.
- {target specification}: This is the hostname, IP address, or range of IPs you want to scan.
Options in nmap Command in Linux
-
-p: This option specifies the port range to be scanned.
For example -
Output:
This command scans the IP address 192.168.0.1 on ports 22, 80, and 443. The output shows that ports 22 and 443 are open, and 80 is closed.
-
-sV: This option enables version detection.
For example -
Output:
This command detects services and their versions running on open ports.
-
-O: This option enables OS detection.
For example -
Output:
This command tries to determine the operating system of the host 192.168.0.1.
How Scaler Transformed Careers in Different Fields
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Example Usages
-
Scanning a single host:
Output:
Explanation: This command performs a basic scan of the host 192.168.0.1. The output shows the open ports and their services.
-
Scanning multiple hosts:
Output:
Explanation: This command scans multiple hosts (192.168.0.1 and 192.168.0.2) and provides individual reports for each.
Tips
-
Always use nmap in a legal and ethical manner. Scanning networks without permission is illegal and unethical.
-
Use the '-v' flag for verbose output, helpful in understanding what's happening during the scan.
-
Utilize '-oN' to save the scan output to a file.
Turn Learning into Career Growth
Advanced Use Cases of nmap Command in Linux
-
Ping sweep to discover hosts in a network:
Output:
Explanation: This command performs a ping sweep in the 192.168.0.1/24 subnet, identifying hosts that are up.
-
Script scanning using the Nmap Scripting Engine (NSE):
Output:
Explanation: This command runs a script 'http-title' from the NSE that fetches the title of the web page running on the target host.
-
Stealth scanning using SYN scan:
Output:
Explanation: This command performs a stealthy SYN scan, which is less likely to be logged than a standard scan.
Conclusion
-
The nmap command in Linux is a versatile tool for network exploration and security auditing.
-
It offers a variety of features, from basic scanning and version detection to advanced uses like OS detection and scripting.
-
While powerful, it should always be used responsibly and ethically, respecting network permissions.