A fresh VPS usually gets its first automated port scan within minutes of going online. Those bots aren't guessing; they're cataloguing every service you left listening. Learning how to check open ports in Linux takes one command, and closing the dangerous ones takes about 10 more minutes.
Quick Answer: Run
sudo ss -tulpn. Every line marked LISTEN is an open port, with the process that owns it in the last column. Ports bound to0.0.0.0or[::]accept connections from the whole internet, while127.0.0.1means local only. Stop services you don't need, rebind internal ones to localhost, then confirm the result with a scan from outside.
Last verified: October 2026, on Ubuntu 26.04.1 LTS and Ubuntu 24.04 LTS using
ss(iproute2),nmapand UFW.
Hostaccent's engineers resolve 20-30 client server issues every day (as of October 2026), and a fair share of the security tickets trace back to a port nobody remembered opening. This guide is the same audit our team runs on servers we take over, written so you can do it yourself in about 60 seconds of terminal time.
What an Open Port Means and Which Ones Are Risky
An open port is a network socket that a program has bound to and is listening on, waiting for TCP connections or UDP packets. Linux numbers them from 0 to 65,535. The number alone doesn't tell you the risk. The bind address does.
As of 2026, the most useful thing to read in any Linux port listing is the local address column. A service bound to 0.0.0.0 (IPv4) or [::] (IPv6) answers anyone who can reach the server, while one bound to 127.0.0.1 or [::1] only talks to programs on the same machine. A database on 0.0.0.0:3306 is an invitation. The same database on 127.0.0.1:3306 is invisible from outside.
| Port | Usual service | Public on a typical web server? |
|---|---|---|
| 22/tcp | SSH | Yes, but hardened (keys only, ideally IP-limited) |
| 80, 443/tcp | Nginx or Apache (HTTP, HTTPS) | Yes |
| 25, 587/tcp | SMTP mail (Exim, Postfix) | Only if this server handles mail |
| 21/tcp | FTP | Rarely; SFTP over port 22 replaces it |
| 3306/tcp | MySQL or MariaDB | No, bind it to localhost |
| 5432/tcp | PostgreSQL | No, bind it to localhost |
| 6379/tcp | Redis | Never |
| 3000, 8080, 9000/tcp | Node apps, dev servers, admin tools | Usually no; proxy them through Nginx |
Control panels change the picture. A cPanel or Plesk box legitimately opens a longer list (2083, 2087, 8443 and others), which is part of a proper cPanel server setup rather than a sign of trouble.
How to Check Open Ports in Linux With ss (and netstat)
As of 2026, sudo ss -tulpn is the standard way to list open ports on Ubuntu, Debian, AlmaLinux and every other current distribution. It ships in the iproute2 package that's already installed, covers TCP and UDP over IPv4 and IPv6 in one pass, and names the process behind every port that's actually listening.
The ss -tulpn command, flag by flag
bashsudo ss -tulpn
-tand-ushow TCP and UDP sockets-llimits the output to listening sockets-pshows the process name and PID (it needs sudo for other users' processes)-nprints numbers instead of resolving names, which is faster and clearer
Here's typical output from a small web server, trimmed to the useful columns:
textNetid State Local Address:Port Process tcp LISTEN 0.0.0.0:22 users:(("sshd",pid=812,fd=3)) tcp LISTEN 0.0.0.0:80 users:(("nginx",pid=1044,fd=6)) tcp LISTEN 127.0.0.1:3306 users:(("mariadbd",pid=930,fd=21)) tcp LISTEN 0.0.0.0:6379 users:(("redis-server",pid=977,fd=6))
SSH and Nginx are public on purpose, MariaDB is safely local, and that Redis line is the one to fix today. The full list of filters lives in the ss manual page.
Pro Tip: On Ubuntu 24.04 and later, port 22 may show
systemdwith pid 1 instead ofsshd. That's SSH socket activation (systemd holds the socket and starts sshd on demand), so don't go hunting for a rogue process.
The netstat listening ports Linux admins still use
sudo netstat -tulpn gives the same picture with the same flags, but it comes from the old net-tools package, which minimal Ubuntu and Debian server images no longer install. Add it with sudo apt install net-tools if muscle memory insists.
Find which process is using a port
When the full list is noisy, filter on one port:
bashsudo ss -tlnp 'sport = :6379' sudo lsof -i :6379 systemctl status 977
The last command maps the PID to its systemd unit, which tells you what started the service and whether it comes back on boot.
Still working through this server issue?
Send the symptoms, error output, and what you have already tried. We can work with Hostaccent services or infrastructure hosted with another provider.
Check From the Outside: The Who-Where-Why Port Test
A local listing shows what's listening; only an outside scan shows what's reachable. A firewall can hide a listening port, and Docker can expose one your firewall claims to block, so the two views don't always agree.
Run a scan against your own server
From your laptop or a second server (only ever scan machines you own):
bashnmap -Pn -p- your.server.ip
-p- checks all 65,535 TCP ports and -Pn skips the ping check that many VPS firewalls drop. A full scan typically takes 2-10 minutes. Ports reported as open are reachable, while filtered means a firewall dropped the probe. Nmap's guide to port-scanning basics explains every state. Skip nmap localhost: scanning from inside the server goes around the firewall and proves nothing about exposure.
Why does nmap show a port my firewall supposedly blocks?
In our experience, it's almost always Docker. Published container ports (-p 5432:5432) are routed by Docker's own iptables rules before UFW's rules ever see the packet, a behaviour the Docker documentation on packet filtering and firewalls describes plainly. Running ufw deny 5432 does nothing for that container. Publish internal containers on localhost instead, with -p 127.0.0.1:5432:5432.
The three questions
The Who-Where-Why test is the three-question check our team uses when auditing a server: who owns each open port (a process you recognise), where it's bound (public 0.0.0.0 or private 127.0.0.1), and why an outside machine needs to reach it at all. A port that fails even 1 of the 3 questions should be stopped, rebound to localhost or firewalled.
How to Close Risky Open Ports Without Locking Yourself Out
The safest order for closing risky ports on a Linux server in 2026 is simple: stop the service if nothing needs it, rebind it to 127.0.0.1 if only local apps use it, and add a firewall rule only as a backstop. On a typical single-site VPS, the whole cleanup takes about 10 minutes.
Across the 4,000+ sites Hostaccent has migrated, one of the leftovers we find most often is a database or Redis instance listening on 0.0.0.0 because an old tutorial said to "allow remote connections". Usually nothing connects to it remotely at all.
1. Stop services you don't use
bashsudo systemctl disable --now rpcbind
Swap in whatever unit the "who" question flagged. disable --now stops it immediately and keeps it from returning after the next reboot.
2. Rebind internal services to localhost
For MariaDB or MySQL, set this under [mysqld] (on Ubuntu, in /etc/mysql/mariadb.conf.d/50-server.cnf):
inibind-address = 127.0.0.1
For Redis, use bind 127.0.0.1 -::1 in /etc/redis/redis.conf. Restart the service, re-run sudo ss -tulpn, and the address column should now read 127.0.0.1. Your PHP or Node apps keep working because they connect locally anyway.
3. Close unused ports: firewall as the backstop
UFW makes a default-deny policy easy on Ubuntu, but the order matters:
bashsudo ufw allow OpenSSH sudo ufw allow 80,443/tcp sudo ufw default deny incoming sudo ufw enable sudo ufw status verbose
If SSH runs on a custom port, allow that number before you enable UFW, exactly as in our guide to changing the SSH port without locking yourself out. Keep your current session open and test a second login before closing the first. On AlmaLinux or Rocky, the firewalld equivalent is sudo firewall-cmd --permanent --remove-service=ftp followed by sudo firewall-cmd --reload. The UFW manual page covers rate limiting and per-IP rules.
Pro Tip: Keep port 80 open even on an HTTPS-only site. Let's Encrypt's HTTP-01 challenge connects on port 80, and blocking it is a classic cause of Certbot renewal failures that surface about 60 days later. Let Nginx redirect it to 443 instead.
If closing port 21 breaks a designer's FTP client, move them to SFTP instead of reopening it; for other login errors, see our fix for FTP 530 login authentication failed.
Verify, then recap
Finish by repeating both checks: sudo ss -tulpn on the server and the nmap scan from outside. A clean result shows only the ports your "why" answers justified.
- Read the bind address first: 0.0.0.0 and [::] are public, 127.0.0.1 is private.
- Trust an outside scan over your firewall's own status.
- Close at the source (stop or rebind) before you reach for a firewall rule.
- Always allow SSH before enabling a default-deny firewall.
Your Next Step: A Server With Engineers Behind It
Now that you know how to check open ports in Linux, the Redis-on-0.0.0.0 mistake won't slip past you. You can keep running this audit monthly yourself, or put your site on a server where a second pair of eyes is one ticket away. Hostaccent is a UK-registered company (hosting since 2016, UK-incorporated 2018), and 24/7 support comes from our own engineers. The Standard VPS at $12.00/mo gives you full root access and free 30 Gbps DDoS protection, and it renews at that same price. One honest caveat: no control panel licence is included, so if you want cPanel you'll buy that separately. Start on the Standard plan at $12.00/mo, with 30 days to change your mind.
Frequently Asked Questions
How to check open ports in Linux without root access?
Run ss -tuln as a normal user. You'll still see every listening port and its bind address, because Linux shares that information with all local accounts. What you lose is the process column, since the kernel only reveals the owning program for sockets your own account created. For the full audit, log in as a sudo-enabled user, add sudo and the -p flag, and the program name and PID appear beside each port.
Is netstat deprecated in Linux?
Effectively, yes. The net-tools package behind netstat is no longer installed by default on minimal Ubuntu 24.04 and 26.04 server images, and most distributions have pointed admins to ss for years. It still works once you run sudo apt install net-tools, and netstat -tulpn accepts the same flags. For new scripts and documentation, use ss instead: it reads socket data straight from the kernel, stays fast on busy servers, and supports richer filters.
What does 0.0.0.0 mean in ss output?
It means the service is listening on every IPv4 address the server has, including its public IP, so anyone on the internet can attempt a connection unless a firewall stops them. The IPv6 equivalent is [::], sometimes shown as an asterisk. Compare that with 127.0.0.1 or [::1], which only accept connections from the same machine. During an audit, treat every 0.0.0.0 or [::] line as public and make sure it has a reason to be.
Should I close port 22 on my server?
No, unless you have another way in, such as your provider's web console, because closing SSH is the quickest way to lock yourself out. Harden it instead: key-based logins only, password and root login disabled, Fail2ban rate limiting, and an IP allowlist if your address is stable. Moving SSH off port 22 cuts bot noise but replaces none of that. After a server rebuild, a host key verification failed warning is normal.
How often should I audit open ports on a VPS?
Run sudo ss -tulpn after every software install or config change, and do a full outside nmap scan at least once every 30 days. New packages sometimes open ports the moment they install (database servers, mail agents and monitoring tools are common culprits), and Docker Compose files change quietly. Save each scan's output to a dated file, so a simple diff against last month instantly shows any port that wasn't there before.












Discussion
Have a question or tip about this topic? Share it below — your comment will appear after review.