Ubuntu/Debian Linux使用ethtool设置以太网设备

时间:2019-11-20 08:53:14  来源:igfitidea点击:

ethtool可用于查询和修改许多网络设备的设置

它可以用于:

  • 获取标识和诊断信息
  • 获取扩展的设备统计信息
  • 以太网设备的控制速度,双工,自动协商和流控制
  • 控制校验和卸载和其他硬件卸载功能
  • 控制DMA环大小和中断控制
  • 控制多队列设备的接收队列选择
  • 升级闪存中的固件等

那么,如何在Ubuntu或Debian Linux中安装和使用ethtool?

安装ethtool

在Debian或Ubuntu Linux下,执行以下apt-get命令,安装ethtool:

$ sudo apt-get update
$ sudo apt-get install ethtool

或者

# apt-get update
# apt-get install ethtool

ethtool语法

语法为:

ethtool deviceName
ethtool [options] deviceName
ethtool eth0

ethtool示例

查看设备ens32有关的信息

# 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
        Supported FEC modes: Not reported
        Advertised link modes:  10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Full 
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        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

查看驱动程序信息

# ethtool -i eth0

输出示例:

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

查看网卡的统计信息

# ethtool -S eth1
# ethtool --statistics eth0

输出示例:

NIC statistics:
     rx_packets: 108048475
     tx_packets: 125002612
     rx_bytes: 17446338197
     tx_bytes: 113281003056
     rx_broadcast: 83067
     tx_broadcast: 1329
     rx_multicast: 3
     tx_multicast: 9
     rx_errors: 0
     tx_errors: 0
     tx_dropped: 0
     multicast: 3
     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: 2367
     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: 17446338197
     rx_csum_offload_good: 107876452
     rx_csum_offload_errors: 2386
     rx_header_split: 0
     alloc_rx_buff_failed: 0
     tx_smbus: 0
     rx_smbus: 0
     dropped_smbus: 0
     rx_dma_failed: 0
     tx_dma_failed: 0

设置eth0网卡的协商速度

在Linux中设置网口的协商速度和通道:

# ethtool -s eth0 speed 100 duplex full
# ethtool --change eth0 speed 10 duplex half
# ethtool eth0
# ethtool eth0 | egrep -i 'speed|duplex'

输出示例:

Speed: 10Mb/s
Duplex: Half