Ethtool命令詳解

muxinqing發表於2014-03-11

用途
顯示或修改乙太網卡的配置資訊。

語法
ethtool [ -a | -c | -g | -i | -d | -k | -r | -S |] ethX

ethtool [-A] ethX [autoneg on|off] [rx on|off] [tx on|off]

ethtool [-C] ethX [adaptive-rx on|off] [adaptive-tx on|off] [rx-usecs N] [rx-frames N] [rx-usecs-irq N] [rx-frames-irq N] [tx-usecs N] [tx-frames N] [tx-usecs-irq N] [tx-frames-irq N] [stats-block-usecs N][pkt-rate-low N][rx-usecs-low N] [rx-frames-low N] [tx-usecs-low N] [tx-frames-low N] [pkt-rate-high N] [rx-usecs-high N] [rx-frames-high N] [tx-usecs-high N] [tx-frames-high N] [sample-interval N]

ethtool [-G] ethX [rx N] [rx-mini N] [rx-jumbo N] [tx N]

ethtool [-e] ethX [raw on|off] [offset N] [length N]

ethtool [-E] ethX [magic N] [offset N] [value N]

ethtool [-K] ethX [rx on|off] [tx on|off] [sg on|off] [tso on|off]

ethtool [-p] ethX [N]

ethtool [-t] ethX [offline|online]

ethtool [-s] ethX [speed 10|100|1000] [duplex half|full] [autoneg on|off] [port tp|aui|bnc|mii] [phyad N] [xcvr internal|external]

[wol p|u|m|b|a|g|s|d...] [sopass xx:yy:zz:aa:bb:cc] [msglvl N]

描述
Ethtool命令用於獲取乙太網卡的配置資訊,或者修改這些配置。

ethX是乙太網卡的名稱,Linux系統將檢測到的第一塊乙太網卡命名為eth0, 第二塊為eth1,…….。

標誌
-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地址等

示例
檢視機器上網路卡的速度:百兆還是千兆,請輸入:
ethool eth0

操作完畢後,輸出資訊中‘Speed:’ 這一項就指示了網路卡的速度。

停止網路卡的傳送模組TX,請輸入:
ethtool -A tx off eth0

操作完畢後,可輸入:ethtool -a eth0,檢視tx模組是否已被停止。

檢視網路卡eth0採用了何種驅動,請輸入:
ethtool -i eth0

操作完畢後,顯示 driver: bnx2;version: 1.4.30 等資訊。

關閉網路卡對收到的資料包的校驗功能,請輸入:
ethtool -K eth0 rx off

操作完畢後,可輸入:ethtool –k eth0,檢視校驗功能是否已被停止。

如果機器上安裝了兩塊網路卡,那麼eth0對應著哪塊網路卡呢?輸入:
ethtool -p eth0 10

操作完畢後,看哪塊網路卡的led燈在閃,eth0就對應著哪塊網路卡。

檢視網路卡,在接收/傳送資料時,有沒有出錯?請輸入:
ethtool –S eth0

將千兆網路卡的速度降為百兆,請輸入:
ethtool -s eth0 speed 100

資料來源
Ethtool命令顯示的資訊來源於網路卡驅動層,即TCP/IP協議的鏈路層。

該命令在Linux核心中實現的邏輯層次為:

最重要的結構體struct ethtool_ops,該結構體成員為用於顯示或修改乙太網卡配置的一系列函式指標,見下表中的第二列。

網路卡驅動負責實現(部分)這些函式,並將其封裝入ethtool_ops結構體,為網路核心層提供統一的呼叫介面。因此,不同的網路卡驅動會給應用層返回不同的資訊。

Ethtool命令選項、struct ethtool_ops成員函式、Ethtool命令顯示引數的來源,三者間的對應關係如下表所示。

命令選項 struct ethtool_ops成員函式 Ethtool命令顯示引數的來源(以網路卡驅動BNX2為例)

-s
 get_settingsget_wol
get_msglevel

get_link

set_settings

set_wol

set_msglevel
 從網路卡暫存器中獲得網路卡速度等資訊,可配置
-a-A get_pauseparam set_pauseparam 從網路卡暫存器中獲得 Autonegotiate/RX/TX模組的狀態:on or off,可配置
-c-C get_coalesceset_coalesce 從網路卡暫存器中獲得coalescing引數:TX/RX一個資料包後,推遲發生TX/RX中斷的時間(us)/資料包個數。—減小該值可以提高網路卡的響應時間。
當rx-usecs&rx-frames同時被設為0時,RX中斷停止。

當tx-usecs&tx-frames同時被設為0時,TX中斷停止。
 
-g-G get_ringparam set_ringparam 除當前TX/RX ring的值(從網路卡暫存器中讀取得到,可配置)外,其它為網路卡bnx2自己固定的資訊。
-k
-K
 get_rx_csumget_tx_csum
get_sg

get_tso

set_rx_csum

set_tx_csum

set_sg

set_tso
 顯示資訊從儲存該狀態的變數中讀取得到,沒有對應的暫存器。因此,TX/RX校驗等模組一直處於on狀態,實際上是無法修改的。
-i get_drvinfo[self_test_count,
get_stats_coun,t

get_regs_len,

get_eeprom_len]
 網路卡bnx2自己固定的資訊,如——————————————————–
driver: bnx2

version: 1.4.30

firmware-version: 1.8.0.5

bus-info: 0000:09:00.0

——————————————————–
 
-d get_drvinfoget_regs 不支援,即bnx2中沒有實現函式get_regs
-e-E get_eepromset_eeprom 不支援,即bnx2中沒有實現函式get_eeprom
-r nway_reset 配置網路卡MII_BMCR暫存器,重啟Auto negotiation模組
-p phys_id 配置網路卡BNX2_EMAC_LED暫存器,實現LED閃功能
-t self_test 透過配置網路卡暫存器,逐一測試網路卡的硬體模組:registers,memory,loopback,Link stat,interrupt
-S get_ethtool_stats 顯 示資訊來源於網路卡驅動中的結構體變數stats_blk。(網路卡透過DMA方式,將暫存器BNX2_HC_STATISTICS _ADDR_L和BNX2_HC_STATISTICS_ADDR_H中的資料實時地讀取到結構體變數struct statistics_block *stats_blk中。)
—顯示的資料都是從網路卡暫存器中統計得到的,各項的含義需查詢網路卡(晶片)手冊。
 

由上可見,ethtool命令用於顯示/配置網路卡硬體(暫存器)。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29065182/viewspace-1107161/,如需轉載,請註明出處,否則將追究法律責任。