ss
Which ports are listening, which connections are open and which process owns them
ss (socket statistics) shows sockets: listening ports, established connections, their state and the owning process. It is the modern replacement for netstat: faster and with flexible filters.
Syntax
ss [options] [state STATE] [filter]
Options choose the socket type and output format; state and the filter select rows. With no options, ss shows all established connections, including unix sockets.
Which sockets to show
| Option | Meaning |
|---|---|
-t | TCP |
-u | UDP |
-x | unix sockets (local, via a file: /run/…sock) |
-w | raw sockets |
-l | listening only (LISTEN, UNCONN for UDP) |
-a | all: both listening sockets and connections |
-4 / -6 | IPv4 only / IPv6 only |
What to show about each socket
| Option | Meaning |
|---|---|
-n | numbers instead of names: :80, not :http |
-r | the opposite: resolve IPs to host names |
-p | owning process: users:(("nginx",pid=812,fd=6)) |
-e | extended: uid, socket inode, cgroup |
-o | TCP timers: keepalive, retransmits |
-i | internal TCP info: RTT, window, congestion algorithm |
-m | socket memory usage |
-H | no header line — for wc -l and scripts |
-O | each entry on one line (handy with -i, -p) |
-s | summary only: how many sockets of each type and in each state |
The most common combinations: ss -tlnp — who is listening on TCP ports, ss -tunap — all TCP and UDP sockets with processes, ss -s — the big picture.
Output columns
| Column | Meaning |
|---|---|
Netid | socket type: tcp, udp, u_str… (shown when several types are selected) |
State | state: LISTEN, ESTAB, TIME-WAIT, UNCONN… |
Recv-Q | for a connection — bytes received but not yet read by the program; for LISTEN — connections queued for accept() |
Send-Q | for a connection — bytes sent but not acknowledged; for LISTEN — the maximum queue size (backlog) |
Local Address:Port | own address and port; 0.0.0.0 / [::] / * — all interfaces |
Peer Address:Port | the peer's address; * for listening sockets |
Process | owner (only with -p) |
TCP states
| State | Meaning |
|---|---|
LISTEN | waiting for incoming connections |
ESTAB | connection established |
SYN-SENT | waiting for a reply to a connection attempt — the server isn't answering or a firewall drops it |
SYN-RECV | incoming connection halfway set up |
TIME-WAIT | we closed the connection, the socket waits it out (up to a minute) — this is normal |
CLOSE-WAIT | the peer closed, but the program hasn't yet; many of these mean a leak in the application |
FIN-WAIT-1/2, LAST-ACK, CLOSING | intermediate closing stages |
In a state filter, names are lowercase: established, listening, time-wait, close-wait, syn-sent. There are groups: connected (everything except listening and closed), all. The inverse filter is exclude state.
Address and port filters
| Filter | Meaning |
|---|---|
sport = :80 | local port (source port) |
dport = :5432 | remote port — e.g. outgoing connections to a database |
src 127.0.0.1 / dst 10.0.0.0/8 | local / remote address or subnet |
sport > :1024, dport != :22 | comparisons: =, !=, <, >, <=, >= |
and, or, not, ( … ) | logic; separate parentheses with spaces |
Put the whole filter in single quotes: otherwise the shell grabs > and the parentheses.
Examples
# who listens on TCP ports: address, port, process
ss -tlnp
# all TCP and UDP sockets with processes
ss -tunap
# is anyone listening on port 8080
ss -tlnp 'sport = :8080'
# several ports at once
ss -tlnp '( sport = :80 or sport = :443 )'
# listening ports above 1024
ss -tln 'sport > :1024'
# established connections to PostgreSQL
ss -tn state established '( dport = :5432 )'
# how many established TCP connections right now
ss -Htn state established | wc -l
# stuck connections the application doesn't close
ss -tnp state close-wait
# which UDP ports are open
ss -ulnp
# listening unix sockets (docker.sock, php-fpm, etc.)
ss -xlp
# summary of all sockets
ss -s
Pitfalls
grep :80catches too much::8080,:8000. The filtersport = :80is exact; withgrep, put a space after the port (':80 ').- Without
-n, ports are shown as names from/etc/services(:http,:ssh), and agrepfor the number finds nothing. - The process column is empty without privileges.
-pshows only processes you have access to; other users' processes are visible as root. 0.0.0.0:80and127.0.0.1:80are different. The first accepts connections on all interfaces, the second only from this machine. If a service is "not reachable from outside", check the address in theLocal Addresscolumn.[::]:80is a separate IPv6 socket. nginx usually has two lines per port: one for IPv4 and one for IPv6.- UDP is never in
LISTEN. An open UDP port has the stateUNCONN;ss -ulshows exactly those. - The exit code is always
0, even if nothing matched the filter. In a script, check the output:ss -Htln 'sport = :8080' | grep -q .. - After
state …theStatecolumn disappears from the output — that's normal, the state is already set by the filter.