Octet

Name the TCP states and tell me what a pile-up in each one usually means when you run ss or netstat.

Show the answer

Say this first

The states are LISTEN, SYN_SENT, SYN_RCVD, ESTABLISHED, FIN_WAIT_1, FIN_WAIT_2, CLOSE_WAIT, CLOSING, LAST_ACK, TIME_WAIT and CLOSED. Many SYN_SENT means SYNs are not answered; many SYN_RCVD points at a SYN flood or lost final ACKs; many CLOSE_WAIT is almost always an application that does not close its sockets; many TIME_WAIT is normal on the side that closes first.

Go deeper

What each pile-up tells you

StateSideMany of them usually means
SYN_SENTClientPeer down, route missing, or a firewall dropping SYNs silently
SYN_RCVDServerSYN flood, or the client's final ACK not arriving (asymmetric path through a stateful firewall)
ESTABLISHEDBothNormal. Steady growth is a connection leak or a slow backend
FIN_WAIT_1Active closerOur FIN is not acknowledged: peer gone, or unsent data stuck behind a zero window
FIN_WAIT_2Active closerPeer acknowledged our FIN but its application never closed
CLOSE_WAITPassive closerOur application received end of stream and never called close()
LAST_ACKPassive closerOur FIN is not acknowledged, peer probably gone
CLOSINGBothSimultaneous close, rare and short-lived
TIME_WAITActive closerNormal. A problem only if ephemeral ports run out

Naming differs by tool

netstat prints SYN_SENT, ESTABLISHED, CLOSE_WAIT. ss prints SYN-SENT, SYN-RECV, ESTAB, CLOSE-WAIT, TIME-WAIT, and UNCONN for unconnected UDP sockets.

Quick count on Linux

Shell
ss -tan | awk 'NR>1 {print $1}' | sort | uniq -c | sort -rn

Traps

  • Blaming the network for CLOSE_WAIT. The kernel has done its part; the local application has not.
How did you do?Book 5.2 Reliable Byte Stream (TCP)