使用ethtool查看MAC和PHY的相關信息


查看MAC和PHY配置和狀態工具有 mii-tool/ethtool. 經常使用的工具是ethtool, ethtool可以詳細的描述MAC和PHY的相關信息,包括寄存器的配置,相關的統計。

使用語法

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]

命令參數說明

-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  修改網卡的部分配置,包括網卡速度、單工/全雙工模式、mac地址等。加上-s選項修改的內容才會生效

-S  顯示NIC- and driver-specific 的統計參數,如網卡接收/發送的字節數、接收/發送的廣播包個數等。

-t  讓網卡執行自我檢測,有兩種模式:offline or online

 

用法舉例

1. 查看ethtool的詳細功能

ethtool --help

2. 查看基本信息

root@baohua-VirtualBox:/home/baohua/workspace/sourceCode# ethtool eth0
Settings for eth0:
    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
    Speed: 1000Mb/s
    Duplex: Full
    Port: Twisted Pair
    PHYAD: 0
    Transceiver: internal
    Auto-negotiation: on
    MDI-X: off (auto)
    Supports Wake-on: umbg
    Wake-on: d
    Current message level: 0x00000007 (7)
                   drv probe link
    Link detected: yes

 

3. 查看MAC和PHY的相關寄存器

root@baohua-VirtualBox:/home/baohua/workspace/sourceCode# ethtool -d eth0
MAC Registers
-------------
0x00000: CTRL (Device control register)  0x48000249
      Endian mode (buffers):             little
      Link reset:                        reset
      Set link up:                       1
      Invert Loss-Of-Signal:             no
      Receive flow control:              enabled
      Transmit flow control:             disabled
      VLAN mode:                         enabled
      Auto speed detect:                 disabled
      Speed select:                      1000Mb/s
      Force speed:                       no
      Force duplex:                      no
0x00008: STATUS (Device status register) 0x00000083
      Duplex:                            full
      Link up:                           link config
      TBI mode:                          disabled
      Link speed:                        1000Mb/s
      Bus type:                          PCI
      Bus speed:                         33MHz
      Bus width:                         32-bit
0x00100: RCTL (Receive control register) 0x00008002
      Receiver:                          enabled
      Store bad packets:                 disabled
      Unicast promiscuous:               disabled
      Multicast promiscuous:             disabled
      Long packet:                       disabled
      Descriptor minimum threshold size: 1/2
      Broadcast accept mode:             accept
      VLAN filter:                       disabled
      Canonical form indicator:          disabled
      Discard pause frames:              filtered
      Pass MAC control frames:           don't pass
      Receive buffer size:               2048
0x02808: RDLEN (Receive desc length)     0x00001000
0x02810: RDH   (Receive desc head)       0x000000AE
0x02818: RDT   (Receive desc tail)       0x000000AC
0x02820: RDTR  (Receive delay timer)     0x00000000
0x00400: TCTL (Transmit ctrl register)   0x0103F0FA
      Transmitter:                       enabled
      Pad short packets:                 enabled
      Software XOFF Transmission:        disabled
      Re-transmit on late collision:     enabled
0x03808: TDLEN (Transmit desc length)    0x00001000
0x03810: TDH   (Transmit desc head)      0x0000008D
0x03818: TDT   (Transmit desc tail)      0x0000008D
0x03820: TIDV  (Transmit delay timer)    0x00000008
PHY type:                                M88
M88 PHY STATUS REGISTER:                 0x0000BC08
      Jabber:                            no
      Polarity:                          normal
      Downshifted:                       no
      MDI/MDIX:                          MDI
      Cable Length Estimate:             0-50 meters
      Link State:                        Up
      Speed & Duplex Resolved:           Yes
      Page Received:                     Yes
      Duplex:                            Full
      Speed:                             1000 mbps
M88 PHY CONTROL REGISTER:                0x00000868
      Jabber function:                   enabled
      Auto-polarity:                     disabled
      SQE Test:                          disabled
      CLK125:                            enabled
      Auto-MDIX:                         auto
      Extended 10Base-T Distance:        disabled
      100Base-TX Interface:              MII
      Scrambler:                         enabled
      Force Link Good:                   disabled
      Assert CRS on Transmit:            enabled

4. 查看收發包統計

root@baohua-VirtualBox:/home/baohua/workspace/sourceCode# ethtool -S eth0
NIC statistics:
     rx_packets: 105902
     tx_packets: 14458
     rx_bytes: 7561476
     tx_bytes: 2602118
     rx_broadcast: 105692
     tx_broadcast: 3406
     rx_multicast: 4
     tx_multicast: 10756
     rx_errors: 0
     tx_errors: 0
     tx_dropped: 0
     multicast: 4
     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: 0
     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: 7561476
     rx_csum_offload_good: 0
     rx_csum_offload_errors: 0
     alloc_rx_buff_failed: 0
     tx_smbus: 0
     rx_smbus: 0
     dropped_smbus: 0

5. 設置PHY的動作方式,速度/半雙工/自動協商

ethtool -s ethX [speed 10|100|1000] [duplex half|full] [autoneg on|off] ethtool -s eth0 autoneg off speed 100 duplex full

 

將 ethtool 設置永久保存在網絡設備:

1. ethtool 設置可通過 /etc/sysconfig/network-scripts/ifcfg-ethx 文件保存,從而在設備下次啟動時激活選項

ethtool -s eth0 speed 100 duplex full autoneg off

此指令將eth1設備設置為全雙工自適應,速度為100Mbs。若要eth0啟動時設置這些參數, 修改文件/etc/sysconfig/network-scripts/ifcfg-eth1 ,添加如下一行

ETHTOOL_OPTS="speed 100 duplex full autoneg off"

2. 將ethtool設置寫入/etc/rc.d/rc.local之中,開機自動執行命令設置

ethtool -s eth0 speed 100 duplex full autoneg off


免責聲明!

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



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