Skip to content
zefıly
← All posts

How to check open ports on a Linux server (and which are normal)

4 min read

Every listening port is a door. How to list them with ss, how to read the output, which ports a web server should have open, which ones are a warning sign, and how to check from the outside what the internet really sees.

"Is anything open that should not be?" is a question you can answer in two minutes, and should answer after every installation. A package that starts a service on all interfaces is the most common way a database ends up on the internet.

In short

  • sudo ss -tulpn lists every listening port with the program behind it.
  • The address matters as much as the port: 127.0.0.1 is local only, 0.0.0.0 and [::] are everybody.
  • A web server needs 22, 80 and 443. Almost nothing else should be reachable from outside.
  • Check from another machine too. The firewall decides what the internet sees.

1. List what is listening

sudo ss -tulpn
  • -t TCP, -u UDP
  • -l listening sockets only
  • -p the process (needs sudo)
  • -n numbers instead of names

On a fresh Ubuntu 26.04 system with only PostgreSQL installed, we got:

Netid State  Local Address:Port  Process
tcp   LISTEN     127.0.0.1:5432
tcp   LISTEN         [::1]:5432

PostgreSQL listens on 127.0.0.1 and [::1] only. That is the safe default: programs on the server can connect, the internet cannot.

2. Read the address column

Local address Who can connect
127.0.0.1:port, [::1]:port Only programs on this server
0.0.0.0:port, *:port Anybody, over IPv4
[::]:port Anybody, over IPv6 (and often IPv4 too)
10.x.x.x:port, 192.168.x.x:port The private network

A port on 127.0.0.1 is not a risk from outside. A port on 0.0.0.0 is one firewall rule away from the internet, or already on it.

3. What is normal on a web server

Port Service Should listen on
22 SSH all interfaces, firewall limited to you if possible
80, 443 web server all interfaces
443/udp HTTP/3 all interfaces, if you use it
3306 MariaDB / MySQL 127.0.0.1
5432 PostgreSQL 127.0.0.1
6379 Redis / Valkey 127.0.0.1
9000 or a socket PHP-FPM 127.0.0.1 or a Unix socket
3000, 8000, 8080… your apps 127.0.0.1, behind the web server
53 on 127.0.0.53 systemd-resolved local only, normal
25 on 127.0.0.1 local mail local only, normal

4. Warning signs

  • A database on 0.0.0.0. MariaDB, PostgreSQL, Redis, MongoDB, Elasticsearch and Memcached on a public address are found and attacked within hours. Redis without a password on the internet is a classic way to lose a server.

  • A container port. docker run -p 5432:5432 publishes on all interfaces, and Docker writes its own firewall rules that go around ufw. Write -p 127.0.0.1:5432:5432.

  • An admin panel on a high port (8080, 8443, 9090, 10000) that you forgot.

  • A process you do not recognise. Look it up before you do anything else:

    sudo ss -tulpn | grep ':4444'
    ps -fp <pid>
    sudo ls -l /proc/<pid>/exe
    

    A program running from /tmp or a hidden directory, or one whose file was deleted, is a reason to treat the server as compromised.

5. Fix it at the source

A firewall rule hides the port; a bind address removes it. Do both, but start with the service:

  • MariaDB: bind-address = 127.0.0.1
  • PostgreSQL: listen_addresses = 'localhost'
  • Redis / Valkey: bind 127.0.0.1 -::1
  • Your app: listen on 127.0.0.1 and let the web server proxy to it.

Then restart the service and run ss again.

If a service must be reachable from another server, bind it to the private network address and allow only that server's address in the firewall.

6. Check from outside

ss shows what listens. The firewall decides what arrives. From another machine:

nmap -Pn -p- your-server-ip

This scans all 65,535 TCP ports of your own server. Scan only servers you are responsible for. The result should be short: 22, 80, 443.

Check IPv6 separately (nmap -6). Firewall rules for IPv4 do not cover IPv6, and many forgotten open ports are open only there.

7. Make it a habit

Run the check after every installation and every new container. Better, have it run by itself and tell you when something new appears.

With Zefily

Zefily checks the open ports of every connected server and shows them in the Security center: which ports listen, on which addresses, and which program is behind them. Ports that Zefily opened itself are marked as expected. A new port that is reachable from outside raises a notice; one that the firewall already blocks does not send an email. See Security center and Firewall and users.

Frequently asked questions

How do I see open ports on Linux?

Run sudo ss -tulpn. It lists listening TCP and UDP ports with their address and the process behind each.

What is the difference between 127.0.0.1 and 0.0.0.0 in the port list?

A service on 127.0.0.1 accepts connections only from the server itself. On 0.0.0.0 it accepts them from any address, unless a firewall blocks them.

Which ports should a web server have open to the internet?

22 for SSH, 80 and 443 for the web. Databases, caches and application ports should listen on 127.0.0.1.

Does ufw protect ports published by Docker?

Not by default. Docker adds its own rules that bypass ufw. Publish container ports on 127.0.0.1 unless they must be public.

How do I check which ports are reachable from outside?

Scan your own server from another machine, for example with nmap -Pn -p- and the server's address, and repeat for IPv6.

See Monitoring and alerts for the notices Zefily sends.

More posts

Black Friday & Cyber Monday

Before you go: lifetime plans are on sale

Pay once for a lifetime plan, or get 30% off the first year of any yearly plan.

Only 100 lifetime plans per plan. When they are gone, they are gone.

See the campaign

Amazing November

See the campaign →