一、TCP连接的几种状态:

下图为状态表,

TCP protocol operations may be divided into three phases. Connections must be properly established in a multi-step handshake process (connection establishment) before entering thedata transferphase. After data transmission is completed, theconnection terminationcloses established virtual circuits and releases all allocated resources.

A TCP connection is managed by an operating system through a programming interface that represents the local end-point for communications, the. During the lifetime of a TCP connection the local end-point undergoes a series ofstatechanges.

操作系统通过代表通信本地端的一个叫网络socket的一个可编程接口来管理TCP连接。在TCP连接周期中,本地端会经历一系列状态变化。

LISTEN

(server) represents waiting for a connection request from any remote TCP and port.

SYN-SENT

(client) represents waiting for a matching connection request after having sent a connection request.

SYN-RECEIVED

(server) represents waiting for a confirming connection request acknowledgment after having both received and sent a connection request.

ESTABLISHED

(both server and client) represents an open connection, data received can be delivered to the user. The normal state for the data transfer phase of the connection.

FIN-WAIT-1

(both server and client) represents waiting for a connection termination request from the remote TCP, or an acknowledgment of the connection termination request previously sent.

FIN-WAIT-2

(both server and client) represents waiting for a connection termination request from the remote TCP.

CLOSE-WAIT

(both server and client) represents waiting for a connection termination request from the local user.

CLOSING

(both server and client) represents waiting for a connection termination request acknowledgment from the remote TCP.

LAST-ACK

(both server and client) represents waiting for an acknowledgment of the connection termination request previously sent to the remote TCP (which includes an acknowledgment of its connection termination request).

TIME-WAIT

(either server or client) represents waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request. a connection can stay in TIME-WAIT for a maximum of four minutes known as twoMSL(maximum segment lifetime).]

CLOSED

(both server and client) represents no connection state at all.

二、怎么样建立连接(3次握手):SYN: The active open is performed by the client sending a SYN to the server. The client sets the segment's sequence number to a random value A.

SYN-ACK: In response, the server replies with a SYN-ACK. The acknowledgment number is set to one more than the received sequence number i.e.A+1, and the sequence number that the server chooses for the packet is another random number, B.

ACK: Finally, the client sends an ACK back to the server. The sequence number is set to the received acknowledgement value i.e. A+1, and the acknowledgement number is set to one more than the received sequence number i.e. B+1.

At this point, both the client and server have received an acknowledgment of the connection. The steps 1, 2 establish the connection parameter (sequence number) for one direction and it is acknowledged. The steps 2, 3 establish the connection parameter (sequence number) for the other direction and it is acknowledged. With these, a full-duplex communication is established.

三、连接终止(4次挥手):

The connection termination phase uses a four-way handshake(4次挥手), with each side of the connection terminating independently. When an endpoint wishes to stop its half of the connection, it transmits a FIN packet, which the other end acknowledges(告知已收到) with an ACK. Therefore, a typical tear-down requires a pair of FIN and ACK segments from each TCP endpoint. After the side that sent the first FIN has responded with the final ACK, it waits for a timeout before finally closing the connection, during which time the local port is unavailable for new connections; this prevents confusion due to delayed packets being delivered during subsequent connections.

A connection can be"half-open", in which case one side has terminated its end, but the other has not. The side that has terminated can no longer send any data into the connection, but the other side can. The terminating side should continue reading the data until the other side terminates as well.

It is also possible to terminate the connection by a 3-way handshake, when host A sends a FIN and host B replies with a FIN & ACK (merely combines 2 steps into one) and host A replies with an ACK.

Some host TCP stacks may implement a half-duplex close sequence, asLinuxorHP-UXdo. If such a host actively closes a connection but still has not read all the incoming data the stack already received from the link, this host sends a RST instead of a FIN . This allows a TCP application to be sure the remote application has read all the data the former sent—waiting the FIN from the remote side, when it actively closes the connection. But the remote TCP stack cannot distinguish between aConnection Aborting RSTandData Loss RST. Both cause the remote stack to lose all the data received.

Some application protocols may violate theOSI modellayers, using the TCP open/close handshaking for the application protocol open/close handshaking — these may find the RST problem on active close. As an example:s = connect(remote);

send(s, data);

close(s);

For a usual program flow like above, a TCP/IP stack like that described above does not guarantee that all the data arrives to the other application.

四、中文解释3次握手,4次挥手

五、为什么TIME_WAIT状态还需要等待2MSL才能回到CLOSED状态?或者为什么TCP要引入TIME_WAIT状态?

当TCP执行一个主动关闭,并发回最后一个ACK后,该连接必须在TIME_WAIT状态停留的时间为2倍的MSL,这样可以让TCP再次发送最后的ACK以防止这个ACK丢失(另一端超时重发最后的FIN)。MSL(Maximum Segment Lifetime)即最大生存时间,常用值为30秒、1分钟或者2分钟。

linux 网络状态图,linux的网络连接状态相关推荐

  1. linux查看哪个网卡插着网线,(笔记)Linux下检测网卡与网线连接状态

    Linux下检测网卡与网线连接状态,使用ioctl向socket发送SIOCETHTOOL命令字. #include #include #include #include #include #incl ...

  2. linux 有线网卡,linux下有线网卡出现ADDRCONF(NETDEV_UP): eth0: link is not ready的解决方法...

    一.背景 2018年5月24日,笔者的pc已经连续运转两天了,突然要使用有线网卡,却发现有线网卡无法正常工作,于是查看了一下内核日志: r8169 0000:05:00.0 eth0: link do ...

  3. 4g网络切换软件_5G 网络NSA与SA模式 互操作策略研究

    点击上方"慧牛科技"关注我们哦 整体介绍 当前NSA采用Option3x方式组网,以4G网络为信令锚点,只有进入连接态才会触发与NR网络的双连接.因此,NSA与SA模式无法直接进行 ...

  4. 详解linux netstat输出的网络连接状态信息

    本博文为老男孩linu培训机构早期的培训教案,特分享以供大家学习参考. 全部系列分为五篇文章,本博文为第一篇: 目录:一.生产服务器netstat tcp连接状态................... ...

  5. Linux的系统调用、网络连接状态、磁盘I/O;可疑行为监控/日志收集、SHELL命令执行流程

    http://man7.org/linux/man-pages/man7/capabilities.7.html http://www.cnblogs.com/LittleHann/p/3850653 ...

  6. linux netstat Netstat是在内核中访问网络连接状态及其相关信息的程序,它能提供TCP连接,TCP和UDP监听,进程内存管理的相关报告。

    在Internet RFC标准中,Netstat的定义是: Netstat是在内核中访问网络连接状态及其相关信息的程序,它能提供TCP连接,TCP和UDP监听,进程内存管理的相关报告. Netstat ...

  7. linux查看tcp连接状态_Linux使用lsof查看打开的文件和网络连接

    lsof是List Open Files的缩写.顾名思义,它用来查看系统中进程打开了哪些文件:因为Linux几乎所有的设备都可以看成是文件,所以lsof经常也可以用来查看管道,sockets的使用状态 ...

  8. Linux网络监控工具--netstat及网络连接分析

    netstat命令用来打印Linux中网络系统的状态信息,可让你得知整个Linux系统的网络情况 -a     (all)显示所有选项,默认不显示LISTEN相关     -t     (tcp)仅显 ...

  9. linux命令行模式连接网络,centos命令行模式连接无线网络的过程

    1. 首先, 你的系统要能驱动无限网卡, 要是人品好的话, 系统已经自带了你的网卡的驱动程序. 不然就要先搞定无线网卡的驱动再说. 不然后面的步骤也就没必要了. 2. 看一下你的无线网卡叫什么: iw ...

最新文章

  1. centos设置固定IP方法
  2. 2019年安徽省模块七满分多少_二级造价考情分析:20年二级造价考试还有戏吗?...
  3. paper structure for innovation management
  4. 72、android状态栏一体化,状态栏改变颜色
  5. 成人教育计算机统考分数查询江苏省,江苏省教育考试院查询
  6. 概率论 方差公式_概率论与数理统计课程教学、学习基本要求和教学建议
  7. redis高级命令2
  8. 如何使用AOP改进.NET应用程序
  9. phpcms v9 在当前栏目下获取父栏目与当前栏目的名称与连接
  10. 能留住女友的,都是王者
  11. HTML5系列代码:用户注册页面
  12. Hive安装与配置详解
  13. 89c52如何控制ad9833输出正弦波,三角波,方波。
  14. 360驱动器显示服务器失败,360驱动大师显示驱动安装失败该怎么办 - 卡饭网
  15. 类Dota2服务器架构
  16. Java OCR tess4j 图片识别技术(三)
  17. bin和cue怎么合并,BIN和CUE文件如何打开?
  18. SCIgen与野鸡期刊的梗
  19. 《墨宝非宝经典作品合集(套装共10册)》墨宝非宝(作者)epub+mobi+azw3格式下载...
  20. 硕士学论文中的国内图书分类号和国际图书分类号

热门文章

  1. RHEL6上课笔记之background_process_command
  2. ZZULIOJ 1087: 获取出生日期(多实例测试)
  3. matlab在常微分方程的应用,MATLAB在常微分方程上应用.ppt
  4. 联想小新13pro锐龙版网卡_12G大内存 联想小新Air 14锐龙版仅售3799
  5. 信息学奥赛一本通(2062:【例1.3】电影票)
  6. 信息学奥赛一本通(1145:字符串p型编码)
  7. 和为k的连续区间(51Nod-1094)
  8. Summarize to the Power of Two(CF-1005C)
  9. 小鱼的游泳时间(洛谷-P1425)
  10. 27 SD配置-主数据-信用管理-定义风险类别