Check Exposed Ports on Your Server
In this article
Checking exposed ports on your server tells you which services are reachable from the internet (or your local network) and which ones might be unintentionally open. This is a key step in securing any server. The quickest way is to use a network scanning tool like nmap from your own computer, or to check listening ports directly on the server with ss or netstat. Below are the steps for both approaches, plus how to interpret the results.
What You'll Need
- Access to your server via SSH (Linux/Unix) or Remote Desktop (Windows).
- Your server's IP address or hostname.
- A local computer (your laptop/desktop) with internet access.
- Optional:
nmapinstalled on your local computer. If not installed, you can use online port scanners (but be cautious with sensitive servers).
Step-by-Step
Method 1: Check Listening Ports on the Server Itself
- Log into your server via SSH (for Linux) or RDP (for Windows).
- Open a terminal or command prompt.
- Run the appropriate command to list listening ports:
- Linux (modern):
ss -tuln(shows TCP and UDP listening ports with numeric addresses). - Linux (older):
netstat -tuln(ifssis not available). - Windows:
netstat -an | findstr LISTENING(in Command Prompt) orGet-NetTCPConnection -State Listenin PowerShell.
- Linux (modern):
- Interpret the output. Look for lines where the local address is
0.0.0.0or::(meaning the service is bound to all interfaces, so it's reachable from outside). Note the port numbers and the process names (if shown). For example,0.0.0.0:22means SSH is exposed on all interfaces. - Cross-reference with running services. Use
ps aux | greporlsof -i :(Linux) to see which process is using each port.
Method 2: Scan from Your Local Computer (External View)
- Install nmap on your local computer if you don't have it:
- Windows: Download from the official nmap.org site.
- macOS:
brew install nmapor download from nmap.org. - Linux: Use your package manager, e.g.,
sudo apt install nmap(Debian/Ubuntu) orsudo yum install nmap(RHEL/CentOS).
- Run a basic scan from your local terminal:
nmap -sS(this is a stealth SYN scan, requires admin/root on your local machine). If you don't have admin rights, usenmap -sT(TCP connect scan). - Wait for the scan to finish. It may take a few seconds to a few minutes depending on the number of ports.
- Read the output. The output shows open ports and the service usually associated with them (e.g., 22/tcp ssh, 80/tcp http, 443/tcp https). If a port is filtered, it means a firewall is blocking your scan, but the port might still be open to the internet.
Method 3: Check Your Firewall Rules (Optional but Important)
- On the server, list the firewall rules to see which ports are explicitly allowed:
- Linux (ufw):
sudo ufw status - Linux (firewalld):
sudo firewall-cmd --list-all - Windows Firewall:
netsh advfirewall firewall show rule name=all(may be long; use specific filters).
- Linux (ufw):
- Compare with the listening ports. A port can be listening but blocked by the firewall (so not actually exposed), or the firewall may allow a port that nothing is listening on (so no service is exposed). The real exposure is the intersection of listening ports and firewall rules that allow inbound traffic.
Common Mistakes
- Only checking localhost: Running
ss -tulnshows all listening ports, but if a service is bound to127.0.0.1only, it's not exposed externally. Make sure you look for0.0.0.0or::addresses. - Forgetting about UDP ports: Many scans default to TCP only. Use
nmap -sUto scan UDP ports (but this can be slow). - Assuming nmap output is the whole story: If a port shows as "filtered," it might still be open but firewalled from your location. Always check the server's firewall rules.
- Not considering IPv6: A service bound to
::is exposed over IPv6. Check both IPv4 and IPv6. - Scanning from the server itself: Scanning your own server from itself (e.g.,
nmap localhost) only shows what's listening, not what's externally reachable. You need an external scan for a true exposure check.
Tips
- Use a port range: To scan common ports only, use
nmap --top-ports 1000to keep it fast. - Identify unknown ports: If you see an open port you don't recognize, look it up in the IANA service name registry, and check the process using it on the server.
- Close unnecessary ports: For any port that is open but not needed, disable the service or block it in the firewall.
- Regularly audit: Make this a monthly routine, especially after installing new software or changing firewall rules.
- Use a cloud provider's security group: If your server is in the cloud, also review the security group / network ACL settings in the cloud console, as these act as an external firewall.
Troubleshooting
If nmap shows no open ports but you expected some:
- Check that the service is actually running on the server (
systemctl statuson Linux, or Services.msc on Windows). - Verify the service is bound to the correct interface. If it's bound to
127.0.0.1, it won't be reachable externally. - Check the server's firewall and the cloud security group. There might be a rule blocking inbound traffic.
- Try scanning from a different network (e.g., mobile hotspot) to rule out your local network blocking outbound scans.
If nmap shows a port as "filtered":
- This usually means a firewall is dropping packets. Check the server's firewall and the cloud security group. If you want to allow that port, add an allow rule.
- Note that some ISPs block certain ports (like 25 for email). This is outside your control.
If you get "Permission denied" when running nmap:
- On Linux/macOS, use
sudofor SYN scans. Alternatively, use-sTwhich doesn't require root. - On Windows, run the command prompt as Administrator.
If the server has no internet access:
- You can still check listening ports locally, but you cannot do an external scan. Use a friend's computer or an online port scanning service (but be careful with production servers).
Frequently Asked Questions
What is the difference between a listening port and an exposed port?
A listening port is one where a service is actively accepting connections on the server. An exposed port is a listening port that is reachable from outside the server (i.e., not blocked by a firewall or bound only to localhost).
Can I check exposed ports without installing any software?
Yes, you can use built-in commands like ss or netstat on the server to see listening ports. To check external exposure, you can use an online port scanner (like portchecker.co) from your browser, but be aware that these only test a limited set of ports and may not be as reliable as nmap.
Is it safe to use an online port scanner?
Generally yes, but only use reputable services. Be cautious about entering your server's IP on unknown websites, as they could log it. For production servers, prefer using nmap from your own machine.
How often should I check exposed ports?
It's a good practice to check after any configuration change, after installing new software, and at least monthly as part of a security routine. Also check when you suspect a breach or unusual activity.
What should I do if I find an open port I didn't expect?
First, identify the process using that port (lsof -i : or netstat -ano on Windows). If it's not a service you recognize, investigate immediately. If it's unnecessary, disable the service and block the port in your firewall. If you can't identify it, consider a full security audit.
Does exposing a port automatically mean it's vulnerable?
No, but it increases your attack surface. The service running on that port might be secure, but any exposed port is a potential entry point. Always keep software updated and use strong authentication.