TCP connection status

TCP status:
1), LISTEN: First, the server needs to open a socket for listening, the status is LISTEN. /* The socket is listening for incoming connections. Listening for connection requests from remote TCP ports*/
2), SYN_SENT: client Then the client tcp sends a SYN to request to establish a connection. Then the state is set to SYN_SENT. /*The socket is actively attempting to establish a connection. Waiting for a matching connection after sending a connection request Request */
  www.2cto.com 
3), SYN_RECV: The server should send an ACK to confirm the SYN of the client, and at the same time send a SYN to the client. After that, the status is set to SYN_RECV /* A connection request has been received from the network. In After receiving and sending a connection request, wait for the confirmation of the connection request*/

4), ESTABLISHED: represents an open connection, and the two parties can conduct or have already exchanged data. /* The socket has an established connection. Represents an open connection, data can be transmitted to the user*/

5), FIN_WAIT1: Active close (active close) The end application calls close, so its TCP sends a FIN request to actively close the connection, and then Enter the FIN_WAIT1 state. /* The socket is closed, and the connection is shutting down. Waiting for the connection interruption request from the remote TCP, or the confirmation of the previous connection interruption request*/
6), CLOSE_WAIT: After the passive close (passive close) end TCP receives the FIN, it sends an ACK in response to the FIN request (its reception is also passed to the upper-layer application as the end of file), and enters CLOSE_WAIT. /* The remote end has shut down, waiting for the socket to close. Waiting for the connection interruption request from the local user*/

7), FIN_WAIT2: After actively closing the terminal and receiving ACK, it enters FIN-WAIT-2 ./* Connection is closed , and the socket is waiting for a shutdown from the remote end. Waiting for a connection interruption request from the remote TCP */
8), LAST_ACK: After passively closing the end for a period of time, the application receiving the end-of-file character will call CLOSE to close the connection. This causes its TCP to also send a FIN, waiting for the other party's ACK. It enters LAST-ACK. /* The remote end has shut down, and the socket is closed. Waiting for acknowledgement. Waiting for the connection originally sent to the remote TCP to be interrupted Confirmation of the request */
9), TIME_WAIT: After receiving the FIN on the active shutdown end, TCP sends an ACK packet and enters the TIME-WAIT state. /* The socket is waiting after close to handle packets still in the network. Waiting enough time to ensure that the remote TCP receives an acknowledgment of the connection break request */

10), CLOSING: relatively rare./* Both sockets are shut down but we still don't have all our data sent. Waiting for the confirmation of the connection interruption from the remote TCP*/ www.2cto.com 
11), CLOSED: passively close the end After receiving the ACK packet, it enters the closed state. The connection ends./* The socket is not being used. There is no connection status*/


During the routine maintenance of the server, the following commands are often used:
netstat -n | awk '/^tcp/ {++S[$ NF]} END {for(a in S) print a, S[a]}'   
It will display information such as the following:
TIME_WAIT 814
CLOSE_WAIT 1
FIN_WAIT1 1
ESTABLISHED 634
SYN_RECV 2
LAST_ACK 1
The three commonly used states are: ESTABLISHED means that Communication, TIME_WAIT means active close, CLOSE_WAIT means passive close.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326780591&siteId=291194637