By Tux Harlow — Solnyxus editorial voice. Drafted with AI assistance; reviewed by the team.
Fresh server. Something's supposed to be listening on a port and clearly isn't. Your fingers type netstat -tulpn before your brain has finished the thought, you hit Enter, and the shell answers command not found with the calm of a librarian. Good news: the ss command has been sitting on that box the whole time. It ships in iproute2, the same package that gives you ip, and it's better at this job than netstat ever was.
Why the ss command replaced netstat
netstat lives in net-tools, and plenty of distributions just don't install that by default any more. Nobody held a funeral. It simply stopped turning up.
ss does the work differently. Instead of reading and parsing the text files under /proc/net, it asks the kernel directly over netlink, through the sock_diag interface. That's why it stays quick on a box juggling tens of thousands of connections, where scraping text starts to drag. And it knows more than its grandparent did: TCP timers, congestion details, memory per socket. (Side note: if you've ever watched a terminal sit there while netstat chewed through a busy load balancer, you already understand the appeal.)
The one-liner everyone needs
If you remember one thing from this post, make it this:
ss -tlnp
Read it left to right. TCP (-t). Listening sockets only (-l). Numeric addresses and ports, not names (-n). And the process that owns each socket (-p). Want UDP too? Add -u.
One catch that bites everyone once. Without root, the process column comes back empty for sockets you don't own, and you'll stare at it wondering whether the daemon is even running. It probably is. Run it with sudo and the names appear.
Who is connected right now
ss -tn
No -l, no -a, and ss shows established connections, the live ones. If you want every state at once, listening sockets included, that's what -a is for.
State filters
This is the bit that made me stop piping everything into grep. ss filters by TCP state on its own:
ss -tn state established
ss -tn state time-wait
ss -tn state syn-sent
The states you can ask for: established, syn-sent, syn-recv, fin-wait-1, fin-wait-2, time-wait, closed, close-wait, last-ack, listening and closing. There are groups as well, such as connected and synchronized, for when you want a family rather than one member.
My favourite is syn-sent. A pile of those usually means you've been knocking on a door upstream and nobody's answering. It's a diagnosis in one line, and I love it a little more than is healthy.
Address and port filters
ss -tn '( dport = :443 or sport = :443 )'
ss -tn dst 192.0.2.10
The first line catches connections to or from port 443. Quote those parentheses, or the shell will grab them before ss ever sees them, and the error you get won't tell you that's what happened. The second line shows connections to one remote address.
Summary and Unix sockets
ss -s
ss -x
ss -s prints totals per protocol and state. It's the fastest health check I know: one glance and you know whether you've got forty connections or forty thousand. ss -x lists Unix domain sockets, and that's where a lot of local daemons quietly live, databases and Docker among them. If a service "isn't listening" on any port, check here before you panic.
Timers and TCP internals
ss -tno
ss -tni
-o adds timer information: keepalive timers, retransmit timers, the little countdowns the kernel keeps on every connection. -i goes deeper into internal TCP information, with round-trip time, congestion window and retransmits. When a connection feels slow and nobody believes you, -i is how you bring receipts.
Killing a socket
Now the sharp knife. ss -K forcibly closes every socket that matches your filter. It needs root, and it needs a kernel built with CONFIG_INET_DIAG_DESTROY, so it won't work everywhere.
sudo ss -K dst 192.0.2.10 dport = :5432
Here's my hill, and I'll stand on it: always run the exact same filter without -K first. Read what comes back. Then add the K. A filter that's one character too broad will happily close connections you very much wanted open.
Translating netstat habits
Your fingers will keep typing the old commands for a while. Here's the phrasebook:
netstat -tulpnbecomesss -tulpn.netstat -anbecomesss -an.netstat -sstatistics are closer tonstatfrom iproute2;ss -sis a socket summary.netstat -rbecomesip route.
Notice how little changes in most of them? That's deliberate, and it's a kindness.
So here's tonight's homework. Open a terminal on anything you look after, run ss -tlnp with sudo, and check that every listening port on that list is one you meant to open. If one surprises you, well. Now you know which process to go and have a word with.
Linux
More like this
Linux
entr and watch: Make Your Terminal Rerun Things So You Don't Have To
Save, switch window, press up, press Enter, squint. Save, switch window, press up... Stop. entr reruns your command whenever a file changes, and watch reruns it on a timer. Two tiny tools, a thousand saved keystrokes.
Linux
ripgrep: grep, But It Drank Three Espressos and Read Your .gitignore
grep is a legend. It's also happy to search all 80,000 files in node_modules while you wait. ripgrep searches only what matters, very quickly, with sensible defaults. The flags worth knowing, and when old grep still wins.
Linux
Linux Terminal Toys (and the Surprisingly Useful Tools Hiding Among Them)
A talking cow, a train that punishes typos, the Matrix in your terminal, and hidden among them, six genuinely useful tools you'll keep long after the novelty wears off. A toy box for Linux nerds.