ss From Zero: Who Holds the Port, Where the Connection Stalls — Read Sockets at a Glance
ss reads the kernel's socket table: who is listening, what state each connection is in, which process holds the socket. This guide runs every command for real on iproute2 ss 6.1.0 — a live http.server on 127.0.0.1:18080, LISTEN vs ESTABLISHED, state filters, ss -s, Unix sockets — with output pasted verbatim.

When a service will not start, a port is taken, or a connection stalls, the first instinct is usually to read the logs. But logs tell you the program's version of events. ss tells you the kernel's: which ports are listening, what state each connection is in, which process holds each socket. ss belongs to the iproute2 suite, and its manual page defines it in one line: "another utility to investigate sockets". It replaces netstat: netstat assembles its picture by reading files under /proc, while ss asks the kernel directly over netlink — faster, and more complete. Every command in this guide was run for real on iproute2 ss 6.1.0, and the output is pasted verbatim.
Check the version first, then start:
$ ss --version ss utility, iproute2-6.1.0 exit=0
Run bare, with no options, ss shows only established, non-listening sockets — the manual page's words: "When no option is used ss displays a list of open non-listening sockets (e.g. TCP/UNIX/UDP) that have established connections." In this sandbox, nothing listens at first, so a filtered ss -tlnp returns only the header:
$ ss -tlnp State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess exit=0
That header is the first lesson: ss output is read column by column. State is the socket's state (LISTEN, ESTAB, and so on); Recv-Q is the bytes the kernel has received that the program has not collected yet; Send-Q is the bytes the program has handed over that the kernel has not sent yet; Local Address:Port is this end's address and port; Peer Address:Port is the other end; and the final column, Process, shows which process holds the socket — only when you ask for it with -p. An empty table is not ss failing; it means this machine genuinely has no listening TCP ports. On your own machine, the same command lists sshd, nginx, your database — whatever is listening.
To have something to look at, the demo script starts a real service: Python's http.server, bound to 127.0.0.1 on port 18080. Run ss -tlnp again and the table fills in:
$ ss -tlnp sport = :18080
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 0 127.0.0.1:18080 0.0.0.0:* users:(("python3",pid=4089,fd=3))
exit=0
Read it column by column. State is LISTEN: the socket is waiting for connections. Recv-Q and Send-Q are both 0: nothing is queued. Local Address:Port is 127.0.0.1:18080: the service is bound to the loopback address only, so nothing outside this machine can reach it. Peer Address:Port is 0.0.0.0:*: in LISTEN state there is no peer yet, so it is a wildcard. The last column, users:(("python3",pid=4089,fd=3)), says the socket belongs to a python3 process, on file descriptor 3. The pid differs on every run — it is the process number of that particular http.server start — so this article and its validator never treat it as a fixed value.
The sport = :18080 at the end is an ss filter expression: show only sockets whose source port is 18080. It goes at the end of the command, with no pipe and no grep. Drop the -p and run it again, and the difference is immediate:
$ ss -tln sport = :18080 State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess LISTEN 0 0 127.0.0.1:18080 0.0.0.0:* exit=0
The Process column simply disappears — not because the process is gone, but because ss was not asked to show it. -p means "show processes using sockets", in the manual page's words. One more detail: showing process information requires privilege. Run as root, or as the user who owns the socket, and you see the full column; as an ordinary user looking at someone else's socket, the column may be empty. That is a permission design, not a bug. And the option letters: -t is TCP, -l is listening only, -n is numeric (no resolving service names or host names), -p is processes. Put together, ss -tlnp is the combination you will type most.
Listening is only one socket state. The demo script next opens a real TCP connection — Python connects to 127.0.0.1:18080 and holds it for four seconds — and inspects it while it is alive:
$ ss -tn state established dport = :18080 Recv-Q Send-Q Local Address:Port Peer Address:Port Process 0 0 127.0.0.1:60052 127.0.0.1:18080 exit=0
This line says: local 127.0.0.1:60052 is connected to 127.0.0.1:18080, in state ESTABLISHED. The 60052 is an ephemeral port, different on every connection, so this article never treats it as fixed. Note there is no -l here: state established means "only established connections", the complement of -l ("only listening"). Drop the filter and look at all established connections at the same moment, and the same connection appears twice:
$ ss -tn state established Recv-Q Send-Q Local Address:Port Peer Address:Port Process 0 0 127.0.0.1:18080 127.0.0.1:60052 0 0 127.0.0.1:60052 127.0.0.1:18080 exit=0
That is not a duplicate. It is the two ends of one connection: the server end (18080 to 60052) and the client end (60052 to 18080). ss sees two sockets in the kernel that happen to form a pair. Run the same filtered command after the connection closes, and only the header remains — the connection is gone:
$ ss -tn state established dport = :18080 Recv-Q Send-Q Local Address:Port Peer Address:Port Process exit=0
State filtering is ss's most useful skill. TCP has more states than LISTEN and ESTABLISHED. The manual page lists these state-filter keywords: established, syn-sent, syn-recv, fin-wait-1, fin-wait-2, time-wait, closed, close-wait, last-ack, listening and closing — plus group keywords: all (everything), connected (everything except listening and closed), synchronized (connected states except syn-sent), bucket (states kept as minisockets, i.e. time-wait and syn-recv) and big (the opposite of bucket). The three you will use daily are: ss -tlnp to see who is listening, ss -tn state established to see who is connected, and ss -tn state time-wait | wc -l to see how many sockets are piling up in TIME-WAIT. A TIME-WAIT pile-up is not itself a fault — it is the normal waiting state after an active close, there to stop old packets confusing new connections — but if the count keeps climbing and ports run out, the application has a short-connection problem worth investigating, usually a missing connection pool.
For a quick picture of a whole machine's sockets, use ss -s for the summary:
$ ss -s Total: 376 TCP: 30 (estab 2, closed 27, orphaned 0, timewait 1) Transport Total IP IPv6 RAW 0 0 0 UDP 0 0 0 TCP 3 3 0 INET 3 3 0 FRAG 0 0 0 exit=0
The first line, Total: 376, is the socket count (different on every run). The second line breaks down TCP: estab 2 is the established connections (exactly the pair from the demo), closed 27 closed, orphaned 0 orphaned sockets, timewait 1 in TIME-WAIT. The Transport table splits by protocol and address family: 3 TCP, 0 UDP. The manual page notes that -s does not parse the socket lists at all; it gathers the summary from various sources — the right choice when there are so many sockets that parsing /proc/net/tcp would be painful. Notice that Total and the TCP number do not match (376 versus 3): Total counts every socket, including Unix domain sockets, while the Transport table only covers network protocols.
Unix domain sockets are how processes on the same machine talk to each other: no network card, no IP address, just a file path. Use ss -xl to see the listening ones:
$ ss -xl Netid State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess u_str LISTEN 0 4096 /run/systemd/private 23940 * 0 u_str LISTEN 0 4096 /run/systemd/userdb/io.systemd.DynamicUser 23942 * 0 u_str LISTEN 0 4096 /run/systemd/io.systemd.ManagedOOM 23943 * 0 u_dgr UNCONN 0 0 /run/systemd/journal/dev-log 23948 * 0 u_str LISTEN 0 4096 /run/systemd/journal/stdout 23952 * 0 u_str LISTEN 0 4096 /run/systemd/journal/io.systemd.journal 25290 * 0 u_str LISTEN 0 4096 /run/hatch/sandbox/space-inference.sock 31962 * 0 exit=0
Here the Local Address:Port column holds socket file paths: /run/systemd/private is systemd's private control channel, /run/systemd/journal/stdout is a logging channel, and the .sock files belong to the sandbox's services. In the Netid column, u_str is a Unix stream socket and u_dgr a datagram one. A first-time reader often asks why systemd has so many sockets. The answer is socket activation: many services do not run until a request arrives on their socket, at which point the socket wakes them. Once you know that, you also know why plain ss -x prints hundreds of lines — the quiet chatter between processes on one machine far exceeds the traffic leaving it. The demo script deliberately uses -xl rather than -x, to show only the listening ones and avoid a flood.
Three advanced options are used rarely but can save a debugging session. -o shows timer information in the form timer:(name, expire time, retransmissions), with five timer names: on (retransmission timer), keepalive, timewait, persist (zero-window probe) and unknown. When a connection sits still, -o shows what it is waiting for. -e shows extended information: uid (the user id the socket belongs to), ino (its inode number in the VFS) and sk (a socket cookie, a uuid). -i shows internal TCP information: rtt and rttvar, cwnd (congestion window), mss (maximum segment size), ssthresh (slow-start threshold), bytes_acked and bytes_received, segs_out and segs_in, even pacing_rate. For a slow connection, packet loss or a throughput ceiling, -i is first-hand evidence. The manual page also documents -K (--kill), which attempts to forcibly close sockets, for IPv4 and IPv6 only. This guide does not demonstrate it: closing someone else's socket is a destructive operation, and on a production machine you should think twice before using it.
Finally, place ss in the toolbox alongside the guides already published in this series. ping tests whether packets can get there — the IP layer. ss shows what state sockets are in — the transport layer. lsof shows which process opened which file and port — processes and files. curl sends a real HTTP request — the application layer. Each covers one layer, and troubleshooting runs in order: ping first to confirm reachability, then ss to confirm the service is listening and where a connection stalls, then curl to confirm the application answers. netstat can do similar things, but iproute2 has replaced it — this sandbox still has netstat (the net-tools package), but many new systems do not install it by default, so learning ss is the durable choice. One common misconception: ss only sees this machine. It cannot see the other end or the routers in between; it reads this machine's kernel socket table, and only that. For a cross-machine problem, run ss again on the other end.
Here is a daily cheat sheet, ready to copy. A service will not start: run ss -tlnp first. Is the service listening? Is it on 127.0.0.1 or 0.0.0.0? Is the port number right? Is the process holding it the one you expect? A port is taken: ss -tlnp 'sport = :8000' narrows it to that port, and the users column gives the process name and pid — then decide whether to stop it or pick another port. Connection counts look wrong: ss -s gives the totals and the TIME-WAIT count, and ss -tn state established | wc -l counts the established ones. A service is slow: ss -tnp state established 'dport = :5432' shows its connections to the database, and a Recv-Q that stays above zero means the program is not collecting data as fast as the kernel receives it — the bottleneck is in the application, not the network. A Unix socket is missing: ss -xl searches by path. None of these commands changes configuration or restarts anything; read the output once, and the problem is usually half located.
The Recv-Q and Send-Q columns deserve a paragraph of their own, because they are the most overlooked and most useful columns in ss output. Recv-Q is "the kernel has received it, the program has not collected it", in bytes. Send-Q is "the program has handed it over, the kernel has not sent it yet". On a healthy established connection, both are 0. A Recv-Q that stays above zero means the other end is sending, the kernel is receiving, but the program is not collecting — the bottleneck is in the application: it may be stuck, its thread pool may be full, or it may be waiting on a lock. A Send-Q that stays above zero means data cannot get out — the bottleneck is the network or the other end. When a service gets slow, checking these two columns first puts the problem on the application side or the network side, and saves half the detour. One nuance: a LISTEN socket also has a Send-Q, but it means something different there — the length of the queue of connections waiting for accept, the backlog. Python's http.server uses a default backlog of 5; a production service sets it in its listen call.
The difference between 127.0.0.1 and 0.0.0.0 is the most common trap in ss output. In the demo the service binds 127.0.0.1:18080, which means only this machine can connect to it. If the same service bound 0.0.0.0:18080, it would listen on every interface, and other machines on the network could reach it. The two most common "service will not start" failures both trace back to this: either the program bound 127.0.0.1 while you are connecting from another machine, or the program tried to bind 0.0.0.0:8000 while another process already held port 8000 and the start failed outright. One look at the Local Address:Port column in ss -tlnp separates the two cases. A third case: a service bound to the IPv6 :::8000, accepting both IPv4 and IPv6 connections depending on the system's dual-stack settings — ss shows that as [::]:8000, and the square brackets are just IPv6 notation, not an error.
Filter expressions are the heart of ss, so they are worth a longer look. The manual page's FILTER syntax is [ state STATE-FILTER ] [ EXPRESSION ], and expressions can filter by source port, destination port, source address and destination address, with comparison operators. The combinations that cover daily work: ss -tlnp 'sport = :8000' for one exact port; ss -tn 'dport = :5432' for every connection to the database on port 5432; ss -tn state established '( dport = :443 or sport = :443 )' for every established connection involving port 443; ss -t state time-wait for TIME-WAIT only; ss -tlnp 'sport > :8000' for listening sockets above port 8000. Quote the filter expression, or the shell will treat the parentheses as its own syntax. Two handy shorthands: ss -tan is all TCP states with numeric output, and ss -tulpn is listening TCP plus UDP with processes — the two lines many experienced users type from memory.
Here is a full troubleshooting story that strings the commands together. Suppose an application on your development server does not answer at http://localhost:8000. Step one, ss -tlnp: is port 8000 listening? If not, the service never started — read the program's logs. If it is, check whether Local Address is 127.0.0.1 or 0.0.0.0: if you are connecting from another machine and the service only bound loopback, the problem is found. Step two, the service listens but connections fail: ss -tn state syn-sent shows connections stuck in SYN-SENT — handshake packets went out and no reply came back, which points at a firewall or routing. Step three, connected but no response: ss -tnp state established 'dport = :8000' shows whether the connection exists, and Recv-Q shows whether requests arrived and the program is not processing them — then it is time to look at the program's threads and locks. Step four, suspecting a stolen port: ss -tlnp 'sport = :8000' shows the users column, which process and pid hold port 8000. Four steps, and the problem is usually located — without restarting a single service.
Now a few traps that catch people. First: without -n, ss tries to resolve port numbers to service names (80 becomes http, 443 becomes https) and IP addresses to host names. Resolution goes through DNS, and when DNS is slow, ss output is slow with it. When troubleshooting, add -n first — numbers do not lie. Second: a LISTEN socket does not mean the service is healthy. It only says the socket is listening; the application behind it may be deadlocked. To confirm a service really works, send a real request — curl it, or connect to the port. Third: do not confuse TIME-WAIT with CLOSE-WAIT. TIME-WAIT is the side that closed first waiting out twice the maximum segment lifetime; it disappears on its own. CLOSE-WAIT means the other end has closed and this end has not — a pile-up of CLOSE-WAIT usually means the program forgot to close the socket, which is an application bug worth reading code for. Fourth: ss only sees this machine. For a cross-machine problem, run ss on the other end too and compare.
One more modern scenario is worth a paragraph: ss inside a container. A Docker container has its own network namespace by default, so ss inside a container only sees that container's sockets — not the host's, not other containers'. That is isolation, and it is also a troubleshooting trap: it is normal not to see a container's listening port from the host; you have to look inside the container. And the 127.0.0.1 inside a container is the container's own loopback, not the host's. ss has a -N (--net) option to switch to a named network namespace, given the privilege. The rule to remember is simple: ss always shows the sockets of the current network namespace. In the container era, that one sentence dissolves a lot of confusion — when a port mapping does not work, run ss -tlnp inside the container, then on the host, compare the two, and the layer at fault becomes obvious.
Finally, two options for scripting. -H (--no-header) drops the header line, -Q (--no-queues) drops the Recv-Q and Send-Q columns, and -O (--oneline) squeezes each socket's data onto one line. These exist for scripts: to count established connections, ss -tnH state established | wc -l is cleaner than the version with a header; to feed a listening-port list into monitoring, ss -tlnH gives one record per line. -4 and -6 restrict the output to IPv4 or IPv6, and -f selects the address family (unix, inet, inet6, link, netlink, vsock and more). -D dumps raw diagnostic information about TCP sockets to a file, and -F reads filter conditions from a file — advanced uses, rarely needed in daily troubleshooting, but good to know they exist.
Stepping back, the learning curve for ss is gentle: one core concept — the socket — and one core table. Remember ss -tlnp (who is listening), ss -tn state established (who is connected), ss -s (how many), ss -xl (communication between processes on this machine), plus the sport, dport and state filters, and daily troubleshooting is covered. The deeper options (-o, -e, -i, -K) are for the day a specific problem sends you back to the manual page — the full ss(8) text is public on man7.org. Save the demo script from this guide, run it again with a different port and a different service, and you will really know ss. One more detail for the thorough reader: the State column means different things under different protocols. For TCP, LISTEN, ESTAB, TIME-WAIT are states of the connection state machine; UDP has no connections, so its sockets usually show UNCONN (not connected) or ESTAB (a UDP socket that called connect); Unix domain sockets show LISTEN and UNCONN in a similar sense. At first, do not memorise every state — LISTEN (waiting for connections), ESTAB (connected), TIME-WAIT (waiting for old packets to expire) and CLOSE-WAIT (the other end closed, this end has not) cover ninety percent of daily work. The rest can wait until you actually meet them in output, and then the STATE-FILTER section of the manual page is there.
Boundary note: this guide covers only ss (socket statistics). It does not cover packet capture (that is tcpdump's territory), firewall rules, or performance tuning. Boundaries against previously published guides: the ping guide covers ICMP reachability, the lsof guide covers processes, files and port ownership, the curl guide covers HTTP requests, and the process-management guide covers ps, kill and signals. ss differs from all of them: it only reads the kernel's socket table. The demo in this guide ran in a sandbox: the sandbox starts with no listening TCP ports, so the demo script starts a real python3 http.server (127.0.0.1:18080), stops it at the end, and verifies the port no longer listens. In the transcript, pids, ephemeral ports and socket totals differ on every run; this article quotes only stable lines, and the transcript is the authority for exact numbers. The demo script ends by printing --- done (server stopped, no process left) ---, meaning the server is stopped and the port is clear.
One more thing worth noting: ss output barely differs between distributions. It is part of iproute2, which ships with every mainstream Linux distribution — Ubuntu, Debian, CentOS, Arch — with the same options and the same output format. Learn it once, use it everywhere. That is also why this series keeps returning to such foundational tools: they do not chase trends, they do not get discontinued, and their interfaces do not change. Ten years from now, ss -tlnp will still mean the same thing.
It helps to know what ss replaced and why the replacement stuck. netstat read its information from files under /proc/net — text files the kernel regenerates — which made it slow on machines with tens of thousands of sockets and occasionally inconsistent while the files were being read. ss talks to the kernel over netlink and gets a coherent snapshot, which is why it stays fast when socket counts grow into the hundreds of thousands. On a laptop the difference is invisible; on a busy server with fifty thousand connections, it is the difference between an answer in a second and an answer in a minute. That is the practical reason the iproute2 authors deprecated netstat, and why distributions stopped installing net-tools by default. The old tool still works where it is installed — this sandbox has it — but new systems increasingly do not, and the knowledge does not transfer forward.
For readers who want to go deeper, the manual page repays a full read. The sections this guide did not cover — -b for classic BPF filters on sockets, --bpf-maps for socket-local BPF data, --inet-sockopt for socket options, the MPTCP and TIPC families, the --tipcinfo output — belong to specialised work: tracing a connection through a load balancer, debugging a multipath TCP setup, or inspecting a telecom stack. You will know when you need them, because the ordinary options will have stopped answering your question. Until then, the four commands in the cheat sheet and the filter syntax are the whole working set, and they are enough for the overwhelming majority of real incidents: a service that will not start, a port that is taken, a connection that stalls, a queue that grows.
A last practical note on habits. The fastest troubleshooters are not the ones who know the most commands; they are the ones who check the cheapest hypothesis first. ss -tlnp costs nothing and answers the most common question — is the thing listening, and is it the thing I think it is? — in under a second. Make it the first command after ping in any network incident, before opening logs, before restarting services, before asking anyone for help. Most of the time, the answer is already in that one table, and the rest of the investigation is just confirming what it said.
One question that comes up often: if ss is so good, why does netstat still exist? Because removing a tool breaks scripts, and distributions are conservative about that. netstat still ships in the net-tools package on many systems, and old runbooks still call it. But no new development happens there, and the direction of travel is clear: every major distribution's documentation now teaches ss, and container images increasingly do not include net-tools at all. If you are writing a new runbook, a new monitoring script, or a new guide for your team, write ss. If you inherit a script that calls netstat, it will keep working — but the day it stops working will be the day you wish you had already switched.
Comments (0)
Sources
Related articles
ping does exactly one thing: send an ICMP echo request, wait for the echo reply, and report the round-trip time and packet loss. This guide runs every command for real on iputils ping 20240117 — packet count, interval, quiet mode, packet size, timestamps, IPv4 vs IPv6, the three failure modes, exit codes 0/1/2 — with output pasted verbatim.
df answers one question: how much space is left on each file system. This guide runs every command for real on GNU coreutils df 9.4 — a 100M file moving Use% from 2% to 21%, inodes with df -i, and the classic trap: a deleted-but-open file keeps its space until the process exits — with output pasted verbatim.
cron is the scheduling daemon that has run on Linux for decades: write a crontab file saying 'run this command at this time', and it handles the rest. This guide runs everything for real on Debian cron 3.0pl1-162 — installing a job, waiting one minute for the trigger, verifying the log, removing the job — plus special strings, five classic mistakes, and a real 3 a.m. log-archiving job.