Foundations: Linux, scripting, Git & networking
The TCP handshake
Every TCP connection — every HTTPS request, database query, kubectl call — starts with the three-way handshake and ends with a FIN or RST exchange. Understanding the handshake, the socket states it creates, and the kernel queues behind it lets you read tcpdump output, tell a firewall drop from a dead service in seconds, explain why TIME_WAIT and CLOSE_WAIT pile up, defend against SYN floods, and reason about latency. This topic pairs with TCP/UDP (transport fundamentals) and TLS (what happens right after the handshake).
After this topic you can
- Walk through the three-way handshake and connection close
- Read connection states with ss
- Explain SYN floods, TIME_WAIT and connection limits
Lessons
-
1The three-way handshake
- The exchange
- Why sequence numbers are exchanged
- Why three steps, not two
- Options negotiated in the handshake
- What the ACK number means
-
2Closing connections and socket states
- Graceful close: FIN
- Abort: RST
- All the states
- TIME_WAIT: purpose and problems
- CLOSE_WAIT: always an application bug
-
3Kernel queues, backlogs and SYN floods
- Two queues per listening socket
- SYN floods
-
4Reading the handshake in packet captures
- tcpdump flag notation
- Measuring handshake cost with curl
-
5Latency: handshakes, TLS and connection reuse
- Counting round trips
- Idle timeout mismatches: the 502 classic
-
6Troubleshooting scenarios
- "Connection timed out" for clients, server looks fine
- Clients see resets when pods terminate
- Health checks pass, users fail
- Thousands of TIME_WAIT on a reverse proxy
- NAT gateway connection failures under load
- "Cannot assign requested address"
- Retransmissions are high on a link
-
7IP TTL, traceroute and MSS clamping
- IP TTL (not DNS TTL)
- How traceroute works
- MSS clamping and PMTUD
-
8Interview questions and model answers
- "Explain the TCP three-way handshake."
- "What's the difference between FIN and RST?"
- "Your server has thousands of sockets in CLOSE_WAIT. What does it mean?"
- "Lots of TIME_WAIT on a client. Is that bad?"
- "Clients get connection timeouts but the server shows no SYNs in tcpdump. Where's the problem?"
- "What is a SYN flood and how do you defend against it?"
- "Why does TLS add latency, and how does HTTP/3 help?"
- "How does traceroute work?"