ethtool

最後更新: 2018-08-28

介紹

ethtool 是一個顯示網卡資料及修改其設定值的工具來

他的功能與 mii-tool 差不多, 以下是它的幾個主要用法

 


顯示一般資料

 

# 它會顯示出 eth0 的重要資訊, 如 Speed, Duplex, Link detected, Auto-negotiation

ethtool eth0

Settings for eth0:
        .......................................
        Speed: 100Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: pumbg           <-- pumbg=magic packet
        Wake-on: d                        <-- d=Disable 
        Current message level: 0x00000033 (51)
                               drv probe ifdown ifup
        Link detected: yes

 


設定

 

# 將網卡設定成 100MB/s full duplex 的狀態, 並關閉 Auto-negotiation

ethtool -s eth0 autoneg on

ethtool -s eth0 speed 100 duplex full autoneg off

#  -s     option  allows  changing  some or all settings of the specified ethernet device.

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

# -A     change the pause parameters of the specified ethernet device.

 

        ethtool -A DEVNAME \
                [ autoneg on|off ] \
                [ rx on|off ] \
                [ tx on|off ]

        ethtool -s DEVNAME \
                [ speed 10|100|1000 ] \
                [ duplex half|full ]    \
                [ port tp|aui|bnc|mii|fibre ] \
                [ autoneg on|off ] \
                [ phyad %d ] \
                [ xcvr internal|external ] \
                [ wol p|u|m|b|a|g|s|d... ] \
                [ sopass %x:%x:%x:%x:%x:%x ] \
                [ msglvl %d ]

 


檢看統計資料

 

# 查看網卡總共收過及發過幾多個 package

# 此 cmd 的重點係佢可以得知以往有幾多個 package 有錯

ethtool -S eth0

NIC statistics:
     tx_packets: 127491258
     rx_packets: 97445159
     tx_errors: 10
     rx_errors: 577324
     rx_missed: 0
     align_errors: 36143
     tx_single_collisions: 0
     tx_multi_collisions: 0
     unicast: 96824556
     broadcast: 559290
     multicast: 620603
     tx_aborted: 0
     tx_underrun: 0

 

P.S.

只有 reload NIC 的 module 才可以 reset 統計 counter

 


Driver 資料

 

# 顯示網卡的 driver, 及使用那條 bus

ethtool -i eth0

driver: r8169
version: 2.3LK-NAPI
firmware-version: N/A
bus-info: 0000:02:00.0

 


re-negotiation

 

# 重新來多次 Auto-negotiation, 令網卡它們 "洽商" 適當的速度

ethtool -r
 


TCP Offload

 

offload 是指網卡代替了 cpu 處理部份網絡流量, 這可以說是網卡的"硬解"來

# 顯示現時網卡的 offload 設定

ethtool -k

Offload parameters for eth0:
rx-checksumming: on
tx-checksumming: on
scatter-gather: on
tcp-segmentation-offload: on
udp-fragmentation-offload: off
generic-segmentation-offload: off
generic-receive-offload: on
large-receive-offload: off
ntuple-filters: off
receive-hashing: off

 

# 開啟網卡的全部 offload 能力

ethtool -K eth0 rx on tx on sg on tso on ufo on gso on
 

當見到以下 warning, 那表示網卡不支援此 offload 能力

Cannot get device udp large send offload settings: Operation not supported

以上表示沒有 udp fragmentation offload 能力

網卡 default 沒有開啟這些 function

 

Offload 能力一覽:

  • rx:  RX checksumming
  • tx:  TX checksumming
  • sg:  scatter-gather
  • tso: TCP segmentation offload
  • ufo: UDP fragmentation offload
  • gro: generic receive offload
  • lro: large receive offload
  • rxhash: receive hashing offload

 


Wake On Lan

 

SecureON password feature

設置 PW:

ethtool -s eth0 wol g sopass 11:22:33:44:55:66     // PW 的格式 11:22:33:44:55:66

 


開機設定

 

在 /etc/rc.local 裡加入

# /sbin/ethtool -s eth0 wol g <-- 行一次即可
/sbin/ethtool -s eth0 speed 100 duplex full autoneg off
/sbin/ethtool -K eth0 tx on sg on tso on gro on

 


1G lan - autonegotiation (802.3u)

 

a) To negotiate that the PHY is capable of supporting 1000BASE-T half duplex or full duplex transmission.

b) To determine the MASTER-SLAVE relationship between the PHYs at each end of the link.

1000BASE-T MASTER PHY is clocked from a local source. The SLAVE PHY uses loop timing where the clock is recovered from the received data stream.

P.S.

在 1G Network 裡一定要用 autonegotiation 的 !!

 


DOC