ss · Linux command

Also known as: ss command

On this page 7

ss is a Linux command for inspecting sockets: it lists network and local connections together with their state, queue sizes, addresses and owning processes. Part of the iproute2 package, the ss command is the modern replacement for the older netstat and is a core tool for monitoring on Linux servers and desktops.

The name stands for socket statistics. Administrators use ss to answer practical questions quickly: which service listens on a port, how many connections are stuck in a given state, whether data is piling up in a queue, and which process owns a suspicious connection.

How the ss command reads socket data

The ss command obtains its information from the kernel through the netlink sock_diag interface, also known as inet_diag for TCP and UDP sockets. Instead of parsing large text files under /proc/net, as netstat traditionally does, ss asks the kernel for filtered binary records, which makes it considerably faster on busy hosts with tens of thousands of connections.

Filtering can happen inside the kernel when a state or port filter is given, so only matching sockets cross into user space. This matters on load balancers and proxies, where an unfiltered listing may contain more than 100,000 entries and take noticeable time to print.

The table below contrasts the two data paths and their practical consequences.

AspectThe ss commandThe netstat command
Data sourceNetlink sock_diagText files under /proc/net
FilteringIn the kernel for many filtersIn user space after reading
Speed on large hostsFast, scales wellSlow with many sockets
TCP internalsRTT, cwnd, retransmits with -iNot available
Packageiproute2, maintainednet-tools, deprecated
Data sources used by ss and netstat

Essential options and output columns

Most ss invocations combine a few single-letter options that select the socket family, the state and the level of detail. The widely used form ss -tulpn shows TCP and UDP listening sockets with numeric addresses and the processes that own them, which is the standard way to check open ports.

The following table lists the options that cover the majority of daily monitoring tasks.

OptionMeaningTypical purpose
-t / -uTCP or UDP socketsLimit output to one protocol
-l / -aListening or all socketsFind services or see every connection
-nNumeric outputSkip slow name and service resolution
-pShow owning processIdentify the program behind a port
-sSummary statisticsCount sockets per state and protocol
-iInternal TCP informationInspect RTT, congestion window, retransmits
-mSocket memory usageDiagnose buffer pressure
-xUnix domain socketsInspect local inter-process communication
Frequently used ss options

The default output contains the columns Netid, State, Recv-Q, Send-Q, local address and peer address, plus a process column when -p is used. The meaning of Recv-Q and Send-Q depends on the state: for a listening socket, Recv-Q is the current accept queue length and Send-Q is the configured backlog limit; for an established socket, Recv-Q counts bytes not yet read by the application and Send-Q counts bytes not yet acknowledged by the peer.

Filtering connections by state and address

A distinctive strength of ss is its filter expression language. A state filter such as ss -t state established restricts output to one TCP state, and address filters such as dport = :443 or src 10.0.0.0/8 select connections by port or network. Expressions can be combined with and, or and parentheses, which replaces long grep pipelines with a single precise query.

Knowing what each TCP state indicates turns a raw listing into a diagnosis. The table below lists the states that most often appear in monitoring work.

StateWhat it meansSignal when counts are high
LISTENWaiting for incoming connectionsNormal; check for unexpected services
ESTABConnection carrying dataLoad level or connection leaks
SYN-RECVHandshake started by a clientPossible SYN flood or slow accept
TIME-WAITClosed locally, waiting out old packetsMany short-lived outgoing connections
CLOSE-WAITPeer closed, application has notApplication fails to close sockets
FIN-WAIT-2Waiting for the peer to closePeer keeps half-open connections
TCP states commonly examined with ss

ss among Linux monitoring tools

The ss command focuses on sockets and connections, so it complements rather than replaces other monitoring tools. lsof shows every open file, including sockets, per process; strace reveals the system calls a process makes on a socket; and sar records network counters over time. A typical investigation starts with ss -s for an overview and narrows down with filters.

The decision table below matches common questions with the most suitable tool.

QuestionRecommended toolReason
Which process listens on port 8080ss -ltnpDirect port to process mapping
How many connections per statess -s or state filterFast kernel-side counting
Which files and sockets a process holdslsof -p PIDCovers all descriptor types
Why a connection is slowss -tiShows RTT and retransmissions
How traffic changed over a daysar -n DEVHistorical interface statistics
Choosing between ss and related tools

Common mistakes when reading ss output

Several misreadings recur even among experienced administrators, and most of them stem from missing privileges or misunderstood columns.

  • Running -p without root: the process column stays empty for sockets owned by other users, which looks like orphaned connections.
  • Treating TIME-WAIT as a fault: thousands of TIME-WAIT sockets are normal on clients making many short connections.
  • Ignoring CLOSE-WAIT growth: a steadily rising count usually indicates an application bug that never closes sockets.
  • Misreading Send-Q on listeners: it shows the backlog limit, not queued data.
  • Forgetting -n: name resolution can make ss slow and hide the real port numbers.

Understanding it simply

Every network conversation on a computer runs through a socket, a kind of numbered doorway. The ss command is like a building directory that lists every open doorway, who stands behind it and whether a conversation is starting, active or ending.

Administrators use it to see which programs accept visitors, how many visitors are inside and whether anyone is stuck waiting. It is quick, precise and already installed on almost every modern Linux system.

Applied in practice

An operations engineer receives an alert that a Java API server on Linux has started refusing requests, although CPU and memory look normal. The engineer runs ss -s and sees about 9,000 TCP sockets, far above the usual 1,500. A follow-up query, ss -tn state close-wait, shows that more than 7,000 of them are in CLOSE-WAIT, all pointing to the same database proxy on port 6432.

Running ss -tnp state close-wait as root confirms that the API process owns these sockets. The finding points to connections the application never closes after the proxy ends them. The team traces the issue to a missing close call in an error path of the connection pool, deploys a fix, and the CLOSE-WAIT count drops below 50 within an hour. The root cause was identified in minutes without restarting the service.