Ubuntu-12.04

當 sysctl tcp_retries1 設置為 3 時,TCP 數據包被重傳 7 次 - 為什麼?

  • August 19, 2014

Ubuntu 12.04

我試圖更好地了解當 TCP 沒有收到目的地收到的確認時,它會嘗試重新傳輸數據包的次數。閱讀tcp 手冊頁後,似乎很清楚這是由 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

如果我正確地解釋了這一點(我可能不是),第 3 行的數據包永遠不會被系統 B 確認。然後 A 重試發送該數據包 7 次(第 5-11 行),每次增加其重傳計時器(每次大約加倍)時間)。

為什麼數據包被重傳 7 次而不是 3 次?

注意:在註意到一些 pcap 文件在 HTTP 連接上發生 6-7 次重傳後,我執行了這個正式測試,因此重傳次數似乎並不特定於 SSH。

我相信您通過終止 .137 伺服器上的連接創建了一個孤立套接字。因此,使用的核心參數將是 tcp_orphan_retries - 它的通用 linux 預設值為 7。

您可以在此處獲得對您創建的條件和結果的描述: http ://www.linuxinsight.com/proc_sys_net_ipv4_tcp_orphan_retries.html

引用自:https://serverfault.com/questions/583674