Using nmap to Scan for Open Ports
nmap (Network Mapper) is the standard tool for discovering open ports and services on a server or network.
Install nmap
apt install nmap -y # Ubuntu/Debian
dnf install nmap -y # CentOS/RHEL
Basic Port Scan
nmap YOUR_SERVER_IP
Scans the 1,000 most common ports and shows which are open.
Scan All 65,535 Ports
nmap -p- YOUR_SERVER_IP
Scan Specific Ports
nmap -p 22,80,443,3306 YOUR_SERVER_IP
Detect Service Versions
nmap -sV YOUR_SERVER_IP
Shows the software and version running on each open port (e.g., nginx 1.24.0).
OS Detection
nmap -O YOUR_SERVER_IP
UDP Scan
nmap -sU -p 53,67,123,161 YOUR_SERVER_IP
Output Formats
nmap -oN output.txt YOUR_SERVER_IP # Normal text
nmap -oX output.xml YOUR_SERVER_IP # XML format
Verify Your Own Firewall Rules
Run nmap against your server from a different machine (or use an online nmap tool) to verify your firewall is blocking the ports you expect:
nmap -p 22,80,443,3306,5432 YOUR_SERVER_IP
Ports with status filtered are being blocked by the firewall. Ports with status closed are not blocked but nothing is listening.