The process and principle of tcp three handshake in Linux?-in Security and Organized Manner

In Linux, the three handshakes of TCP (Transmission Control Protocol) are an important process for establishing a reliable connection. This mechanism ensures that data can be exchanged between the client and the server in a secure and organized manner. The following will elaborate on the process and principles of TCP three handshakes:

First, the process of TCP handshake three times

TCP three handshake process involves the client (usually called “active open side”) and the server (usually called “passive open side”) between the three message exchange. The following are the specific steps:

  1. First handshake:

o The client sends a SYN (Synchronized Sequence Number) message segment to the server and sets the SYN flag bit to 1. At the same time, the client randomly generates an initial sequence number (seq=x) and puts it in the Sequence Number field of the TCP header. o The client sends the server an initial sequence number (seq=x). o The client sends the server an initial sequence number (seq=x). At this point, the client's TCP connection status changes to SYN_SENT.

o Example message: client -> server [SYN, seq=x]

  1. Second handshake:

o The server receives the client's SYN message segment and acknowledges it (ACK). The acknowledgement is done by setting the ACK flag bit to 1 in the response message segment and setting the acknowledgement number (ack) field to the received sequence number plus 1 (ack=x+1). At the same time, the server also randomly generates an initial sequence number of its own (seq=y) and places it in the sequence number field of the response message segment and sends a SYN message segment (SYN=1), which is the SYN+ACK message segment. At this point, the server's TCP connection status changes to SYN_RCVD.

o Example message: server -> client [SYN, ACK, seq=y, ack=x+1]

  1. Third handshake:

o The client receives a SYN+ACK message segment from the server and acknowledges it. The acknowledgement is done by sending an ACK message segment, setting the ACK flag bit to 1, and setting the acknowledgement number (ack) field to the received server sequence number plus 1 (ack=y+1). At this point, the client's TCP connection status changes to ESTABLISHED, indicating that the connection has been successfully established.

o Example message: Client -> Server [ACK, seq=x+1, ack=y+1]

o After the server receives the client's ACK message segment, its TCP connection status also becomes ESTABLISHED, at this time the two sides can start transmitting data.

Second, the principle of TCP handshake three times

The principle of TCP handshake three times is mainly based on the following key points:

  1. synchronization sequence number: through the SYN message segment, the client and the server can negotiate and determine the respective initial sequence number, which is to ensure the order and reliability of data transmission.
  2. Acknowledgement mechanism: Through the ACK message segment, both parties are able to confirm that the other party is ready to receive data and has successfully received the other party's sequence number. This acknowledgement mechanism is an important part of TCP's reliability guarantee.
  3. Preventing a failed connection request message segment from suddenly being transmitted to the server: Due to network instability, a failed connection request message segment may linger in the network and suddenly be transmitted to the server. The three handshakes mechanism ensures that the server does not incorrectly accept these invalid requests, thus avoiding unnecessary resource consumption and potential security risks.

In summary, the TCP three times handshake is an important process to establish a reliable connection, which ensures that data can be exchanged between the client and the server in a safe and orderly manner through the synchronization of sequence numbers, the confirmation mechanism, and the prevention of invalidated request message segments and other measures.

Privacy    |    Terms of use