Inspect socket state on a production host using ss
to enumerate listening services, UDP endpoints, established TCP
sessions, and summary statistics. Use the output to confirm what
is exposed, what is active, and what to investigate next.
You need to inspect network socket activity on a production
server to understand what is listening, what is communicating,
and whether there are unexpected services exposed. Your task
is to use ss to list listening TCP sockets, view
UDP endpoints, filter for established TCP sessions, and
produce a socket summary.
ss is the modern replacement for
netstat in many environments. When diagnosing
incidents or validating a change, socket state gives you a
fast truth: what ports are open, which processes are bound,
and which connections are active right now.
ss
variant.
ss -tln.
ss
filters (-u, -a, -n,
-l).
state selectors.
ss -s.
ss -tln
This shows listening TCP sockets with numeric ports. It is a fast way to confirm what services are bound and accepting inbound connections.
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:5432 *:*
LISTEN 0 128 0.0.0.0:22 *:*
ss -ua
UDP sockets are connectionless, so the output typically
appears as UNCONN. Depending on flags, you may
show listening UDP sockets or all UDP endpoints.
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 127.0.0.1:123 *:*
ss -tn state established
This filters to established TCP sessions and prints numeric addresses and ports, which is useful for quick triage when a host is under load or unexpectedly busy.
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ESTAB 0 0 192.168.1.10:22 192.168.1.5:53324
ss -s
The summary view provides a quick count of sockets by protocol and state. It is useful when validating whether the system is accumulating large numbers of connections.
Total: 3 (kernel 4)
TCP: 1 (estab 1, closed 0, orphaned 0, timewait 0)
ss -tln
: Lists listening TCP sockets with numeric output.
-t TCP sockets.-l listening sockets only.-n numeric addresses and ports.ss -ua
: Displays UDP sockets (often shown as UNCONN).
-u UDP sockets.-a all sockets (not just listening).ss -un (numeric) and
ss -uln (listening + numeric).
ss -tn state established
: Filters to established TCP connections.
state established restricts output to active sessions.-n avoids DNS/service name resolution for faster output.ss -s
: Displays socket summary statistics by protocol/state for quick triage.