Drill: Examine TCP Connection States with ss¶
Goal¶
Use ss to inspect TCP connection states, identify CLOSE_WAIT and TIME_WAIT accumulation, and diagnose connection issues.
Setup¶
- Linux system with iproute2 installed (provides ss)
- Root access for viewing all sockets
Commands¶
Show all TCP connections with state:
Show listening sockets with process info:
Filter by specific state:
Count connections by state:
Show connections to a specific port:
Show connections from a specific source:
Show socket memory and timer info:
What to Look For¶
- Large numbers of TIME_WAIT are often normal but can exhaust port space
- CLOSE_WAIT accumulation indicates the local application is not closing connections properly
- SYN_RECV buildup may indicate SYN flood or slow application accept
- ESTABLISHED count should match expected concurrency for the service
Common Mistakes¶
- Using netstat instead of ss (netstat is slower and deprecated on modern systems)
- Forgetting
-pflag and not seeing which process owns the socket - Not using
-nand waiting for DNS resolution on every connection - Confusing source and destination in filter expressions
Cleanup¶
No cleanup needed. ss is a read-only inspection tool.