ss Command: List Listening Ports and Connections on Linux

Use ss to list listening TCP and UDP ports, see which process owns each socket, and filter established connections by state and port.

Tools Published 3 min read

The ss command shows the sockets on your machine: which ports are listening, which connections are open, and, when you ask for it, which process owns each one. This guide covers the handful of options that answer most questions.

The man page lists ss as part of the iproute2 project. The examples below were run in containers, so the output you see on a real host will differ.

Install ss

On most systems ss is already present. If not, install the package that ships it.

✓ tested · debian,ubuntu
apt-get update && apt-get install -y iproute2 python3
✓ tested · fedora
dnf install -y iproute python3
✓ tested · arch
pacman -Sy --noconfirm iproute2 python

List listening ports

Combine -l (listening only), -t (TCP), -u (UDP) and -n (numeric, no service-name lookup). Listening sockets are omitted by default, so -l is what you need here.

✓ tested · debian,ubuntu,fedora,arch
ss -tuln

Add -4 or -6 to restrict output to IPv4 or IPv6, and -H to drop the header line, which helps in scripts.

✓ tested · debian,ubuntu,fedora,arch
ss -tlnH4

See which process owns a port

Add -p to show the processes using each socket. The next blocks start a throwaway listener on port 8080, find it, and stop it.

✓ tested · debian,ubuntu,fedora,arch
python3 -m http.server 8080 --bind 127.0.0.1 >/dev/null 2>&1 &
sleep 2
ss -tlnp 'sport = :8080'

The output includes a users:(("python3",pid=...,fd=...)) field naming the process. Clean up afterward by killing the PID that ss reported:

✓ tested · debian,ubuntu,fedora,arch
kill $(ss -tlnpH 'sport = :8080' | grep -o 'pid=[0-9]*' | cut -d= -f2)

Show established connections

The -a option shows both listening and non-listening sockets. To narrow things down, use the state filter. The man page defines established, listening, time-wait, close-wait and other TCP states, plus the groups connected (everything except listening and closed) and all.

✓ tested · debian,ubuntu,fedora,arch
ss -tn state established

Filter by port

Filters follow the options. Predicates such as sport and dport compare source and destination ports, and src and dst match hosts. Combine them with and, or and not, and group with parentheses. This example is taken from the man page and lists established SSH connections in either direction:

✓ tested · debian,ubuntu,fedora,arch
ss -o state established '( dport = :ssh or sport = :ssh )'

-o adds timer information for each socket.

Other useful options

  • -e adds extended details: the user ID, inode and socket cookie.
  • -i shows internal TCP information such as the congestion algorithm, RTT and MSS.
  • -s prints summary statistics.
✓ tested · debian,ubuntu,fedora,arch
ss -s

If a service will not start because a port is taken, the listener list above is the first place to look. For other quick system checks, see Check disk usage on Linux with df, du and ncdu.

Sources

  1. ss(8) manual page, Linux man-pages project

#Ss #Iproute2 #Networking #Ports #Sockets

This article was drafted with AI assistance, fact-checked against the sources listed above and reviewed by a human editor before publication. Spotted an error? See our corrections policy.