MSL indicates the Maximum Segment Lifetime. MSL indicates the Maximum Segment Lifetime for which a packet is discarded. TCP packets are BASED on THE IP protocol, and the TTL field in the IP header is the maximum number of routes that an IP packet can pass through. This value decreases by 1 for each router that processes the PACKET. When this value is 0, the packet is discarded and an ICMP packet is sent to notify the source host.

The difference between MSL and TTL: THE unit of MSL is time, while TTL is the number of hops through the route. Therefore, MSL should be greater than or equal to the time when TTL consumption is 0 to ensure that the message has died naturally.

TIME_WAIT Waits twice as long for MSL packets. When packets from the sender are processed by the receiver, the sender sends a response to the receiver.

For example, if the passive closing party does not receive the last ACK packet of the disconnected connection, a TIMEOUT resending Fin packet is triggered. After receiving a Fin, the other party resends an ACK to the passive closing party, with exactly two MSLS coming and going.

The 2MSL time starts when the client sends an ACK after receiving the FIN. If the CLIENT receives a FIN packet from the server again because the ACK from the client is not transmitted to the server during the time-wait, the 2MSL TIME is reset.

On Linux, 2MSL defaults to 60 seconds, so an MSL is 30 seconds. Linux stays in TIME_WAIT for a fixed period of 60 seconds. This is defined in the Linux kernel code as TCP_TIMEWAIT_LEN:

#define TCP_TIMEWAIT_LEN (60HZ) / how long to wait to destroy TIME-WAIT

state, about 60 seconds */

To change the length of TIME_WAIT, change the value of TCP_TIMEWAIT_LEN in the Linux kernel code and recompile the Linux kernel. Time-wait is required for two reasons:

Prevent “old” packets with the same “quad” from being received;

Ensure that the “passive closing connection” can be closed correctly, that is, ensure that the last ACK can be received by the passive closing party, thus helping it to close properly;