Linux命令——ethtool


參考:9 Linux ethtool Examples to Manipulate Ethernet Card (NIC Card)

Fun with ethtool

簡介

ethtool允許你修改Ethernet adapter配置,並且這種修改只適用於physical ethernet adapters,這意味着bond0,tun0和任何其他非物理網絡設備將無法與ethtool一起使用。

注意:大多數Linux內核將以太網設備標記為ethX,其中X是物理以太網接口的#(從0開始)。

我知道我知道,先從最少使用的東西開始。 但是,嘿,有人可能覺得這很有用,對嗎? 在處理內核級別問題時,我可能不得不在10年以上查詢驅動程序信息十幾次,但有人必須在他們生命中的某個時刻遇到這個問題,讓我告訴你,它可能更容易 運行一個命令,而不是通過lsmod挖掘並希望模塊正確地拾取驅動程序。

驅動信息 和 統計數據

在處理內核級別的問題時,人們往往會使用lsmod來查看相應驅動是否被加載,使用ethtool可以更優雅的解決這個問題。

-i:Queries the specified network device for associated driver information.

root@ubuntu:~# ethtool -i ens32
driver: e1000
version: 7.3.21-k8-NAPI
firmware-version: 
expansion-rom-version: 
bus-info: 0000:02:00.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: no

-S(大寫):Queries the specified network device for NIC- and driver-spe‐cific statistics.

這個參數可以快速定位 rx/tx問題

root@ubuntu:~# ethtool -S ens32
NIC statistics:
     rx_packets: 380
     tx_packets: 386
     rx_bytes: 42819
     tx_bytes: 81789
     rx_broadcast: 0
     tx_broadcast: 0
     rx_multicast: 0
     tx_multicast: 0
     rx_errors: 0
     tx_errors: 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_no_buffer_count: 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
     tx_abort_late_coll: 0
     tx_deferred_ok: 0
     tx_single_coll_ok: 0
     tx_multi_coll_ok: 0
     tx_timeout_count: 0
     tx_restart_queue: 0
     rx_long_length_errors: 0
     rx_short_length_errors: 0
     rx_align_errors: 0
     tx_tcp_seg_good: 1
     tx_tcp_seg_failed: 0
     rx_flow_control_xon: 0
     rx_flow_control_xoff: 0
     tx_flow_control_xon: 0
     tx_flow_control_xoff: 0
     rx_long_byte_count: 42819
     rx_csum_offload_good: 358
     rx_csum_offload_errors: 0
     alloc_rx_buff_failed: 0
     tx_smbus: 0
     rx_smbus: 0
     dropped_smbus: 0

跟蹤網卡

當一台服務器上有多張網卡,查找具體某一張物理網卡往往十分令人頭疼。當然,你可以這么做:從ifconfig中取出MAC地址,將所有電纜插入一個管理型交換機,然后在交換機上將Mac表導出,查看具體Mac指向哪里。 使用ethtool可以更優雅地解決這個問題。

-p:Initiates adapter-specific action intended to enable an oper‐ator to easily identify the adapter by sight. Typically this involves blinking one or more LEDs on the specific network port.

ethtool -p ethX [N] 

其中[N]是閃爍的秒數。 ethtool -p eth0 15使eth0閃爍15秒。此時,太網適配器背面的指示燈閃爍會閃爍。

測試Ethernet Adapter

可以針對物理以太網接口運行一些基本測試,測試有兩個選項,一個online test(tests nvram and a link test)和一個offline test(register, memory, loopback, interrupt)。 脫機測試很可能在測試期間使主機離線,因此如果你對生產服務器或只能遠程訪問的計算機運行此操作,請特別注意。

ethtool -t ethX [offline|online] 
root@ubuntu:~# ethtool -t ens32 online
The test result is PASS
The test extra info:
Register test  (offline)     0
Eeprom test    (offline)     0
Interrupt test (offline)     0
Loopback test  (offline)     0
Link test   (on/offline)     0

root@ubuntu:~# ethtool -t ens32 offline
The test result is FAIL
The test extra info:
Register test  (offline)     0
Eeprom test    (offline)     0
Interrupt test (offline)     0
Loopback test  (offline)     13
Link test   (on/offline)     0

一些網卡可能不支持online test 或者 offline test

改變Ethernet 配置

ethtool ethX

檢查網卡配置信息

root@ubuntu:~# ethtool ens32
Settings for ens32:
    Supported ports: [ TP ]
    Supported link modes:   10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Full 
    Supported pause frame use: No
    Supports auto-negotiation: Yes
    Advertised link modes:  10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Full 
    Advertised pause frame use: No
    Advertised auto-negotiation: Yes
    partner advertised link modes:	10baseT/Half 10baseT/Full
                         	        100baseT/Half 100baseT/Full
    Link partner advertised pause frame use: No 
    Link partner advertised auto-negotiation: Yes 
    Speed: 1000Mb/s 
Duplex: Full
Port: Twisted Pair
PHYAD:
0
Transceiver: internal
Auto
-negotiation: on
MDI
-X: off (auto)
Supports Wake
-on: d
Wake
-on: d
Current message level:
0x00000007 (7) drv probe link
Link detected: yes

可以得出結論:設備支持TP,最高1000BaseT/Full,自動協商。 Partner(Switch)支持最高100baseT / Full和自動協商。設備的實際設置:100Mb / s,全雙工,運行TP,物理地址0,設置為自動協商,啟用WoL並檢測鏈路。

如果我網卡的支持鏈接模式設置為low(例如10/Half由於某種原因)但交換機支持1000baseT / Full,那么可以使用ethtool -s ethX將我的以太網設置更改為1000baseT / Full。幾乎所有你看到的東西:ethtool ethX,可以用ethtool -s ethX改變。在這種情況下,您將使用以下內容:

ethtool -S eth0 speed 1000 duplex full autoneg on

 -s(小寫):Allows changing some or all settings of the specified network device. All following options only apply if -s was specified.

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM