SYN:(同步序列编号,Synchronize Sequence Numbers)该标记仅在三次握手创建TCP毗连时有效。表示一个新的TCP毗连请求。 ACK:(确认编号,Acknowledgement Number)是对TCP请求简直认标记,同时提示对端系统已经乐成接收所有数据。 FIN:(结束标记,FINish)用来结束一个TCP回话.但对应端口仍处于开放状态,准备接收后续数据。 LISTEN:首先服务端须要打开一个socket进行监听,状态为LISTEN, The socket is listening for incoming connections. 侦听来自远方TCP端口的毗连请求 。 SYN_SENT:客户端通过应用步伐调用connect进行active open.于是客户端tcp发送一个SYN以请求创建一个毗连,之后状态置为SYN_SENT,The socket is actively attempting to establish a connection. 在发送毗连请求后等待匹配的毗连请求。 SYN_RECV:服务端应发出ACK确认客户端的SYN,同时本身向客户端发送一个SYN, 之后状态置为SYN_RECV ,
A connection request has been received from the network. 在收到和发送一个毗连请求后等待对毗连请求简直认 。 ESTABLISHED:代表一个打开的毗连,双方可以进行或已经在数据交互了, The socket has an established connection. 代表一个打开的毗连,数据可以传送给用户。 FIN_WAIT1:主动关闭(active close)端应用步伐调用close,于是其TCP发出FIN请求主动关闭毗连,之后进入FIN_WAIT1状态。 The socket is closed, and the connection is shutting down. 等待远程TCP的毗连停止请求,或先前的毗连停止请求简直认。 CLOSE_WAIT:被动关闭(passive close)端TCP接到FIN后,就发出ACK以回应FIN请求(它的接收也作为文件结束符传递给上层应用步伐),并进入CLOSE_WAIT, The remote end has shut down, waiting for the socket to close. 等待从本地用户发来的毗连停止请求 。 FIN_WAIT2:主动关闭端接到ACK后,就进入了FIN-WAIT-2 , Connection is closed, and the socket is waiting for a shutdown from the remote end. 从远程TCP等待毗连停止请求。 LAST_ACK:被动关闭端一段时间后,接收到文件结束符的应用步伐将调用CLOSE关闭毗连。这导致它的TCP也发送一个 FIN,等待对方的ACK.就进入了LAST-ACK , The remote end has shut down, and the socket is closed. Waiting for acknowledgement. 等待原来发向远程TCP的毗连停止请求简直认。 TIME_WAIT:在主动关闭端接收到FIN后,TCP就发送ACK包,并进入TIME-WAIT状态。 The socket is waiting after close to handle packets still in the network.等待足够的时间以确保远程TCP接收到毗连停止请求简直认。 CLOSING:比力少见, Both sockets are shut down but we still don’t have all our data sent. 等待远程TCP对毗连停止简直认。 CLOSED: 被动关闭端在接受到ACK包后,就进入了closed的状态。毗连结束, The socket is not being used. 没有任何毗连状态。
TIME_WAIT状态的形成只发生在主动关闭毗连的一方。
主动关闭方在接收到被动关闭方的FIN请求后,发送乐成给对方一个ACK后,将本身的状态由FIN_WAIT2修改为TIME_WAIT,而必须再等2倍 的MSL(Maximum Segment Lifetime,MSL是一个数据报在internetwork中能存在的时间)时间之后双方才华把状态 都改为CLOSED以关闭毗连。目前RHEL里保持TIME_WAIT状态的时间为60秒。
Linux的干系keepalive参数
1、tcp_keepalive_time – INTEGER
How often TCP sends out keepalive messages when keepalive is enabled.(Default: 2hours)
一个毗连须要TCP开始发送keepalive探测数据包之前的空闲时间,以秒为单元。
2、tcp_keepalive_probes – INTEGER
How many keepalive probes TCP sends out, until it decides that the connection is broken. (Default value: 9)
发送TCP keepalive探测数据包的最大数目,默认是9.如果发送9个keepalive探测包后对端仍然没有响应,就关掉这个毗连。
3、tcp_keepalive_intvl – INTEGER
How frequently the probes are send out. Multiplied by tcp_keepalive_probes it is time to kill not responding connection,
after probes started. Default value: 75sec i.e. connection will be aborted after ~11 minutes of retries.
发送两个TCP keepalive探测数据包的隔断时间,默认是75秒。
五、常用netstat干系命令