Something is listening on a port and you do not know what. A service is “up” but connections to it hang. A server has thousands of connections and you need to know which state they are in and who holds them. ss answers all three from the kernel’s own socket tables, and it does so in a fraction of the time netstat took, because it asks the kernel directly over netlink instead of reading and parsing /proc/net/tcp line by line. netstat has been unmaintained for years and is missing from a default install of most current distributions; ss ships in iproute2 alongside ip, so it is on every machine you will meet.
sudo ss -tulpnThat is the one most people know: tcp and udp sockets that are listening, with the process that owns each and numeric ports rather than service names. sudo is needed for the process column of sockets owned by other users; without it the column is simply blank for those rows, with no warning.
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
tcp LISTEN 0 10 127.0.0.1:9000 0.0.0.0:* users:(("ncat",pid=944,fd=3))
tcp LISTEN 0 5 127.0.0.1:8080 0.0.0.0:* users:(("python3",pid=942,fd=3))
tcp LISTEN 0 128 0.0.0.0:2024 0.0.0.0:*A local address of 0.0.0.0 or [::] means the socket accepts connections on every interface; 127.0.0.1 means only from this machine. That one column answers “is this reachable from outside” before any firewall question arises — Networking Basics walks the rest of that diagnosis.
The two columns that change meaning
On an established connection, Recv-Q is bytes received and not yet read by the application and Send-Q is bytes sent and not yet acknowledged by the peer. On a LISTEN row the same two columns mean something else entirely: Recv-Q is the number of completed connections waiting for the application to accept() them, and Send-Q is the size of that queue, the backlog. When the first number reaches the second, the kernel starts dropping new connection attempts silently, and clients see connects that succeed in whole-second steps or never. This was measured for this page with a listener that called listen(1) and never accept()ed, against four clients:
$ ss -ltn '( sport = :8081 )'
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 2 1 127.0.0.1:8081 0.0.0.0:*
$ ss -tan '( dport = :8081 )'
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ESTAB 0 0 127.0.0.1:50368 127.0.0.1:8081
ESTAB 0 0 127.0.0.1:50370 127.0.0.1:8081
SYN-SENT 0 1 127.0.0.1:50382 127.0.0.1:8081
SYN-SENT 0 1 127.0.0.1:50396 127.0.0.1:8081
$ nstat -az TcpExtListenOverflows TcpExtListenDrops
TcpExtListenOverflows 4 0.0
TcpExtListenDrops 4 0.0Two connections sit in the queue (a backlog of 1 holds two), two more are still in SYN-SENT retrying a handshake the server has already dropped, and the overflow counter says so. A service whose LISTEN row shows Recv-Q at or near Send-Q is a service that is not accepting fast enough, whatever its own health check says. The Life of a TCP Connection is built around this reading.
Selecting what you see
| Flag | Shows |
|---|---|
-t / -u / -x | TCP / UDP / Unix-domain sockets. -w raw, -S SCTP |
-l | Listening sockets only. Without it, only non-listening sockets; -a for both |
-n | Numeric ports and addresses; never resolve names (always use it on a server) |
-p | The owning process: name, PID, descriptor. Needs root for other users’ sockets |
-4 / -6 | Only IPv4 / only IPv6 |
-o | Timer information: retransmit, keepalive, time-wait countdowns |
-i | TCP internals: RTT, congestion window, retransmits, pacing rate, bytes delivered |
-m | Socket memory: receive and send buffer in use and their limits |
-e | Extended: owning uid, inode number, socket cookie, cgroup |
-s | Summary counts by protocol and state, nothing per socket |
-H / -O | No header / one line per socket, for scripts and watch |
-K | Destroy the matching sockets (root, kernel built with INET_DIAG_DESTROY) |
The thing that lifts ss above netstat | grep is its filter language, which runs in the kernel so you never page through sockets you did not want:
ss -tan state established # one state
ss -tan state time-wait # or: syn-sent, syn-recv, fin-wait-1, close-wait, ...
ss -tan state connected # every state except LISTEN and CLOSED
ss -tan '( sport = :443 )' # by local port
ss -tan '( dport = :5432 or sport = :5432 )' # either end
ss -tan dst 10.0.0.0/8 # by peer network
ss -tan dst 203.0.113.7:443 # by peer address and port
ss -tanp state established '( sport = :443 )' | awk 'NR>1 {print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | headThe parentheses and the spaces around = are required, and the quotes keep the shell away from them. The last line is the question “who has the most connections to my web server right now”, answered in one pipeline. Note that a state filter changes the output: the State column disappears because every row would say the same thing, which trips up scripts that count columns.
Reading a connection’s state
The State column is the TCP state machine, and three of its values are worth recognising at a glance. CLOSE-WAIT means the peer closed and this machine’s application has not: a server with hundreds of them has a bug, a program that forgets to close(). TIME-WAIT is normal and harmless on the side that closed first; -o shows its countdown and -s counts them. SYN-SENT or SYN-RECV that persist are handshakes not completing, a firewall or the full backlog above.
$ ss -tano state time-wait
Recv-Q Send-Q Local Address:Port Peer Address:Port Process
0 0 127.0.0.1:8082 127.0.0.1:42468 timer:(timewait,59sec,0)
$ ss -tano state established
0 0 192.0.2.2:40316 203.0.113.10:443 timer:(keepalive,42sec,0)The timer field names what the kernel is waiting on and how long is left: keepalive on an idle connection, on for a retransmission timer with a retry count as its third number, timewait for the sixty seconds after a close. A connection in ESTAB with no timer and nothing in either queue is one that nobody is checking on; whether it still works will only be known when someone sends on it.
Inside a connection: -i and -m
$ ss -tin '( sport = :8080 )'
ESTAB 0 0 127.0.0.1:8080 127.0.0.1:46314
bbr wscale:10,10 rto:204 rtt:0.011/0.005 mss:32768 cwnd:10 segs_in:2 lastsnd:516 lastrcv:516
lastack:516 delivered:1 app_limited rcv_space:65483 minrtt:0.011 snd_wnd:65536Each field is one of the kernel’s own TCP variables for that connection. The ones that pay for themselves: rtt (round-trip time and its variance, in milliseconds), cwnd (congestion window, in segments — a small number on a long-lived connection means loss), retrans:X/Y (current and total retransmissions; its absence means none), lastsnd/lastrcv/lastack (milliseconds since each, which tells you which side went quiet), and app_limited (the application, not the network, is the bottleneck). The congestion control algorithm is the first word; bbr or cubic is a per-connection fact, not a system-wide one.
-m adds skmem:(r…,rb…,t…,tb…): receive buffer in use and its limit, then the same for send. A connection with r close to rb is one whose application is not reading; t close to tb is one whose peer is not draining. Both are the same diagnosis as the queue columns, with the limits attached.
Unix sockets
$ sudo ss -xlp
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
u_str LISTEN 0 4096 /run/docker.sock 12345 * 0 users:(("dockerd",pid=812,fd=4))
u_str LISTEN 0 512 /run/postgresql/.s.PGSQL.5432 98765 * 0 users:(("postgres",pid=1203,fd=6))-x lists the sockets that local services talk over — Docker, PostgreSQL, systemd, D-Bus — with the path, the backlog and the owner. -xp with a dst filter on the path shows who is connected to one. A path that starts with @ is in the abstract namespace and has no file; The Life of a Unix Socket has the rest.
Killing a connection
ss -K destroys matching sockets without touching the process that owns them: the process sees an error on its next read or write, and a stuck client falls off a server without a restart. It needs root and a kernel built with CONFIG_INET_DIAG_DESTROY, which the major distributions’ kernels are. On the test machine it printed RTNETLINK answers: Invalid argument and destroyed the socket anyway, so confirm with a second ss rather than trusting the message. Write the filter without -K first and read what it matches: ss -K dst 10.0.0.0/8 with a typo in the network is a very quick way to disconnect everyone.
ss -tan dst 198.51.100.23 # look first
sudo ss -K dst 198.51.100.23 # then cut it offCommon problems
| Symptom | Cause | Fix |
|---|---|---|
| Process column is empty for some rows | Not root; ss cannot read other users’ /proc/PID/fd | sudo ss -p |
ss -t shows no listening sockets | Without -l or -a, listeners are excluded | -l for listeners, -a for everything |
| The port you expect is shown as a name, or is slow to print | Service-name and DNS resolution | -n, always |
A state filter broke your awk column numbers | The State column is omitted when it would be constant | Count columns from the right, or avoid state and filter on $1 |
Error: an inet prefix is expected rather than "..." | Filter syntax: missing spaces around =, or the shell ate the parentheses | Quote the whole expression: '( dport = :443 )' |
Hundreds of CLOSE-WAIT | The application is not closing connections its peers closed | A bug in the application; restart buys time, the fix is in the code |
LISTEN row with Recv-Q equal to Send-Q | Accept queue full; new connections are being dropped | Find out why the application is not accepting; raise the backlog only if it is a burst |
ss -K fails and the socket is still there | Kernel without INET_DIAG_DESTROY, or not root | Kill the owning process, or block the peer at the firewall |
Quick reference
sudo ss -tulpn # what is listening, and who owns it
ss -tan state established # live connections
ss -tanp '( sport = :443 )' # who is connected to my web server
ss -tano # with timers: keepalive, retransmit, time-wait
ss -tin '( dport = :5432 )' # RTT, cwnd, retransmits on the database connections
ss -ltn # LISTEN rows: Recv-Q = queued, Send-Q = backlog
ss -s # counts by state; watch time-wait and orphaned
sudo ss -xlp # unix sockets and their owners
watch -n1 'ss -tan state syn-recv | wc -l' # half-open connections, live
sudo ss -K dst 198.51.100.23 # cut one peer off (look first)Related reading
- The Life of a TCP Connection — the eight stages behind the State column, and the
ss -tanoireading as a diagnostic - The Life of a Packet — what the
Recv-QandSend-Qbytes are waiting for, in both directions - Networking Basics — the outward diagnosis that starts with
ss -tulpn - lsof — the same sockets from the process side:
lsof -i :443 - The Life of a Unix Socket — what
ss -xis listing, and why its backlog behaves differently - ip — the other half of
iproute2: addresses, routes and neighbours - The Morris worm — the 1988 reason
ss -tlnpis the first hardening check: three listening services nobody was watching

