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

By RunRacks Team · Published

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.

Terminal
sudo ss -tulpn

The flags mean:

  • -t TCP sockets, -u UDP sockets.
  • -l listening sockets only.
  • -p show the process using each socket.
  • -n show port numbers instead of service names.

Example output, trimmed:

Text
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:

Terminal
sudo ss -tlnp 'sport = :443'

Read the local address

The Local Address column tells you who can reach the port.

  • 0.0.0.0:80 or *: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:3306 or [::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:

Terminal
sudo lsof -i :80 -P -n

If lsof is missing, install it:

Terminal
sudo apt install lsof        # Ubuntu and Debian
sudo dnf install lsof        # AlmaLinux and Rocky Linux

Once you have the PID, find the systemd service that started it:

Terminal
systemctl status 1020

The first line names the unit, for example nginx.service. You can also see the full command line:

Terminal
ps -o pid,user,cmd -p 1020

Check what the internet sees

Local tools show what listens. The firewall decides what is reachable. Combine both views:

  1. List your firewall rules, for example sudo ufw status or sudo firewall-cmd --list-all.
  2. From another machine, test a port:
Terminal
   nc -vz -w 5 203.0.113.10 3306
  1. For a broader scan of your own server, run nmap from another machine you control:
Terminal
   nmap -Pn 203.0.113.10

Close ports you do not need

You have three options, from best to weakest:

  1. Stop and disable the service if you do not use it:
Terminal
   sudo systemctl disable --now cups
  1. Bind it to localhost if only local programs need it. For example, in MariaDB set bind-address = 127.0.0.1 and restart.
  2. Block it in the firewall if it must listen publicly but only some clients should connect.

Check it works

Run the list again after each change:

Terminal
sudo ss -tulpn

The 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 ss without sudo. Run it again with sudo.
  • A port shows up but no service file owns it: it may be a container. Run docker ps and check the PORTS column.
  • 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-resolved on 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

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.

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

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