TCP Teardown, FIN/RST & TIME-WAIT
Cheat sheet · https://pcornel.dk/topic.php?topic=313
Answer
A TCP connection ends politely with FIN from each side, or abruptly with RST. After a polite close, the side that closed first keeps the connection in TIME-WAIT for about a minute.
Remember
FIN from both sides means both applications finished. A reset means something gave up — find out who and after what. CLOSE-WAIT that accumulates is an application not closing. TIME-WAIT is normal, but ties up the port pair.
First checks
tcpdump -ni <if> 'tcp[tcpflags] & (tcp-fin|tcp-rst) != 0' and host <ip>— only the closing packets.ss -tan state time-wait | wc -l— connections lingering after close.ss -tan state close-wait— waiting for the local application.sysctl net.ipv4.ip_local_port_range— a client's port range.
Verify in this order
exchange complete → one side sends FIN → acknowledged → other side sends FIN → acknowledged → first closer waits in TIME-WAIT → connection forgotten
Where it usually breaks
physical/link dependency → local object state → peer/control state → policy → forwarding/adjacency → end-to-end result
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=313