Ifconfig

ifconfig 顯示錯誤的 RX/TX 字節數

  • May 25, 2012

ifconfig 告訴 eth0 一些 RX = 2,8GB, TX = 1,3GB 值,這是不可能的,因為我最近通過 eth0 傳輸了許多 10GB+ 文件。我想知道

  • 如果這只是一些普通的整數溢出(4GB 限制)
  • 或者如果這表明存在一些包含錯誤數據的邪惡 rootkit

這是一個愚蠢的問題,但這種差異讓我很困擾。

謝謝你,尼爾斯

我會說它是您所猜測的 4GB 環繞。我用最近的 32 位 linux 核心遇到了這個問題。

您可以獲取核心的原始碼並查看它是否相同include/linux/netdevice.h並檢查net_device_stats->rx_bytes. 如果您使用的是 32 位系統並且時間是無符號長整數,那麼您將僅獲得 2^32 字節或 4 GB。更多關於這在我的一篇文章這裡

當然,除非 ifconfig 抓取的是這些天除了 proc 之外的某個地方的計數器…

您可以設置 iptables 來管理計數器 - 甚至可以通過保存/恢復或手動清除/將計數器設置為特定值來使它們在重啟後存活。

如果您還沒有 iptables 規則,您只需在輸入和輸對外連結中添加至少一個規則,例如允許所有內容,它將提供您想要的內容:

iptables -A INPUT -j ACCEPT
iptables -A OUTPUT -j ACCEPT

然後你可以看到總數:

root@devcloner:~# iptables -n -vL
Chain INPUT (policy ACCEPT 2850K packets, 4183M bytes)
pkts bytes target     prot opt in     out     source               destination         
22M   32G ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 657K packets, 43M bytes)
pkts bytes target     prot opt in     out     source               destination         
12951  813K ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           

-x 將顯示完整的字節計數器:

root@devcloner:~# iptables -n -vL -x
Chain INPUT (policy ACCEPT 2850263 packets, 4182667884 bytes)
       pkts      bytes target     prot opt in     out     source                   destination         
22285352 32724735127 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0        

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
   pkts      bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 657099 packets, 43320848 bytes)
   pkts      bytes target     prot opt in     out     source               destination         
 102453  6738544 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0  

該資訊可能也可以從 /proc 或 /sys 的某個地方解析。

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