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.
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.
apt-get update && apt-get install -y iproute2 python3dnf install -y iproute python3pacman -Sy --noconfirm iproute2 pythonList 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.
ss -tulnAdd -4 or -6 to restrict output to IPv4 or IPv6, and -H to drop the header line, which helps in scripts.
ss -tlnH4See 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.
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:
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.
ss -tn state establishedFilter 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:
ss -o state established '( dport = :ssh or sport = :ssh )'-o adds timer information for each socket.
Other useful options
-eadds extended details: the user ID, inode and socket cookie.-ishows internal TCP information such as the congestion algorithm, RTT and MSS.-sprints summary statistics.
ss -sRelated reading
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
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.