← Full reference

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

OptionMeaning
-tTCP
-uUDP
-xunix sockets (local, via a file: /run/…sock)
-wraw sockets
-llistening only (LISTEN, UNCONN for UDP)
-aall: both listening sockets and connections
-4 / -6IPv4 only / IPv6 only

What to show about each socket

OptionMeaning
-nnumbers instead of names: :80, not :http
-rthe opposite: resolve IPs to host names
-powning process: users:(("nginx",pid=812,fd=6))
-eextended: uid, socket inode, cgroup
-oTCP timers: keepalive, retransmits
-iinternal TCP info: RTT, window, congestion algorithm
-msocket memory usage
-Hno header line — for wc -l and scripts
-Oeach entry on one line (handy with -i, -p)
-ssummary 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

ColumnMeaning
Netidsocket type: tcp, udp, u_str… (shown when several types are selected)
Statestate: LISTEN, ESTAB, TIME-WAIT, UNCONN…
Recv-Qfor a connection — bytes received but not yet read by the program; for LISTEN — connections queued for accept()
Send-Qfor a connection — bytes sent but not acknowledged; for LISTEN — the maximum queue size (backlog)
Local Address:Portown address and port; 0.0.0.0 / [::] / * — all interfaces
Peer Address:Portthe peer's address; * for listening sockets
Processowner (only with -p)

TCP states

StateMeaning
LISTENwaiting for incoming connections
ESTABconnection established
SYN-SENTwaiting for a reply to a connection attempt — the server isn't answering or a firewall drops it
SYN-RECVincoming connection halfway set up
TIME-WAITwe closed the connection, the socket waits it out (up to a minute) — this is normal
CLOSE-WAITthe peer closed, but the program hasn't yet; many of these mean a leak in the application
FIN-WAIT-1/2, LAST-ACK, CLOSINGintermediate 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

FilterMeaning
sport = :80local port (source port)
dport = :5432remote port — e.g. outgoing connections to a database
src 127.0.0.1 / dst 10.0.0.0/8local / remote address or subnet
sport > :1024, dport != :22comparisons: =, !=, <, >, <=, >=
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 :80 catches too much: :8080, :8000. The filter sport = :80 is exact; with grep, put a space after the port (':80 ').
  • Without -n, ports are shown as names from /etc/services (:http, :ssh), and a grep for the number finds nothing.
  • The process column is empty without privileges. -p shows only processes you have access to; other users' processes are visible as root.
  • 0.0.0.0:80 and 127.0.0.1:80 are 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 the Local Address column.
  • [::]:80 is 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 state UNCONN; ss -ul shows 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 … the State column disappears from the output — that's normal, the state is already set by the filter.

See also

ip · curl · ps · nginx · grep