溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Linux ethtool命令怎么用

發(fā)布時(shí)間:2022-02-08 15:47:56 來(lái)源:億速云 閱讀:202 作者:iii 欄目:開發(fā)技術(shù)

本篇內(nèi)容主要講解“Linux ethtool命令怎么用”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“Linux ethtool命令怎么用”吧!

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

Linux ethtool命令怎么用

ethtool

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

語(yǔ)法

 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):?jiǎn)?dòng)on 或 停用off。
 -A 修改網(wǎng)卡中 接收模塊RX、發(fā)送模塊TX和Autonegotiate模塊的狀態(tài):?jiǎn)?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對(duì)應(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í)行自我檢測(cè),有兩種模式:offline or online。
 -s 修改網(wǎng)卡的部分配置,包括網(wǎng)卡速度、單工/全雙工模式、mac地址等。

數(shù)據(jù)來(lái)源

Ethtool命令顯示的信息來(lái)源于網(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ù)的來(lái)源,三者間的對(duì)應(yīng)關(guān)系如下表所示:

命令選項(xiàng)struct ethtool_ops成員函數(shù)Ethtool命令顯示參數(shù)的來(lái)源(以網(wǎng)卡驅(qū)動(dòng)BNX2為例)
無(wú) -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ù)。—減小該值可以提高網(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)的變量中讀取得到,沒有對(duì)應(yīng)的寄存器。因此,TX/RX校驗(yàn)等模塊一直處于on狀態(tài),實(shí)際上是無(wú)法修改的。
-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通過(guò)配置網(wǎng)卡寄存器,逐一測(cè)試網(wǎng)卡的硬件模塊:registers,memory,loopback,Link stat,interrupt。
-Sget_ethtool_stats顯示信息來(lái)源于網(wǎng)卡驅(qū)動(dòng)中的結(jié)構(gòu)體變量stats_blk。(網(wǎng)卡通過(guò)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)卡(芯片)手冊(cè)。

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

實(shí)例

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

 ethool eth0

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

 ethtool -A tx off eth0

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

 ethtool -i eth0

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

 ethtool -K eth0 rx off

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

 ethtool -p eth0 10

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

 ethtool –S eth0

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

ethtool -s eth0 speed 100

到此,相信大家對(duì)“Linux ethtool命令怎么用”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI