Every hacking tutorial, every CTF write-up and every penetration test starts in the same place: Nmap. Before you can attack a service, you need to know it exists. Nmap tells you which machines are alive, which ports are open, and what software is running behind them.
In this guide you'll run your first real scans, learn to read the output properly, and pick up the 10 options you'll use in almost every lab.
Before you scan anything: the rule
Only scan machines you own or have written permission to test. Scanning a random website or your college network is not harmless "practice". Port scans are logged, and in India unauthorised access attempts can fall under the IT Act.
Legal places to practise:
- your own lab VMs (Metasploitable, DVWA, any vulnerable machine you download)
- TryHackMe and Hack The Box machines, over their VPN
scanme.nmap.org, a server the Nmap project lets you scan lightly for learning
All examples here use a Metasploitable VM at 192.168.56.101 on a private host-only network.
Step 1: find the live hosts
On a new network, first find out which machines are switched on:
nmap -sn 192.168.56.0/24
-sn means "no port scan, just tell me who's up". The /24 means all 256 addresses from 192.168.56.0 to 192.168.56.255. You'll get a short list of IPs. Pick your target.
Step 2: your first port scan
nmap 192.168.56.101
With no options, Nmap scans the 1,000 most common TCP ports. That's fast, and usually enough to start. If you run it with sudo, Nmap uses a SYN scan (it never completes the TCP handshake). Without sudo, it uses a full TCP connect scan. Both work in a lab.
Step 3: find out what's running
An open port alone doesn't tell you much. Add -sV to detect the actual software and version:
nmap -sV 192.168.56.101
Here's how to read that output:
- Host is up means the target replied. The latency tells you it's on your local network.
- Not shown: 977 closed tcp ports means Nmap hid the boring ones so you can focus.
- The table is the important part: port number, state, service name and version.
The version is your clue. vsftpd 2.3.4, for example, is a famous old FTP server version with a known backdoor. In a real assessment you'd note every version and search it for known vulnerabilities (CVEs) before trying anything.
What open, closed and filtered really mean
- open: a program is listening and answered. This is where you look next.
- closed: the machine replied, but nothing is listening there. Still useful: it proves the host is alive.
- filtered: no reply at all. Usually a firewall is silently dropping the packets.
- open|filtered: Nmap can't tell which. You'll see this a lot with UDP scans.
Step 4: scan every port
The default 1,000 ports miss things. Services often hide on unusual ports like 8080, 8443 or 31337. In labs, always scan all of them:
nmap -p- 192.168.56.101
-p- means all 65,535 TCP ports. It's slower, so a common workflow is: scan all ports fast first, then run a detailed scan only on the ones that are open:
nmap -p- -T4 192.168.56.101
nmap -sC -sV -p 21,22,80,445,3306 192.168.56.101
Step 5: let the scripts dig deeper
Nmap has hundreds of scripts (the NSE, Nmap Scripting Engine). -sC runs the default set, which is considered safe. They grab page titles, check for anonymous FTP login, list SMB shares and more.
nmap -sC -sV 192.168.56.101
Want to see what's available? The scripts live in /usr/share/nmap/scripts/. Try:
ls /usr/share/nmap/scripts/ | grep smb
Step 6: save your results
Never scan the same machine twice just because you forgot what it said. Save everything:
nmap -sC -sV -oA scans/box1 192.168.56.101
-oA saves three files at once: normal text (.nmap), a grep-friendly version (.gnmap) and XML (.xml). Put them in your notes folder for that machine.
The 10 options you'll use most
| Option | What it does |
|---|---|
-sn | Find live hosts only |
-p 22,80 | Scan specific ports |
-p- | Scan all 65,535 TCP ports |
-sV | Detect service versions |
-sC | Run default scripts |
-O | Guess the operating system (needs sudo) |
-A | Versions, scripts, OS and traceroute together |
-Pn | Skip the "is it alive" check |
-T4 | Faster timing for stable networks |
-oA name | Save output in three formats |
And one more for later: sudo nmap -sU --top-ports 50 <target> scans the most common UDP ports. UDP is slow and easy to forget, which is exactly why services like SNMP on UDP 161 get missed.
Common beginner mistakes
- Only scanning the top 1,000 ports and missing the service on port 8081.
- Using
-Aon everything. It's loud and slow. In a real test, noise gets you noticed. - Not saving output and re-running scans for no reason.
- Trusting the service name blindly. Nmap guesses "http" for port 80, but anything can run on any port.
-sVchecks properly. - Scanning things you don't own. Don't.
What to do next
- Set up a free home lab with Kali and Metasploitable.
- Run every command in this post against it, and save the output.
- For each open port, write one line in your notes: service, version, and one thing you'd research.
That last step, turning scan results into a plan, is what separates people who run tools from people who understand them.