用ethtool 命令解決Linux 網卡丟包__Linux
來源:互聯網
上載者:User
生產中有一台Linux裝置並發比較大,droped包比較多,尤其是在跑遊戲資料包的時候,存在嚴重的丟包現象,懷疑網卡效能不足,在更換裝置前想能不有通過軟體方法解決,通過網上一些資料顯示,出現這種現象,也有可能是網卡buffer size 太小的原因,遂嘗試更改buffer 大小解決,下面的裝置運行了64天,丟包超過20多億 .
ethtool命令用於擷取乙太網路卡的配置資訊,或者修改這些配置
-a 查看網卡中 接收模組RX、發送模組TX和Autonegotiate模組的狀態:啟動on 或 停用off。
-A 修改網卡中 接收模組RX、發送模組TX和Autonegotiate模組的狀態:啟動on 或 停用off。
-c display the Coalesce information of the specified ethernet card。
-C Change the Coalesce setting of the specified ethernet card。
-g Display the rx/tx ring parameter information of the specified ethernet card。
-G change the rx/tx ring setting of the specified ethernet card。
-i 顯示網卡驅動的資訊,如驅動的名稱、版本等。
-d 顯示register dump資訊, 部分網卡驅動不支援該選項。
-e 顯示EEPROM dump資訊,部分網卡驅動不支援該選項。
-E 修改網卡EEPROM byte。
-k 顯示網卡Offload參數的狀態:on 或 off,包括rx-checksumming、tx-checksumming等。
-K 修改網卡Offload參數的狀態。
-p 用於區別不同ethX對應網卡的物理位置,常用的方法是使網卡port上的led不斷的閃;N指示了網卡閃的期間,以秒為單位。
-r 如果auto-negotiation模組的狀態為on,則restarts auto-negotiation。
-S 顯示NIC- and driver-specific 的統計參數,如網卡接收/發送的位元組數、接收/發送的廣播包個數等。
-t 讓網卡執行自我檢測,有兩種模式:offline or online。
-s 修改網卡的部分配置,包括網卡速度、單工/全雙工系統模式、mac地址等。
查看當前網卡的buffer size情況 ethtool -g eth0
Ring parameters for eth0:
Pre-set maximums:
RX: 4096RX Mini: 0
RX Jumbo: 0
TX: 4096
Current hardware settings:
RX: 256
RX Mini: 0
RX Jumbo: 0
TX: 256
由於我的是rx包會有droped的情況
我們用ethtool -G eth0 rx 2048
同樣對於eth1也是如此 ethtool -G eth1 rx 2048
再看看修改過後的ethtool -g eth0
Ring parameters for eth0:
Pre-set maximums:
RX: 4096
RX Mini: 0
RX Jumbo: 0
TX: 4096
Current hardware settings:
RX: 2048
RX Mini: 0
RX Jumbo: 0
TX: 2048
命令描述:
ethtool 是用於查詢及設定網卡參數的命令。
使用概要:
ethtool ethx //查詢ethx網口基本設定,其中 x 是對應網卡的編號,如eth0、eth1等等
ethtool –h //顯示ethtool的命令協助(help)
ethtool –i ethX //查詢ethX網口的相關資訊
ethtool –d ethX //查詢ethX網口註冊性資訊
ethtool –r ethX //重設ethX網口到自適應模式
ethtool –S ethX //查詢ethX網口收發包統計
ethtool –s ethX [speed 10|100|1000] [duplex half|full] [autoneg on|off] //設定網口速率10/100/1000M、設定網口半/全雙工系統、設定網口是否自協商
使用舉例:
1)[root@Linux /]# ethtool eth1
Settings for eth1:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: umbg
Wake-on: d
Link detected: yes
2)[root@linux /]# ethtool -i eth1
driver: e1000
version: 5.0.43-k1
firmware-version: N/A
bus-info: 06:08.1
3)[root@linux /]# ethtool -S eth1
NIC statistics:
rx_packets: 58068300
tx_packets: 87124083
rx_bytes: 1589713008
tx_bytes: 2165825901
rx_errors: 0
tx_errors: 0
rx_dropped: 0
tx_dropped: 0
multicast: 0
collisions: 0
rx_length_errors: 0
rx_over_errors: 0
rx_crc_errors: 0
rx_frame_errors: 0
rx_fifo_errors: 0
rx_missed_errors: 0
tx_aborted_errors: 0
tx_carrier_errors: 0
tx_fifo_errors: 0
tx_heartbeat_errors: 0
tx_window_errors: 0
4)[root@linux /]# ethtool -s eth1 autoneg off speed 100 duplex full
相關參考:
1)[root@linux /]# which ethtool //查詢 ethtool 存放的路徑
/sbin/ethtool
2)[root@linux /]# rpm -qf /sbin/ethtool //查詢 ethtool 的版本資訊
ethtool-1.6-5
3)將 ethtool 設定永久儲存在網路裝置的方法
解決方案一:
ethtool 設定可通過 /etc/sysconfig/network-scripts/ifcfg-ethX 檔案儲存,從而在裝置下次啟動時啟用選項 。
例如:ethtool -s eth0 speed 100 duplex full autoneg off
此指令將eth0裝置設定為全雙工系統自適應,速度為100Mbs。若要eth0啟動時設定這些參數, 修改檔案/etc/sysconfig/network-scripts/ifcfg-eth0 ,
添加如下一行:
ETHTOOL_OPTS="speed 100 duplex full autoneg off"