Three handshakes and four breakups

Three-way handshake

Functions of three-way handshake: determine whether the sending and receiving functions of both parties are normal, synchronize communication serial number, exchange TCP communication window size and maximum message segment length (MSS)

Four times to wave

Normally, it is up to the client to decide when to close the connection. The point of the four waves is to ensure that the data is transmitted in its entirety.

Packets are captured using tcpdump

  • The test command

curl www.google.com

  • Packet capture command NIC: Wlo1 Port: 80

tcpdump -nn -i wlo1 port 80

  • Output (annotated)
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode listening on wlo1, link-type EN10MB (Ethernet), The snapshot length of 262144 bytes # three-way handshake # # SYN | = 1 seq = 3464472424 | MSS = 1460 23:59:04. 224062 IP 192.168.50.43.49312 > 142.250.217.132.80: Flags [S], seq 3464472424, win 64240, options [mss 1460,sackOK,TS val 388526343 ecr 0,nop,wscale 7], Length 0 # # ACK = 1 = 3464472424 + 1 | | an ACK seq = 2089195576 | MSS = 1460 23:59:04. 225261 IP 142.250.217.132.80 > 192.168.50.43.49312: Flags [S.], seq 2089195576, ack 3464472425, win 28960, options [mss 1460,sackOK,TS val 612064231 ecr 388526343,nop,wscale 6], Length 0 ## ACK = 1 23:59:04.225273 IP 192.168.50.43.49312 > 142.250.217.132.80: Flags [.], ack 1, win 502, options [nop,nop,TS val 388526344 ecr 612064231], 23:59:04.225323 IP 192.168.50.43.49312 > 142.250.217.132.80: Flags [P.], seq 1:79, ack 1, win 502, options [nop,nop,TS val 388526344 ecr 612064231], length 78: HTTP: GET/HTTP/1.1 23:59:04.229628 IP 142.250.217.132.80 > 192.168.50.43.49312: Flags [.], ack 79, win 453, options [nop,nop,TS val 612064235 ecr 388526344], Server response 23:59:04.593391 IP 142.250.217.132.80 > 192.168.50.43.49312: Flags [.], seq 1:1449, ack 79, win 453, options [nop,nop,TS val 612064598 ecr 388526344], length 1448: HTTP: HTTP/1.1 200 OK 23:59:04.593433 IP 192.168.50.43.49312 > 142.250.217.132.80: Flags [.], ack 1449, win 493, options [nop,nop,TS val 388526713 ecr 612064598], Length 0 23:59:04.594312 IP address 142.250.217.132.80 > 192.168.50.43.49312: Flags [P.], seq 1449:8175, ack 79, win 453, options [nop,nop,TS val 612064598 ecr 388526344], length 6726: HTTP 23:59:04.594348 IP 192.168.50.43.49312 > 142.250.217.132.80: Flags [.], ack 8175, win 441, options [nop,nop,TS val 388526713 ecr 612064598], Length 0 23:59:04.594367 IP address 142.250.217.132.80 > 192.168.50.43.49312: Flags [P.], seq 8175:12081, ack 79, win 453, options [nop,nop,TS val 612064598 ecr 388526344], length 3906: HTTP 23:59:04.594378 IP 192.168.50.43.49312 > 142.250.217.132.80: Flags [.], ack 12081, win 411, options [nop,nop,TS val 388526713 ecr 612064598], Length 0 23:59:04.597658 IP address 142.250.217.132.80 > 192.168.50.43.49312: Flags [.], seq 12081:13529, ack 79, win 453, options [nop,nop,TS val 612064603 ecr 388526713], length 1448: HTTP 23:59:04.597682 IP 192.168.50.43.49312 > 142.250.217.132.80: Flags [.], ack 13529, win 493, options [nop,nop,TS val 388526717 ecr 612064603], Length 0 23:59:04.597989 IP 142.250.217.132.80 > 192.168.50.43.49312: Flags [P.], seq 13529:14883, ack 79, win 453, options [nop,nop,TS val 612064603 ecr 388526713], length 1354: HTTP 23:59:04.598013 IP 192.168.50.43.49312 > 142.250.217.132.80: Flags [.], ACK 14883, win 493, options [NOP, NOP,TS val 388526717 ECR 612064603], length 0 # When one party closes the connection and the other party has no data to send, the connection is immediately closed, and the ACK of step 2 and FIN of step 3 are merged into one step. This optimization in RFC793 section 3.5 # # FIN = 1 | seq = 79 | ack = [last seq] + 1 = 14883 23:59:04. 598320 IP 192.168.50.43.49312 > 142.250.217.132.80: Flags [F.], seq 79, ack 14883, win 501, options [nop,nop,TS val 388526717 ecr 612064603], Length = 1 | 0 # # an ACK FIN = 1 = 79 + 1 | | an ACK seq = 14883 23:59:04. 600734 IP 142.250.217.132.80 > 192.168.50.43.49312: Flags [F.], seq 14883, ack 80, win 453, options [nop,nop,TS val 612064605 ecr 388526717], Length 0 # # ACK = 1 | ACK = 14883 + 1 23:59:04. 600768 IP 192.168.50.43.49312 > 142.250.217.132.80: Flags [.], ack 14884, win 501, options [nop,nop,TS val 388526720 ecr 612064605], length 0Copy the code