[转帖]ethtool 命令介绍

ethtool,命令,介绍 · 浏览次数 : 0

小编点评

--实际上ethtool -S 的计数信息对于排查IP层的丢包、物理层的丢包有着比较重要的意义,一个思路是首先首先要判断丢包是发生在tcp/ip哪个层面,然后从ethtool -S的技术中查看丢包的原因。 -s --changeAllows changing some or all settings of the specified network device. All following options only apply if -s was specified.speed NSet speed in Mb/s. ethtool with just the device name as an argument will show you the supported device speeds.duplex half|fullSets full or half duplex mode.port tp|aui|bnc|miiSelects device port.mdix auto|on|offSelects MDI-X mode for port. May be used to override the automatic detection feature of most adapters. An argument of auto means automatic detection of MDI status, onforces MDI-X (crossover) mode, while off means MDI (straight through) mode. The driver should guarantee that this command takes effect immediately, and if necessarymay reset the link to cause the change to take effect.autoneg on|offSpecifies whether autonegotiation should be enabled. Autonegotiation is enabled by default, but in some network devices may have trouble with it, so you can disable itif really necessary--show-priv-flagsQueries the specified network device for its private flags. The names and meanings of private flags (if any) are defined by each network device driver.--set-priv-flagsSets the device's private flags as specified.flag on|off Sets the state of the named private flag.对网卡设置一些私有的标志,这些选项跟驱动强相关,意味着如果驱动版本低的话,则无法修改这些选项。通常是在一些特定的场景下才会需要修改这些标志,例如: ``` https://access.redhat.com/solutions/4054441--show-fecQueries the specified network device for its support of Forward Error Correction. ``` --实际上ethtool -S 的计数信息对于排查IP层的丢包、物理层的丢包有着比较重要的意义,一个思路是首先首先要判断丢包是发生在tcp/ip哪个层面,然后从ethtool -S的技术中查看丢包的原因。

正文

https://www.jianshu.com/p/f456e73a0437

 

name

ethtool - query or control network driver and hardware settings

ethtool

with a single argument specifying the device name prints current settings of the specified device.

ethtool eno1
Settings for eno1:
        Supported ports: [ ]
        Supported link modes:   1000baseT/Full 
        Supported pause frame use: Symmetric
        Supports auto-negotiation: Yes
        Supported FEC modes: Not reported
        Advertised link modes:  1000baseT/Full 
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        Speed: Unknown!
        Duplex: Unknown! (255)
        Port: Other
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: off
        Supports Wake-on: g
        Wake-on: g
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: no
# ethtool ens5f0
Settings for ens5f0:
        Supported ports: [ FIBRE ]
        Supported link modes:   1000baseKX/Full           ##支持的链路模式
                                10000baseKR/Full 
                                25000baseCR/Full 
                                25000baseKR/Full 
                                25000baseSR/Full 
        Supported pause frame use: Symmetric             ##暂停帧的支持,以太网流量控制
        Supports auto-negotiation: Yes                            ##链路自动协商
        Supported FEC modes: None BaseR        
        Advertised link modes:  1000baseKX/Full 
                                10000baseKR/Full 
                                25000baseCR/Full 
                                25000baseKR/Full 
                                25000baseSR/Full 
        Advertised pause frame use: Symmetric
        Advertised auto-negotiation: Yes                       ##建议自动协商  
        Advertised FEC modes: None                            ##建议的FEC mode
        Speed: 10000Mb/s                                              ##速率
        Duplex: Full                                                          ##双工模式
        Port: FIBRE                                                          ##port类型,,还会有
        PHYAD: 0                                                            ##网卡的物理标识,如果两个device的PHYAD相同,表示在一块物理网卡上
        Transceiver: internal                                         ##internal — Use internal transceiver、external — Use external transceiver.
        Auto-negotiation: on                    
        Supports Wake-on: d
        Wake-on: d                                                         ##Wake On LAN是否启用,d:禁用,g:启用
        Current message level: 0x00000004 (4)
                               link
        Link detected: yes                                            ##对于link也有一个比较实用的redhat kb:https://access.redhat.com/solutions/46885

--version

Shows the ethtool version number.

# ethtool --version
ethtool version 4.8

-a --show-pause

Queries the specified Ethernet device for pause parameter information.

[root@localhost ~]# ethtool -a eno1
Pause parameters for eno1:
Autonegotiate:  off
RX:             off
TX:             off

[root@localhost ~]# ethtool --show-pause eno1
Pause parameters for eno1:
Autonegotiate:  off
RX:             off
TX:             off

当以太网卡不能处理对端发送的数据帧时,将发送‘PAUSE’帧到对端,请求暂停发送。
当本端以太网卡可处理更多数据时,或者‘PAUSE’请求的暂停时间超时,对端可继续发送数据。可使用以下的ethtool命令查看网卡的流控设置。

-g --show-ring

Queries the specified network device for rx/tx ring parameter information.

[root@localhost ~]# ethtool -g eno3
Ring parameters for eno3:
Pre-set maximums:
RX:             4096
RX Mini:        0
RX Jumbo:       0
TX:             4096
Current hardware settings:
RX:             512
RX Mini:        0
RX Jumbo:       0
TX:             512

ringbuffer
The network interface ("NIC") shares a data structure with the operating system kernel software in order to pass network packets between them. Usually there are separate structures for transmit and receive directions, and commonly the data structure employed is a logical ring of buffers. This results in the term "ring buffer" being often used to indicate this interface structure. Usually all the buffers in a ring are of the same size.

The kernel device driver for the NIC, and the NIC firmware or hardware, cooperate in managing the data structure.

ifconfig输出下的drop error 通常跟ringbuffer相关。
ens5f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 98:03:9b:48:c7:dc txqueuelen 1000 (Ethernet)
RX packets 2815480 bytes 236634030 (225.6 MiB)
RX errors 0 dropped 441 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

-G --set-ring

Changes the rx/tx ring parameters of the specified network device.
rx N Changes the number of ring entries for the Rx ring.
rx-mini N Changes the number of ring entries for the Rx Mini ring.
rx-jumbo N Changes the number of ring entries for the Rx Jumbo ring.
tx N Changes the number of ring entries for the Tx ring.

设置ringbuffer的大小
[root@localhost ~]# ethtool -G ens5f0 rx 2048
[root@localhost ~]# ethtool -g ens5f0        
Ring parameters for ens5f0:
Pre-set maximums:
RX:             8192
RX Mini:        0
RX Jumbo:       0
TX:             8192
Current hardware settings:
RX:             2048
RX Mini:        0
RX Jumbo:       0
TX:             1024

ethtool -G 命令设置ringbuffer为临时生效
永久生效方法,可参考如下linux kb:https://access.redhat.com/solutions/2127401

-i --driver

Queries the specified network device for associated driver information.

查询网卡的driver以及微码版本
[root@localhost ~]# ethtool -i eno1
driver: i40e
version: 2.8.20-k
firmware-version: 5.10 0x80002c06 1.2890.0
expansion-rom-version: 
bus-info: 0000:5b:00.2
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: yes

--可以查看到网卡的driver信息
--可以查看到网卡的微码版本信息
--可以查看到网卡的总线信息,这个也是比较有用的,bus number结合lspci命令可以如下这样使用:
[root@localhost ~]# lspci -s 5b:00.2 -v
5b:00.2 Ethernet controller: Intel Corporation Ethernet Connection X722 for 1GbE (rev 09)
Subsystem: Lenovo Ethernet Connection X722 for 1GbE
Flags: bus master, fast devsel, latency 0, IRQ 32, NUMA node 0
Memory at 23ffb000000 (64-bit, prefetchable) [size=16M]
Memory at 23fff008000 (64-bit, prefetchable) [size=32K]
Expansion ROM at e3b80000 [disabled] [size=512K]
Capabilities: [40] Power Management version 3
Capabilities: [50] MSI: Enable- Count=1/1 Maskable+ 64bit+
Capabilities: [70] MSI-X: Enable+ Count=129 Masked-
Capabilities: [a0] Express Endpoint, MSI 00
Capabilities: [e0] Vital Product Data
Capabilities: [100] Advanced Error Reporting
Capabilities: [150] Alternative Routing-ID Interpretation (ARI)
Capabilities: [160] Single Root I/O Virtualization (SR-IOV)
Capabilities: [1a0] Transaction Processing Hints
Capabilities: [1b0] Access Control Services
Kernel driver in use: i40e
Kernel modules: i40e

-p --identify

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

小写的P,点亮网卡,用来定位网卡物理位置,命令执行后,ctrl+c 取消执行:
[root@localhost ~]# ethtool -p eno1
^C

-P --show-permaddr

Queries the specified network device for permanent hardware address.
大写的p,查看网卡的mac地址、ip ad和ifconfig等命令均可实现这种功能。

[root@localhost ~]# ethtool -P eno1         
Permanent address: 08:94:ef:9c:13:ea
[root@localhost ~]# ip ad |grep -i eno1 -A 1
4: eno1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether 08:94:ef:9c:13:ea brd ff:ff:ff:ff:ff:ff
[root@localhost ~]# ifconfig eno1
eno1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 08:94:ef:9c:13:ea  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

-r --negotiate

Restarts auto-negotiation on the specified Ethernet device, if auto-negotiation is enabled.

[root@localhost ~]# ethtool -r eno3
[root@localhost ~]# 

看下实际效果,系统会让网卡再重新协商一次链路,可以看到如下日志输出:
localhost kernel: i40e 0000:5b:00.0 eno3: NIC Link is Down
localhost kernel: i40e 0000:5b:00.0 eno3: NIC Link is Up, 10 Gbps Full Duplex, Flow Control: None
localhost NetworkManager[1886]: <info> [1670530932.4519] device (eno3): carrier: link connected

-S --statistics

Queries the specified network device for NIC- and driver-specific statistics.
这个命令输出信息会非常多,也是非常有用的:

[root@localhost ~]# ethtool -S eno3|more
NIC statistics:
     rx_packets: 2330214   # Trasmitted packets
     tx_packets: 63464       #Received packets
     rx_bytes: 230354804
     tx_bytes: 14182808
     rx_errors: 0                   #Trasmission errors
     tx_errors: 0                   #Received errors
     rx_dropped: 0
     tx_dropped: 0
     collisions: 0
     rx_length_errors: 0
     rx_crc_errors: 0
     rx_unicast: 34715
     tx_unicast: 48219
     rx_multicast: 11552
     tx_multicast: 15241
     rx_broadcast: 2283947
     tx_broadcast: 4
     rx_unknown_protocol: 0
     tx_linearize: 0

--对于统计信息,一方面理解各个信息代表的含义是重要的,这方面mellanox有一个文档相对比较详细:https://support.mellanox.com/s/article/understanding-mlx5-ethtool-counters
--零一点对于排障比较重要的是,在排障过程中通常需要对计数器进行重置,redhat对此有一篇文档:
https://access.redhat.com/solutions/125793
--实际上ethtool -S 的计数信息对于排查IP层的丢包、物理层的丢包有着比较重要的意义,有一个思路是首先首先要判断丢包是发生在tcp/ip哪个层面,然后从ethtool -S的技术中查看丢包的原因。
--实际上ethtool -S 的计数信息对于排查IP层的丢包、物理层的丢包有着比较重要的意义,有一个思路是首先首先要判断丢包是发生在tcp/ip哪个层面,然后从ethtool -S的技术中查看丢包的原因。

-s --change

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

speed N
Set speed in Mb/s. ethtool with just the device name as an argument will show you the supported device speeds.

duplex half|full
Sets full or half duplex mode.

port tp|aui|bnc|mii
Selects device port.

mdix auto|on|off
Selects MDI-X mode for port. May be used to override the automatic detection feature of most adapters. An argument of auto means automatic detection of MDI status, on
forces MDI-X (crossover) mode, while off means MDI (straight through) mode. The driver should guarantee that this command takes effect immediately, and if necessary
may reset the link to cause the change to take effect.

autoneg on|off
Specifies whether autonegotiation should be enabled. Autonegotiation is enabled by default, but in some network devices may have trouble with it, so you can disable it
if really necessary

--show-priv-flags

Queries the specified network device for its private flags. The names and meanings of private flags (if any) are defined by each network device driver.
--set-priv-flags
Sets the device's private flags as specified.
flag on|off Sets the state of the named private flag.
对网卡设置一些私有的标志,这些选项跟驱动强相关,意味着如果驱动版本低的话,则无法修改这些选项。
通常是在一些特定的场景下才会需要修改这些标志,如下一个案例:
https://access.redhat.com/solutions/4054441

--show-fec

Queries the specified network device for its support of Forward Error Correction.
一种前向错误纠正技术,旨在增强数据传输的可靠性。
Forward error correction (FEC) is an error correction technique to detect and correct a limited number of errors in transmitted data without the need for retransmission.

In this method, the sender sends a redundant error-correcting code along with the data frame. The receiver performs necessary checks based upon the additional redundant bits. If it finds that the data is free from errors, it executes error-correcting code that generates the actual frame. It then removes the redundant bits before passing the message to the upper layers.

谁提供的ethtool包?

通过如下命令进行查询
[root@localhost ~]# which ethtool
/usr/sbin/ethtool
[root@localhost ~]# rpm -qf /usr/sbin/ethtool
ethtool-4.8-10.el7.x86_64

与[转帖]ethtool 命令介绍相似的内容:

[转帖]ethtool 命令介绍

https://www.jianshu.com/p/f456e73a0437 name ethtool - query or control network driver and hardware settings ethtool with a single argument specifying

[转帖]Linux ethtool 命令详解

命令描述: ethtool 是用于查询及设置网卡参数的命令。 使用概要: ethtool ethx //查询ethx网口基本设置,其中 x 是对应网卡的编号,如eth0、eth1等等 ethtool –h //显示ethtool的命令帮助(help) ethtool –i ethX //查询ethX

【转帖】一文解析ethtool 命令的使用

命令简介 ethtool命令用于查询和控制网络设备驱动程序和硬件设置,尤其是有线以太网设备,devname网卡的名称。网卡就像是交换机的一个端口,正常使用我们只是配置网卡IP地址等信息,网卡的速率、双工模式等我们并不关心。通过ethtool命令我们可以像配置交换机网卡一样配置这些参数,这就是这个命令

[转帖]linux中关于带宽 MTU的一些命令

linux中关于带宽 MTU的一些命令 https://blog.51cto.com/xiaoliuer/1882208 查看协商的带宽大小 sudo ethtools eth0 Linux更改网卡MTU方法: 1. 打开终端,查看当前网卡设置:ifconfig 2. 对需要改MTU的网卡进行设置(

【转帖】【ethtool】ethtool 网卡诊断、调整工具、网卡性能优化| 解决丢包严重

目录 即看即用 详细信息 软件简介 安装 ethtool的使用 输出详解 其他指令 将 ethtool 设置永久保存 如何使用 ethtool 优化 Linux 虚拟机网卡性能 ethtool 解决网卡丢包严重和网卡原理 即看即用 查看: ethtool ethx 查看eth0网卡的基本设置 内容包

[转帖]ethool工具之TSO、UFO、GSO、LRO、GRO和RSS介绍

ethtool -k < 网络接口>, ethtool --show-offload < 网络接口>, 或者可以看到很多网络接口的offload特性,例如: $ sudo ethtool -k eth0Offload parameters for eth0:rx-checksumming: ontx

【转帖】ethool工具之TSO、UFO、GSO、LRO、GRO和RSS介绍

ethtool -k < 网络接口>, ethtool --show-offload < 网络接口>, 或者可以看到很多网络接口的offload特性,例如: $ sudo ethtool -k eth0Offload parameters for eth0:rx-checksumming: ontx

[转帖]网络监控工具

nethogs: 按进程查看流量占用 iptraf: 按连接/端口查看流量 ifstat: 按设备查看流量 ethtool: 诊断工具 tcpdump: 抓包工具 ss: 连接查看工具 其他: dstat, slurm, nload, bmon

[转帖]x86服务器中网络性能分析与调优(高并发、大流量网卡调优)

最近在百度云做一些RTC大客户的项目,晚上边缘计算的一台宿主机由于CPU单核耗被打满,最后查到原因是网卡调优没有生效,今天查了一下网卡调优的资料,欢迎大家共同探讨。 一.网卡调优方法 1、Broadcom的网卡建议关闭GRO功能 ethtool -K eth0 gro off ethtool -K

【转帖】x86服务器中网络性能分析与调优(高并发、大流量网卡调优)

最近在百度云做一些RTC大客户的项目,晚上边缘计算的一台宿主机由于CPU单核耗被打满,最后查到原因是网卡调优没有生效,今天查了一下网卡调优的资料,欢迎大家共同探讨。 一.网卡调优方法 1、Broadcom的网卡建议关闭GRO功能 ethtool -K eth0 gro off ethtool -K