运维开发网

ubuntu-12.04 – 当sysctl tcp_retries1设置为3时,TCP数据包被重传7次 – 为什么?

运维开发网 https://www.qedev.com 2020-04-24 13:50 出处:网络 作者:运维开发网整理
Ubuntu 12.04 我试图更好地了解当TCP没有收到目的地收到的确认时,TCP将尝试重新传输数据包的次数.读完tcp man page后,似乎很清楚这是由sysctl tcp_retries1控制的:
Ubuntu 12.04

我试图更好地了解当TCP没有收到目的地收到的确认时,TCP将尝试重新传输数据包的次数.读完tcp man page后,似乎很清楚这是由sysctl tcp_retries1控制的:

tcp_retries1 (integer; default: 3)
           The number of times TCP will attempt to retransmit a  packet  on
           an  established connection normally, without the extra effort of
           getting the network layers involved.  Once we exceed this number
           of retransmits, we first have the network layer update the route
           if possible before each new retransmit.  The default is the  RFC
           specified minimum of 3.

我的系统设置为默认值3:

# cat /proc/sys/net/ipv4/tcp_retries1 
3

为了测试这个,我通过ssh从系统A(172.16.249.138)连接到系统B(172.16.249.137),并在控制台上启动了一个简单的打印循环.然后,当这种通信发生时,我突然断开了B与网络的连接.

在另一个终端中,我在系统A上运行’tcpdump host 172.16.249.137′.下面是输出中的相关行(为清晰起见,添加了行号).

00: ...
01: 13:29:46.994715 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [.], ack 5989441, win 80, options [nop,nop,TS val 1957286 ecr 4294962520], length 0
02: 13:29:46.995084 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [.], ack 5989441, win 186, options [nop,nop,TS val 1957286 ecr 4294962520], length 0    
03: 13:29:47.040360 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [P.], seq 29136:29184, ack 5989441, win 186, options [nop,nop,TS val 1957298 ecr 4294962520], length 48
04: 13:29:47.086552 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [.], ack 5989441, win 376, options [nop,nop,TS val 1957309 ecr 4294962520], length 0
05: 13:29:47.680608 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [P.], seq 29136:29184, ack 5989441, win 376, options [nop,nop,TS val 1957458 ecr 4294962520], length 48
06: 13:29:48.963721 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [P.], seq 29136:29184, ack 5989441, win 376, options [nop,nop,TS val 1957779 ecr 4294962520], length 48
07: 13:29:51.528564 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [P.], seq 29136:29184, ack 5989441, win 376, options [nop,nop,TS val 1958420 ecr 4294962520], length 48
08: 13:29:56.664384 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [P.], seq 29136:29184, ack 5989441, win 376, options [nop,nop,TS val 1959704 ecr 4294962520], length 48
09: 13:30:06.936480 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [P.], seq 29136:29184, ack 5989441, win 376, options [nop,nop,TS val 1962272 ecr 4294962520], length 48
10: 13:30:27.480381 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [P.], seq 29136:29184, ack 5989441, win 376, options [nop,nop,TS val 1967408 ecr 4294962520], length 48
11: 13:31:08.504033 IP 172.16.249.138.50489 > 172.16.249.137.ssh: Flags [P.], seq 29136:29184, ack 5989441, win 376, options [nop,nop,TS val 1977664 ecr 4294962520], length 48
12: 13:31:13.512437 ARP, Request who-has 172.16.249.137 tell 172.16.249.138, length 28
13: 13:31:14.512336 ARP, Request who-has 172.16.249.137 tell 172.16.249.138, length 28
14: 13:31:15.512241 ARP, Request who-has 172.16.249.137 tell 172.16.249.138, length 28

如果我正确地解释了这一点(我可能不是这样),系统B永远不会确认第3行的数据包.然后每次重新发送此数据包7次(第5-11行),每次增加其重传计时器(每次大约加倍)时间).

为什么数据包被重传7次而不是3次?

注意:我在注意到几个pcap文件之后执行了这个正式测试,其中重新发送通过HTTP连接发生了6-7次,因此重新发送的数量似乎不是特定于SSH的.

我相信您通过终止.137服务器上的连接创建了一个孤立套接字.因此,使用的内核参数是tcp_orphan_retries – 其默认值为7.

您可以在此处获得您创建的条件和结果的描述:http://www.Linuxinsight.com/proc_sys_net_ipv4_tcp_orphan_retries.html

0

精彩评论

暂无评论...
验证码 换一张
取 消