After setting up a VPS, I wanted to confirm that only the ports I meant to expose were reachable from the internet. The quickest way is to scan it from outside with nmap.
What is nmap?
nmap is a command-line network scanner. You give it a host and a list of ports, and it reports the state of each one. Run it from your laptop, not from the server, so you see what the internet sees.
Install it with Homebrew:
brew install nmap
Scan the ports
nmap -Pn -p 22,80,443,6001,6002,8000,8080 <your-vps-ip>
-Pnskips the ping check and scans the ports anyway. Many servers block ping, and without this flag nmap may report the host as down.-pis the list of ports to scan.
Reading the result
22/tcp open
80/tcp open
443/tcp open
6001/tcp filtered
6002/tcp filtered
8000/tcp filtered
8080/tcp filtered
- open: something is listening and the port is reachable.
- closed: the port is reachable, but nothing is listening on it.
- filtered: a firewall is dropping the traffic, so nmap can’t tell.
For a typical web server, this is what I want. SSH (22), HTTP (80) and HTTPS (443) are open, and internal ports like 6001, 6002, 8000 and 8080 are filtered by the firewall.
If an internal port shows up as open, fix the firewall rule before anything else.