How-to

How to Check Open Ports on a Linux Server

An open port is a program listening plus a firewall that lets traffic in. Check both: the socket list on the box and a scan from another machine.

What counts as an open port?

Three things decide whether a port is open to the world. A program must listen on it, it must bind to an address the outside can reach, and no firewall may drop the traffic on the way in. A database bound to 127.0.0.1 is listening but only reachable from the box itself. A web server on 0.0.0.0:80 is reachable unless the firewall blocks it. Checking all three avoids both false alarms and nasty surprises.

How do I list listening ports on the machine?

sudo ss -tulpn
sudo ss -ltn 'sport = :3306'

-t and -u pick TCP and UDP, -l shows listening sockets only, -p adds the owning process and -n keeps numbers instead of service names. The second line uses a filter expression to check one port. The ss command explains the filters in depth; the older The netstat command gives the same answer with netstat -tulpn if you have net-tools installed.

How do I read the Local Address column?

Local addressReachable from
0.0.0.0:443Every IPv4 address on the box, so the internet if the firewall allows
[::]:443 or *:443All addresses; on most systems this also accepts IPv4
127.0.0.1:6379Only programs on the same machine
203.0.113.10:8080Only that one address
%lo or %eth0 suffixBound to a specific interface

Your machine has one public IPv4 address, so in practice the question is simple: is the service bound to loopback or to everything? Databases, Redis, Memcached and admin panels should usually be on loopback or protected by the firewall.

Which program owns a port?

sudo ss -ltnp | awk 'NR==1 || /:25 /'
sudo lsof -nP -iTCP:25 -sTCP:LISTEN
sudo fuser -v 25/tcp

Any of the three names the process and PID. Then systemctl status <pid> tells you which service unit started it, so you can disable the unit rather than kill a process that will just come back. More lsof tricks are in lsof command.

Is the firewall letting the port through?

sudo ufw status numbered                 # Ubuntu, Debian with ufw
sudo firewall-cmd --list-all             # AlmaLinux, Rocky, CentOS Stream
sudo nft list ruleset | less             # what the kernel actually enforces

ufw and firewalld are both front ends to nftables in current releases, so nft list ruleset shows the real rules whatever tool wrote them. If ufw is inactive and no other rules exist, every listening port is reachable. On top of your own firewall, our network filters volumetric attacks at the edge, but it does not close ports for you; see Edge DDoS filtering.

How do I test from outside?

The only proof that counts is a connection from another network. From your laptop or a second server:

nc -zv -w 3 203.0.113.10 22 80 443 5432
nmap -Pn --top-ports 300 203.0.113.10
nmap -Pn -sU -p 53,123,161 203.0.113.10

nc -z tries a handful of ports and reports succeeded or refused. nmap scans ranges and classifies each port as open, closed or filtered. Filtered means a firewall dropped the probe; closed means the packet arrived but nothing listens. UDP scans are slow and less certain, so scan only the ports you care about. Scan only machines you own.

What should a fresh server show?

A new box from us with a clean image should list little more than SSH on port 22, plus a local resolver on 127.0.0.53 on Ubuntu and a chrony socket on loopback. Every port you add later should be on purpose. Make a habit of running ss -tulpn after each install; packages such as mail servers, rpcbind or database servers sometimes start listening on all addresses by default. Close what you do not need with Open a port in Linux in reverse, or bind it to loopback in its own config.

Can I watch for new listeners automatically?

sudo ss -Htuln | sort > /root/ports.baseline
sudo ss -Htuln | sort | diff /root/ports.baseline - && echo unchanged

Save a baseline once, then run the diff from cron and mail yourself any change. It is a cheap early warning that something new appeared, whether from a package upgrade or from a process that should not be there.

Machines With a Public IPv4 Ready for Your Services

ServerProcessorCores / threadsMemoryStorageNetworkPer monthSmallest order
E1Intel Xeon E3-1240 v34 / 816 GB DDR32x 240 GB SSD2x 1 Gbps$30.52$91.56 (3 months)
S2Intel Xeon E-2356G6 / 1264 GB DDR41x 1 TB NVMe2x 10 Gbps$58.39$58.39 (1 month)
S3Intel Xeon E-2356G6 / 1264 GB DDR42x 1 TB NVMe2x 10 Gbps$80.38$80.38 (1 month)

Keep Reading

The ss command

List sockets fast with ss: listening ports, filters by state, port and address, TCP internals like RTT, summaries and killing stuck sockets.

Open

lsof command

Use lsof to see which process holds a file, a port or a deleted log open, and free disk space without a reboot.

Open

Open a port in Linux

Open a TCP or UDP port on Ubuntu, Debian, AlmaLinux or Rocky with ufw, firewalld or nftables, then prove it works from outside.

Open

Firewall

What a firewall does, packet filters versus stateful and application firewalls, and the Linux tools that set the rules on a dedicated machine.

Open

FAQ

Quick Answers

sudo ss -tulpn. It shows TCP and UDP listeners with the owning process.

A firewall dropped the probe, so nmap cannot tell whether anything listens behind it.

It may be bound to 127.0.0.1, or the firewall drops it. Check the Local Address column and your rules.

On Linux, usually yes, because dual-stack sockets accept IPv4 unless bindv6only is set.

Scanning machines you rent and control is normal maintenance. Do not scan networks you do not own.