題 如何解釋netstat -o / netstat --timers的輸出


netstat -o 包括輸出中的一些計時器信息,但我還沒有找到輸出的解釋 Timer 列任何地方。
任何人都可以解釋這一點或指出解釋嗎?

這就是netstat -o的ouptput看起來像(在Ubuntu 8.04上)。

Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       Timer
tcp        0      0 192.168.22.1:443        111.111.11.210:5804     ESTABLISHEDkeepalive (6176.47/0/0)
tcp        0      0 192.168.22.1:443        192.168.22.253:48379    TIME_WAIT  timewait (36.57/0/0)
tcp        0    924 192.168.22.1:47763      10.9.169.60:443         ESTABLISHEDon (0.34/0/0)
tcp        0      0 192.168.22.1:443        192.168.111.99:4059     ESTABLISHEDkeepalive (6963.60/0/0)
tcp        0      0 192.168.22.1:443        192.168.111.74:1729     ESTABLISHEDkeepalive (1393.60/0/0)
tcp        0      0 192.168.56.1:42204      10.9.169.60:443         ESTABLISHEDoff (0.00/0/0)
tcp        0      0 192.168.56.1:42207      10.9.169.60:443         ESTABLISHEDoff (0.00/0/0)
tcp        0    940 192.168.22.1:42186      10.9.169.60:443         ESTABLISHEDon (0.28/0/0)
tcp        0      0 192.168.22.1:443        192.168.22.253:48367    TIME_WAIT  timewait (31.57/0/0)
tcp        0      0 192.168.22.1:42234      10.9.169.60:443         ESTABLISHEDoff (0.00/0/0)
tcp        0      0 192.168.22.1:42209      10.9.169.60:443         ESTABLISHEDoff (0.00/0/0)

16
2018-02-01 17:05


起源




答案:


第一個數字顯然是倒數計時器。根據狀態類型,一旦定時器超時,它將重試並發送另一個FIN或任何需要的數據包再試一次。所以第二個數字跟踪重試次數。請注意,計時器會增加,因為TCP具有退避計時器,以防出現流量情況。退避定時器避免了過度頻繁的重試。每次失敗都會導致越來越大的退避。退避可以是指數增長或線性,取決於TCP堆棧。我還沒弄明白這個數字是為了什麼。在我的顯示器中始終為零。


6
2017-10-20 06:34





計時器列有兩個字段(來自上面的o / p):

keepalive (6176.47/0/0)  
<1st field> <2nd field>

1st field 可以有價值:
keepalive  - 當套接字的keepalive定時器為ON時
on  - 當套接字的重傳定時器為ON時
off  - 以上都沒有開啟

2nd field 有三個子字段:

(6176.47/0/0) -> (a/b/c)

a=定時器值(a = keepalive定時器,當1st field =“keepalive”時; a =重傳定時器,當1st field =“on”時)
b=已發生的重新傳輸次數
c=已發送的keepalive探測器的數量

例如,我在客戶端和服務器之間打開了兩個套接字(不是環回)。 keepalive設置為:

KEEPALIVE_IDLETIME   30
KEEPALIVE_NUMPROBES   4
KEEPALIVE_INTVL      10

我關閉了客戶機,所以在服務器端我運行了一個netstat,輸出是:

端口1:

netstat -c --timer | grep "192.0.0.1:43245             192.0.68.1:49742"

tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (1.92/0/0)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (0.71/0/0)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (9.46/0/1)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (8.30/0/1)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (7.14/0/1)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (5.98/0/1)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (4.82/0/1)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (3.66/0/1)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (2.50/0/1)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (1.33/0/1)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (0.17/0/1)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (9.01/0/2)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (7.75/0/2)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (6.47/0/2)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (5.29/0/2)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (4.08/0/2)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (2.89/0/2)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (1.73/0/2)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (0.54/0/2)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (9.38/0/3)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (8.23/0/3)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (7.08/0/3)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (5.93/0/3)                                                                                                                               
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (4.76/0/3)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (3.62/0/3)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (2.48/0/3)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (1.32/0/3)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (0.13/0/3)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (8.98/0/4)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (7.78/0/4)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (6.62/0/4)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (5.45/0/4)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (4.29/0/4)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (3.14/0/4)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (1.99/0/4)
tcp        0      0 192.0.0.1:43245             192.0.68.1:49742            ESTABLISHED keepalive (0.85/0/4)

您可以看到上面的服務器發送了四個keepalive探測器,每個探測器在10秒後發現並且由於沒有得到任何響應,探測器發送的數量會增加,而在4之後,它會斷開與客戶端的連接。

港口2:

對於第二個連接,套接字是相同的,除了,我的服務器端應用程序試圖在客戶端關閉之後和keepalive過期之前發送一些消息:

 netstat -c --timer | grep "192.0.0.1:36483             192.0.68.1:43881"

tcp        0      0 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED keepalive (8.18/0/1)
tcp        0      0 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED keepalive (7.00/0/1)
tcp        0      0 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED keepalive (5.86/0/1)
tcp        0      0 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED keepalive (4.71/0/1)
tcp        0      0 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED keepalive (3.55/0/1)
tcp        0      0 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED keepalive (2.40/0/1)                                                                                                                               
tcp        0      0 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED keepalive (1.21/0/1)
tcp        0      0 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED keepalive (0.05/0/1)
tcp        0      0 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED keepalive (8.91/0/2)
tcp        0      0 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED keepalive (7.75/0/2)
tcp        0      0 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED keepalive (6.56/0/2)
tcp        0      0 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED keepalive (5.39/0/2)
tcp        0      0 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED keepalive (4.14/0/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (0.21/2/2)  // <---- retransmission timer kicks in
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (0.68/3/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (2.74/4/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (1.59/4/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (0.43/4/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (2.28/5/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (1.11/5/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (2.95/6/2)

. . . . . 

tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (0.65/249/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (2.58/250/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (1.48/250/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (0.36/250/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (2.26/251/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (1.15/251/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (3.01/252/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (1.92/252/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (0.84/252/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (2.72/253/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (1.64/253/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (0.55/253/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (2.47/254/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (1.39/254/2)                                                                                                                                    
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (0.31/254/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (2.19/255/2)
tcp        0    210 192.0.0.1:36483             192.0.68.1:43881            ESTABLISHED on (1.12/255/2)

正如您所看到的,在這種情況下,事情會有所不同。當客戶端發生故障時,我的服務器開始發送keepalive消息,但是當它仍然發送這些keepalive時,我的服務器試圖向客戶端發送消息。由於客戶端已關閉,服務器無法從客戶端獲取任何ACK,因此TCP重新啟動並且服務器嘗試再次發送數據,每次在重傳計時器(第1個字段)時遞增重新傳輸計數(第1個字段)字段)已過期。

希望這能解釋一下 netstat --timer 選擇好。


26
2018-04-22 15:19



你好。如果你打開了 一 連接,為什麼netstat顯示這麼多條目? - Marco Marsala
'-c'標誌使其每秒連續打印此信息。 - brokenfoot


第一場: timewait/keepalive

從最後一個數據傳輸到下一個TCP keepalive探測將被發送的時間(以秒為單位)。

默認情況下,此操作從7200開始,每次發送更多數據時都會重置。如果該值較低,例如。 4000秒,這意味著一些保持活動的連接在很長一段時間內掛起或什麼都不做。

與內部代理或其他內部進程的連接可能會掛起更長時間,但這不應發生在基於Web的連接上。


0
2018-06-18 07:37



為了避免在Linux上出現混淆:計時器可見 netstat -o 但它永遠不會重置,它會計數到0,然後檢查數據是否已發送。如果不是它會發送一個數據包,否則如果將計算剩餘時間並重新開始。這樣它就不需要更改正在運行的計時器。 - eckes