Skip to content
Log In Sign Up info@muvcloud.com

List Listening Ports with ss

sudo ss -tulpn
  • -t and -u: TCP and UDP sockets.
  • -l: only sockets that listen, not established connections.
  • -p: the process that owns each socket; sudo is needed to see other users' processes.
  • -n: numbers instead of service names, so port 22 shows as 22, not ssh.

To check one port, filter the output: sudo ss -tlnp | grep ':443 '. ss is part of iproute2 and present on every current distribution.

Read the Local Address Column

Local addressWho can connect
127.0.0.1:3306Only programs on the server
[::1]:6379Only the server, over IPv6
0.0.0.0:80Any IPv4 address, unless a firewall blocks it
[::]:80Any IPv6 address
*:80All addresses, IPv4 and IPv6
203.0.113.10:8080Only traffic sent to that address

A database, a cache, or an admin interface should usually listen on 127.0.0.1. A service on 0.0.0.0, [::], or * is exposed to the internet unless a firewall stops it. Whether an IPv6 wildcard socket also accepts IPv4 depends on the program and on the kernel setting net.ipv6.bindv6only, which is off by default. Current versions of ss print such a dual-stack socket as * and an IPv6-only one as [::]; programs such as sshd often open two sockets, one for each. The loopback address is explained in what is localhost.

Other Tools: lsof and netstat

sudo lsof -i -P -n | grep LISTEN
sudo netstat -tulpn

lsof shows the same sockets from the process side; -P and -n keep ports and addresses numeric, and the grep keeps TCP listeners, since UDP sockets have no LISTEN state. More in the lsof command. netstat comes from the older net-tools package, which current distributions no longer install by default; the options above match those of ss.

Test from Outside with nc

A port that listens is not necessarily reachable. Test from another machine you control, such as your own computer or a second server:

nc -zv your_server_ip 22
nc -zv your_server_ip 443
  • Succeeded or open: the port is reachable and a service answers.
  • Connection refused: the packet arrived, but nothing listens, or a firewall rejected it.
  • Timeout: a firewall dropped the packet on the way.

See the nc command for more options.

Scan Your Own Server with nmap

Scan only hosts you own or have written permission to test; scanning other people's systems can break laws and terms of service. From your own machine:

nmap -Pn your_server_ip
nmap -Pn -p- your_server_ip
sudo nmap -Pn -sU --top-ports 20 your_server_ip

The first command checks the 1,000 most common TCP ports, the second all 65,535, and the third the 20 most common UDP ports; UDP scans are slow and need root. -Pn skips the ping check, which a firewall may block. nmap reports each port as:

  • open: a service answers.
  • closed: the server answered, but nothing listens.
  • filtered: a firewall blocks the probes, usually by dropping them without an answer.

Why Inside and Outside Differ

  • Listening on 127.0.0.1: visible in ss, never reachable from outside.
  • The server firewall: ufw or firewalld can block a port that listens on 0.0.0.0.
  • A provider firewall: a firewall in front of the server can block ports before traffic arrives.
  • Docker: ports published with -p are opened by Docker's own rules and can be reachable even when ufw or firewalld denies them. Always test them from outside.

Close a Port You Do Not Need

  1. Find the program in the ss output. Never stop the SSH service you are connected through.
  2. If you do not need the program, stop and disable it: sudo systemctl disable --now SERVICE.
  3. If only the server uses it, set its listen or bind address to 127.0.0.1 in its configuration and restart it.
  4. If a few addresses need it, allow only those in the firewall; see how to open a port with UFW or how to use firewalld.
  5. Run ss and the outside test again to confirm.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations