What does ss show?
Socket statistics: every TCP, UDP, Unix and raw socket, with local and remote addresses, state, queues and, on request, the process that owns it. It is part of iproute2, installed on every Linux image we offer, and it reads data straight from the kernel, so it stays fast even with hundreds of thousands of connections.
Which ports are open for listening?
ss -tulpn ss -Htlpn 'sport = :443'
TCP, UDP, listening, processes, numeric. The second form adds a filter and -H to hide the header, handy in scripts. Read the local address column: *:443 or 0.0.0.0:443 listens on every address; 127.0.0.1:5432 only locally. With one public IPv4 per machine, anything listening on all addresses is reachable from the internet unless a firewall says otherwise.
How do filters work?
ss accepts a small expression language after the options:
| Filter | Matches |
|---|---|
state established | Open connections |
state time-wait | Recently closed connections |
'( dport = :5432 or sport = :5432 )' | PostgreSQL traffic either way |
dst 198.51.100.0/24 | Connections to a network |
'sport >= :1024' | Local ports from 1024 up |
state connected | Every state except listen and closed |
ss -tn state established '( sport = :443 )' | wc -l ss -tnp state established dst 198.51.100.12
The first counts open HTTPS connections; the second lists connections to one partner machine, such as a database replica in another city, with the local processes using them.
How do I get a quick summary?
ss -s
It prints totals per protocol and per TCP state in one screen. A sudden rise in synrecv or timewait compared with your normal numbers is an early sign of a traffic change. For per-state counts on one port, combine a filter with counting:
ss -Htan 'sport = :443' | awk '{print $1}' | sort | uniq -c
How do I see TCP details for a connection?
-i adds internal TCP information per socket:
ss -tni dst 198.51.100.12 | head -4 # ESTAB 0 0 203.0.113.25:47182 198.51.100.12:5432 # cubic wscale:7,7 rto:204 rtt:3.1/0.4 mss:1448 cwnd:10 bytes_sent:812345 ...
rtt is the measured round-trip time in milliseconds with its variance; cwnd is the congestion window; retrans, when present, counts retransmitted segments. Slow replication between cities often shows here as high RTT or growing retransmissions, which points at the network path rather than the database. The Latency entry explains what RTT to expect over distance.
What about Unix sockets?
ss -xlp | grep -E 'php|mysql|postgres'
Local services often talk through Unix sockets rather than TCP: PHP-FPM pools, MySQL at /run/mysqld/mysqld.sock, PostgreSQL in /run/postgresql. This shows which ones exist and which process owns each.
Can ss close a connection?
Yes, with -K, on kernels built with socket destroy support, which includes current Ubuntu, Debian and Enterprise Linux kernels. It sends a reset to matching sockets:
ss -K dst 192.0.2.77 dport = :443
Use it to drop a stuck client or a connection from an address you just blocked, without restarting the service. Filters apply, so preview with the same command without -K first.
How do I find which process holds a port I need?
When a service fails with "address already in use", ask ss who has it: ss -Htlpn 'sport = :8080' prints the program name and PID in the last column. Stop that program or move one of the two services to another port. Remember that one public address serves every service on the machine, so planning ports up front saves these collisions later.
How does ss compare with netstat?
Same habits, better engine. ss -tulpn mirrors netstat -tulpn, but ss also filters inside the kernel query, shows TCP internals and closes sockets. Routes and interfaces moved to the ip command, covered in The ip command; the old tool is described in The netstat command.
Keep Reading
The netstat command
What netstat shows, how to install it on current images, the flags still worth knowing and the ss and ip commands that replace it.
OpenThe ip command
Read addresses, links, routes and neighbors with ip, understand the /31 setup on our machines and make test changes without losing SSH.
OpenLatency
Why distance sets the floor for ping time, how to estimate round trips between our six cities and how to choose a location.
OpenFix "Connection reset by peer"
Find out why sshd hangs up mid-handshake: ban lists, MaxStartups throttling, broken host keys, idle timeouts or MTU trouble.
OpenFAQ
Quick Answers
Run ss -tulpn as root to list listening TCP and UDP ports with their processes.
Use ss -Htn state established with a filter such as '( sport = :443 )' and pipe it to wc -l.
Run ss -tni with a filter; the rtt field shows round-trip time in milliseconds.
Yes. ss -K with a filter resets matching sockets on kernels that support it.
Yes. It is part of iproute2, present on every Linux image we install.