Check which ports are open and listening on Linux
Use ss and lsof to list every listening port on your VPS, find the process behind each one, tell localhost from public bindings and close what you do not need.
- Beginner
- Linux VPS
- 4 min read
Every listening port is a door into your server. Knowing which doors exist, and which program opened each one, is the first step in securing a VPS. This guide shows you how to list listening ports, find the process behind them, tell private from public bindings and close the ones you do not need.
Before you start
- A RunRacks Linux VPS running Ubuntu 22.04/24.04, Debian 12, or AlmaLinux/Rocky Linux 8 or 9.
- An SSH session as root or a sudo user. Without
sudo, the tools cannot show which process owns ports opened by other users.
List listening ports with ss
ss is installed by default on every current distribution and replaces the older netstat.
sudo ss -tulpnThe flags mean:
-tTCP sockets,-uUDP sockets.-llistening sockets only.-pshow the process using each socket.-nshow port numbers instead of service names.
Example output, trimmed:
Netid State Local Address:Port Peer Address:Port Process
udp UNCONN 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=512,fd=13))
tcp LISTEN 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=801,fd=3))
tcp LISTEN 127.0.0.1:3306 0.0.0.0:* users:(("mariadbd",pid=950,fd=20))
tcp LISTEN 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=1020,fd=6))
tcp LISTEN [::]:22 [::]:* users:(("sshd",pid=801,fd=4))To filter for one port:
sudo ss -tlnp 'sport = :443'netstat -tulpn gives similar output but needs the net-tools package, which is not installed by default on new systems. ss is the better habit.
Read the local address
The Local Address column tells you who can reach the port.
0.0.0.0:80or*:80: every IPv4 address on the server. Reachable from the internet unless the firewall blocks it.[::]:80: every IPv6 address, and on many systems IPv4 too.127.0.0.1:3306or[::1]:3306: localhost only. Programs on the server can connect; the internet cannot, regardless of firewall rules.127.0.0.53%lo:53: the local DNS stub resolver on Ubuntu. It is normal and only local.- A specific IP, such as
203.0.113.10:8080: only that address.
Databases, caches such as Redis and admin dashboards should normally listen on 127.0.0.1. If you see them on 0.0.0.0, they are relying entirely on the firewall.
Find the process that owns a port
The ss -p column already shows the process name and PID. For more detail, use lsof:
sudo lsof -i :80 -P -nIf lsof is missing, install it:
sudo apt install lsof # Ubuntu and Debian
sudo dnf install lsof # AlmaLinux and Rocky LinuxOnce you have the PID, find the systemd service that started it:
systemctl status 1020The first line names the unit, for example nginx.service. You can also see the full command line:
ps -o pid,user,cmd -p 1020Check what the internet sees
Local tools show what listens. The firewall decides what is reachable. Combine both views:
- List your firewall rules, for example
sudo ufw statusorsudo firewall-cmd --list-all. - From another machine, test a port:
nc -vz -w 5 203.0.113.10 3306- For a broader scan of your own server, run
nmapfrom another machine you control:
nmap -Pn 203.0.113.10Only scan servers you own or have permission to test. Scanning other people's systems can break their terms of service and local law.
Close ports you do not need
You have three options, from best to weakest:
- Stop and disable the service if you do not use it:
sudo systemctl disable --now cups- Bind it to localhost if only local programs need it. For example, in MariaDB set
bind-address = 127.0.0.1and restart. - Block it in the firewall if it must listen publicly but only some clients should connect.
Never stop sshd or block your SSH port while connected over SSH. If you lose access, use the browser console in your Dashboard.
Check it works
Run the list again after each change:
sudo ss -tulpnThe port should be gone, or show 127.0.0.1 instead of 0.0.0.0. From outside, nc -vz should now time out or be refused.
Troubleshooting
- The process column is empty: you ran
sswithoutsudo. Run it again withsudo. - A port shows up but no service file owns it: it may be a container. Run
docker psand check thePORTScolumn. - Port comes back after reboot: you stopped the service but did not disable it. Use
systemctl disable --now. - Port 53 on 127.0.0.53: this is
systemd-resolvedon Ubuntu. Leave it alone unless you know you need to replace it. - Port is closed locally but still open from outside: another server or a NAT rule is answering. Check the IP you are testing.
Next steps
- Shrink the list further: Close unused ports and disable unneeded services.
- Learn what each number means: Common server ports and what uses them.
- Lock the rest down: Open ports with UFW.
- Compare Linux VPS plans.
Was this guide helpful?
Still stuck?
Ask RunRacks AI for a quick answer, or open a ticket and our team will take a look at your server.
Related guides
Networking & DNS
Set your server hostname and reverse DNS
Change the server's hostname, point DNS records at your IP, set reverse DNS in the control panel and check that forward and reverse lookups match.
- Intermediate
- Linux VPS
- 2 min read
Networking & DNS
Reduce latency to your broker: location and ping checks
Find where your broker's trade servers are, choose the nearest location, and measure latency from the VPS with MetaTrader, ping and tracert.
- Beginner
- Admin RDP · Windows VPS
- 3 min read
Networking & DNS
Port speed vs bandwidth: what network specs mean
Learn what port speed in Mbps or Gbps, monthly transfer and real-world throughput mean, so you can read the network specs on any hosting plan with confidence.
- Beginner
- All
- 4 min read