What is the status of the time_wait (Time wait timer)?
Simply put, the TIME_WAIT state is the state that the server enters when it sends a fin termination connection to the client four times in a wave.
The process of waving four times:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/85/80/wKioL1el0k_Tk3ETAAA-lW6b8JE298.png "title=" 1.PNG " alt= "Wkiol1el0k_tk3etaaa-lw6b8je298.png"/>
You can see that the TIME_WAIT state exists when the client receives the server fin and returns an ACK.
when in the TIME_WAIT state, we cannot create a new connection because the port is occupied.
2. Why is there a time_wait status?
The reasons are two points:
<1> reliable termination of TCP connections
If the client in time_wait sends a message to the server to confirm that the packet is missing, the server will resend the fin segment, and the client must be in a state that can be received time_wait instead of the close state.
<2> Ensure that the belated TCP segment has enough time to be identified and discarded
There is a TCP port in Linux that cannot be opened two or more times, and when the client is in the TIME_WAIT state, we will not be able to make a new connection using this port, and if there is no time_wait state, the new connection may receive data from the old connection. The time_wait duration is 2MSL (MSL's longest message life), which ensures that old data can be discarded because the largest amount of data in the network exists in MSL.
3. How can I avoid time_wait state usage resources?
the resource that is in the TIME_WAIT state is not freed by the kernel.
When TCP is in time_wait, it must wait for 2 MSL to time out to reclaim the port, and bind error:address already in is present once the TCP connection server exits unexpectedly without releasing the port number. How to solve?
The option to set the socket descriptor through socksetopt so_reuseaddr to 1, even if sock is in Time_wait state, The socket address to which it is bound can also be reused immediately.
4. Classification of port numbers
by port number can be divided into 3 categories:
(1) Register port (registered Ports): from 1024 to 49151. They are loosely tied to some services. This means that there are many services bound to these ports, which are also used for many other purposes. For example: Many systems handle dynamic ports starting around 1024.
(3) dynamic and/or private ports (Dynamic and/or Private Ports): from 49152 to 65535. In theory, these ports should not be assigned to the service. In fact, machines typically allocate dynamic ports from 1024 onwards. But there are exceptions: Sun's RPC port starts at 32768.
0 is typically used to analyze the operating system. This approach works because "0" is an invalid port in some systems and will produce different results when you try to connect it using a typical closed port. A typical scan: Use an IP address of 0.0.0.0, set the ACK bit and broadcast on the Ethernet layer.
This article from "Together to see the Stars" blog, reproduced please contact the author!
Time_wait Status and port number classification for TCP four-time wave