Discover open ports and running services on target systems using various scanning techniques and timing options. This is the first active reconnaissance step after identifying live hosts, providing the foundation for service enumeration and exploitation.
# Find NSE scripts location ls /usr/share/nmap/scripts/
# Find all scripts for a specific service locate -r '\.nse$' | xargs grep categories | grep smb
# Find default/version scripts for a service locate -r '\.nse$' | xargs grep categories | grep 'default\|version' | grep smb
# Find script by name pattern find / -type f -name ftp* 2>/dev/null | grep scripts
Notes
Always run Nmap as root for full functionality. By default, Nmap scans the top 1000 TCP ports with SYN scan (-sS) when run as root. Without root privileges, it falls back to TCP connect scan (-sT) which is less stealthy and requires completing the full TCP handshake.
OS Detection via TTL values:
TTL 64: Linux/macOS
TTL 128: Windows
TTL 255: Network devices (routers, switches)
Scan optimization tips:
Use -oA to save all output formats for later analysis
Combine -sV and -A for comprehensive service and OS fingerprinting
Use --reason flag to understand why ports are marked as open/closed/filtered
Closed ports respond with RST; filtered ports typically don’t respond (firewall)
Reducing scan time helps evade IDS detection
Increasing speed may trigger security alerts
Performance considerations:
--min-rate sets minimum packets per second (faster scans)
--max-retries limits probe retransmissions (faster but less accurate)
-T4 is recommended for most LAN scans
-T2 or lower for stealth and IDS evasion
Fragment packets (-f) and decoys (-D) help evade firewalls