Linux命令 ethtool - 顯示或修改以太網(wǎng)卡的配置信息

2021-11-09 10:55 更新

ethtool

顯示或修改以太網(wǎng)卡的配置信息

補(bǔ)充說明

ethtool命令用于獲取以太網(wǎng)卡的配置信息,或者修改這些配置。這個(gè)命令比較復(fù)雜,功能特別多。

語法

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-lowN] [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]

選項(xiàng)

-a 查看網(wǎng)卡中 接收模塊RX、發(fā)送模塊TX和Autonegotiate模塊的狀態(tài):啟動(dòng)on 或 停用off。
-A 修改網(wǎng)卡中 接收模塊RX、發(fā)送模塊TX和Autonegotiate模塊的狀態(tài):啟動(dòng)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 顯示網(wǎng)卡驅(qū)動(dòng)的信息,如驅(qū)動(dòng)的名稱、版本等。
-d 顯示register dump信息, 部分網(wǎng)卡驅(qū)動(dòng)不支持該選項(xiàng)。
-e 顯示EEPROM dump信息,部分網(wǎng)卡驅(qū)動(dòng)不支持該選項(xiàng)。
-E 修改網(wǎng)卡EEPROM byte。
-k 顯示網(wǎng)卡Offload參數(shù)的狀態(tài):on 或 off,包括rx-checksumming、tx-checksumming等。
-K 修改網(wǎng)卡Offload參數(shù)的狀態(tài)。
-p 用于區(qū)別不同ethX對應(yīng)網(wǎng)卡的物理位置,常用的方法是使網(wǎng)卡port上的led不斷的閃;N指示了網(wǎng)卡閃的持續(xù)時(shí)間,以秒為單位。
-r 如果auto-negotiation模塊的狀態(tài)為on,則restarts auto-negotiation。
-S 顯示NIC- and driver-specific 的統(tǒng)計(jì)參數(shù),如網(wǎng)卡接收/發(fā)送的字節(jié)數(shù)、接收/發(fā)送的廣播包個(gè)數(shù)等。
-t 讓網(wǎng)卡執(zhí)行自我檢測,有兩種模式:offline or online。
-s 修改網(wǎng)卡的部分配置,包括網(wǎng)卡速度、單工/全雙工模式、mac地址等。

數(shù)據(jù)來源

Ethtool命令顯示的信息來源于網(wǎng)卡驅(qū)動(dòng)層,即TCP/ip協(xié)議的鏈路層。該命令在Linux內(nèi)核中實(shí)現(xiàn)的邏輯層次為:

最重要的結(jié)構(gòu)體struct ethtool_ops,該結(jié)構(gòu)體成員為用于顯示或修改以太網(wǎng)卡配置的一系列函數(shù)指針,見下表中的第二列。

網(wǎng)卡驅(qū)動(dòng)負(fù)責(zé)實(shí)現(xiàn)(部分)這些函數(shù),并將其封裝入ethtool_ops結(jié)構(gòu)體,為網(wǎng)絡(luò)核心層提供統(tǒng)一的調(diào)用接口。因此,不同的網(wǎng)卡驅(qū)動(dòng)會(huì)給應(yīng)用層返回不同的信息。Ethtool命令選項(xiàng)、struct ethtool_ops成員函數(shù)、Ethtool命令顯示參數(shù)的來源,三者間的對應(yīng)關(guān)系如下表所示:

命令選項(xiàng)struct ethtool_ops成員函數(shù)Ethtool命令顯示參數(shù)的來源(以網(wǎng)卡驅(qū)動(dòng)BNX2為例)
無 -sget_settingsget_wol get_msglevel get_link set_settings set_wol set_msglevel從網(wǎng)卡寄存器中獲得網(wǎng)卡速度等信息,可配置。
-a -Aget_pauseparam set_pauseparam從網(wǎng)卡寄存器中獲得Autonegotiate/RX/TX模塊的狀態(tài):on oroff,可配置。
-c -Cget_coalesceset_coalesce從網(wǎng)卡寄存器中獲得coalescing參數(shù):TX/RX一個(gè)數(shù)據(jù)包后,推遲發(fā)生TX/RX中斷的時(shí)間(us)/數(shù)據(jù)包個(gè)數(shù)?!獪p小該值可以提高網(wǎng)卡的響應(yīng)時(shí)間。 當(dāng)rx-usecs&rx-frames同時(shí)被設(shè)為0時(shí),RX中斷停止。 當(dāng)tx-usecs&tx-frames同時(shí)被設(shè)為0時(shí),TX中斷停止。
-g -Gget_ringparam set_ringparam除當(dāng)前TX/RX ring的值(從網(wǎng)卡寄存器中讀取得到,可配置)外,其它為網(wǎng)卡bnx2自己固定的信息。
-k -Kget_rx_csumget_tx_csum get_sg get_tso set_rx_csum set_tx_csum set_sg set_tso顯示信息從保存該狀態(tài)的變量中讀取得到,沒有對應(yīng)的寄存器。因此,TX/RX校驗(yàn)等模塊一直處于on狀態(tài),實(shí)際上是無法修改的。
-iget_drvinfo[self_test_count, get_stats_coun,t get_regs_len, get_eeprom_len]網(wǎng)卡bnx2自己固定的信息,如: ——————————————————– driver: bnx2 version: 1.4.30 firmware-version: 1.8.0.5 bus-info: 0000:09:00.0 ——————————————————–
-dget_drvinfoget_regs不支持,即bnx2中沒有實(shí)現(xiàn)函數(shù)get_regs。
-e -Eget_eepromset_eeprom不支持,即bnx2中沒有實(shí)現(xiàn)函數(shù)get_eeprom。
-rnway_reset配置網(wǎng)卡MII_BMCR寄存器,重啟Auto negotiation模塊。
-pphys_id配置網(wǎng)卡BNX2_EMAC_LED寄存器,實(shí)現(xiàn)LED閃功能。
-tself_test通過配置網(wǎng)卡寄存器,逐一測試網(wǎng)卡的硬件模塊:registers,memory,loopback,Link stat,interrupt。
-Sget_ethtool_stats顯示信息來源于網(wǎng)卡驅(qū)動(dòng)中的結(jié)構(gòu)體變量stats_blk。(網(wǎng)卡通過DMA方式,將寄存器BNX2_HC_STATISTICS _ADDR_L和BNX2_HC_STATISTICS_ADDR_H中的數(shù)據(jù)實(shí)時(shí)地讀取到結(jié)構(gòu)體變量struct statistics_block *stats_blk中。) —顯示的數(shù)據(jù)都是從網(wǎng)卡寄存器中統(tǒng)計(jì)得到的,各項(xiàng)的含義需查詢網(wǎng)卡(芯片)手冊。

由上可見,ethtool命令用于顯示/配置網(wǎng)卡硬件(寄存器)。  

實(shí)例

查看機(jī)器上網(wǎng)卡的速度:百兆還是千兆,請輸入:

ethool eth0

操作完畢后,輸出信息中Speed:這一項(xiàng)就指示了網(wǎng)卡的速度。停止網(wǎng)卡的發(fā)送模塊TX,請輸入:

ethtool -A tx off eth0

操作完畢后,可輸入ethtool -a eth0,查看tx模塊是否已被停止。查看網(wǎng)卡eth0采用了何種驅(qū)動(dòng),請輸入:

ethtool -i eth0

操作完畢后,顯示 driver: bnx2;version: 1.4.30 等信息。關(guān)閉網(wǎng)卡對收到的數(shù)據(jù)包的校驗(yàn)功能,請輸入:

ethtool -K eth0 rx off

操作完畢后,可輸入ethtool –k eth0,查看校驗(yàn)功能是否已被停止。如果機(jī)器上安裝了兩塊網(wǎng)卡,那么eth0對應(yīng)著哪塊網(wǎng)卡呢?輸入:

ethtool -p eth0 10

操作完畢后,看哪塊網(wǎng)卡的led燈在閃,eth0就對應(yīng)著哪塊網(wǎng)卡。查看網(wǎng)卡,在接收/發(fā)送數(shù)據(jù)時(shí),有沒有出錯(cuò)?請輸入:

ethtool –S eth0

將千兆網(wǎng)卡的速度降為百兆,請輸入:

ethtool -s eth0 speed 100


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)