Ubuntu 22.04 ethtool 安装与命令参数详解

在 Ubuntu 22.04 上安装 ethtool 5.16 并逐参数实测网卡参数查看/修改命令的输入与输出,涵盖链路信息/驱动/offload 开关/暂停帧/通道/统计/ring/定位/自协商/中断合并/JSON 与完整 --help。

Linux 网络诊断与调试ethtoolLinux命令行网络诊断2026/10/06

Ubuntu 22.04 ethtool 安装与命令参数详解

目标:在 Ubuntu 22.04 上安装 ethtool 5.16,并逐参数实测网卡参数查看/修改命令的输入与输出,涵盖基本链路信息、驱动/固件信息、协议 offload 查看与开关、暂停帧、通道/队列、收发统计、ring buffer、物理口定位、重启自协商、中断合并、JSON 输出及完整 --help。本文命令与输出均为 Ubuntu 22.04(ethtool 5.16)实测回显。

环境信息

  • 操作系统:Ubuntu 22.04 LTS
  • ethtool 版本:5.16
  • 被测网卡:eth0(veth 虚拟网卡,驱动 veth)
  • 网卡 IP:172.22.0.2,默认网关 172.22.0.1
  • 链路状态:Speed 10000Mb/s、Duplex Full、Link detected yes,auto-negotiation off
  • 驱动信息:driver veth、version 1.0、firmware-version 为空、bus-info 为空;supports-statistics yes、supports-test/eeprom-access/register-dump/priv-flags 均为 no
  • 说明:eth0 为 veth 虚拟对端网卡,多数"硬件级"子命令(自协商、ring、pause、coalesce、识别 LED)不被 veth 支持属正常现象,已如实记录。

工具概述

ethtool 是 Linux 下查看和修改网卡(含物理网卡与虚拟网卡)底层参数的标准工具,覆盖链路速率/双工模式、驱动与固件信息、协议 offload 特性开关、收发统计计数、如何队列(通道)、ring buffer 大小、pause 暂停帧、中断合并(coalesce)等多个层面,是排查网卡驱动、链路状态、网卡吞吐与丢包根因的核心命令。本文针对 Ubuntu 22.04 下的 ethtool 5.16 实测。

安装

在线安装(apt)

sudo apt update
sudo apt install -y ethtool

💡 Ubuntu 22.04 官方仓库自带 ethtool 包,安装即为 5.16 版本,无需额外配置 PPA。

安装后验证:

ethtool --version
ethtool version 5.16

离线安装(.deb 包)

# 在可联网机器下载 ethtool 及其依赖
cd /opt/netdiag-offline
apt-get download ethtool

# 目标机离线安装(如遇依赖缺失,可用 gdebi 自动补齐)
sudo dpkg -i ethtool_*.deb

命令实测

查看网卡设置(链路信息)

用途:直接以网卡名为参数,显示该网卡的速度、双工、自协商、端口类型、链路状态等基本配置。veth 虚拟网卡下 Supported ports 为空、链路模式为 Not reported,属正常现象。

ethtool eth0
Settings for eth0:
        Supported ports: [  ]
        Supported link modes:   Not reported
        Supported pause frame use: No
        Supports auto-negotiation: No
        Supported FEC modes: Not reported
        Advertised link modes:  Not reported
        Advertised pause frame use: No
        Advertised auto-negotiation: No
        Advertised FEC modes: Not reported
        Speed: 10000Mb/s
        Duplex: Full
        Auto-negotiation: off
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: internal
        MDI-X: Unknown
        Link detected: yes

查看驱动信息

用途:-i(--driver)显示网卡驱动名、驱动版本、固件版本、总线信息及支持的 ethtool 能力。本环境为 veth 驱动,固件版本、bus-info 为空属正常。

ethtool -i eth0
driver: veth
version: 1.0
firmware-version:
expansion-rom-version:
bus-info:
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no

查看协议 offload/特性状态

用途:-k(--show-features)列出网卡各协议 offload 特性当前开关状态。注意特性名为全称(如 tcp-segmentation-offload),并不包含 "tso" 字样。

ethtool -k eth0 | head -20
Features for eth0:
rx-checksumming: on
tx-checksumming: on
        tx-checksum-ipv4: off [fixed]
        tx-checksum-ip-generic: on
        tx-checksum-ipv6: off [fixed]
        tx-checksum-fcoe-crc: off [fixed]
        tx-checksum-sctp: on
scatter-gather: on
        tx-scatter-gather: on
        tx-scatter-gather-fraglist: on
tcp-segmentation-offload: on
        tx-tcp-segmentation: on
        tx-tcp-ecn-segmentation: on
        tx-tcp-mangleid-segmentation: on
        tx-tcp6-segmentation: on
generic-segmentation-offload: on
generic-receive-offload: off
large-receive-offload: off [fixed]
rx-vlan-offload: on

修改 offload 开关并回滚(演示命令,实测后已回滚)

用途:-K(--features)动态修改协议 offload 开关。本环境 veth 实测 tso 开关可以成功修改(成功时无输出、退出码 0),修改后需回滚恢复。

ethtool -K eth0 tso off
ethtool -k eth0 | grep tcp-segmentation-offload
ethtool -K eth0 tso on

veth 网卡实测 tso 开关修改完整周期:

# 修改前
tcp-segmentation-offload: on
# ethtool -K eth0 tso off(无输出,退出码 0)
tcp-segmentation-offload: off
# ethtool -K eth0 tso on 回滚(无输出,退出码 0)
tcp-segmentation-offload: on

实测踩坑记录:ethtool -k eth0 | grep tso 匹配不到任何行(grep 退出码 1)。因为 ethtool -k 输出中的特性名是全称 tcp-segmentation-offload,不含 "tso" 字样;验证 TSO 状态应使用 grep tcp-segmentation-offload。

查看暂停帧(pause)参数

用途:-a(--show-pause)查看网卡暂停帧(flow control)收发配置。veth 不支持 pause,netlink 报错、退出码 1。

ethtool -a eth0
netlink error: Operation not supported

只读查看 pause(-A 不带参数)

用途:-A(--pause)本应设置 pause,不带参数时退化为只读查询。veth 不支持,netlink 报错、退出码 76。

ethtool -A eth0
netlink error: Operation not supported

查看通道(队列)信息

用途:-l(--show-channels)查看网卡 RX/TX 队列(通道)数量。13 版本先打印一行 netlink 报错,随后自动回退 ioctl 成功输出,整体退出码 0。

ethtool -l eth0
netlink error: Operation not supported
Channel parameters for eth0:
Pre-set maximums:
RX:             128
TX:             128
Other:          n/a
Combined:       n/a
Current hardware settings:
RX:             1
TX:             1
Other:          n/a
Combined:       n/a

查看网卡统计计数

用途:-S(--statistics)逐行输出网卡收发统计计数。veth 下可见 peer_ifindex(指向对端 veth)、XDP 各队列计数、页池分配(rx_pp_*)等字段。

ethtool -S eth0 | head -15
NIC statistics:
     peer_ifindex: 979
     rx_queue_0_xdp_packets: 0
     rx_queue_0_xdp_bytes: 0
     rx_queue_0_drops: 0
     rx_queue_0_xdp_redirect: 0
     rx_queue_0_xdp_drops: 0
     rx_queue_0_xdp_tx: 0
     rx_queue_0_xdp_tx_errors: 0
     tx_queue_0_xdp_xmit: 0
     tx_queue_0_xdp_xmit_errors: 0
     rx_pp_alloc_fast: 0
     rx_pp_alloc_slow: 0
     rx_pp_alloc_slow_ho: 0
     rx_pp_alloc_empty: 0

查看 ring buffer 参数

用途:-g(--show-ring)查看网卡 RX/TX ring buffer 的当前值与最大值。veth 不支持 ring 查询,netlink 报错、退出码 1。

ethtool -g eth0
netlink error: Operation not supported

闪烁识别网卡(物理口定位)

用途:-p(--identify)让物理网卡指示灯闪烁以定位物理口。虚拟网卡无 LED 可闪,报错、退出码 255。

ethtool -p eth0
Cannot identify NIC: Operation not supported

重启自协商

用途:-r(--negotiate)重启网卡 N-WAY 自协商。veth 无自协商能力,报错、退出码 255。

ethtool -r eth0
Cannot restart autonegotiation: Operation not supported

查看中断合并(coalesce)参数

用途:-c(--show-coalesce)查看网卡中断合并参数(adaptive、rx/tx-usecs、rx/tx-frames 等)。5.16 命令本身支持,但 veth 驱动不提供 coalesce 信息,netlink 报错、退出码 1。

ethtool -c eth0
netlink error: Operation not supported

JSON 输出

用途:--json 期望输出 JSON 格式。实测 ethtool 5.16 的 --json 在 help 的 FLAGS 中有列出,但实际执行报参数错误、退出码 1、无 stdout 输出。JSON 输出需 ethtool 6.x 才真正可用。

ethtool --json -k eth0 | head
ethtool: bad command line argument(s)
For more information run ethtool -h

换参数顺序亦失败:ethtool -k eth0 --json 输出 ethtool: unexpected parameter '--json';ethtool --json --show-features eth0、ethtool --json -i eth0 同样报 bad command line argument(s)。结论:ethtool 5.16 无法实际使用 --json。

版本差异说明

本文实测版本为 Ubuntu 22.04 自带的 ethtool 5.16。与 CentOS 8 自带的 ethtool 5.8(同为 veth 环境)相比,本次实测的差异点如下:

#差异点Ubuntu 22.04(ethtool 5.16)CentOS 8(ethtool 5.8)
1ethtool --versionethtool version 5.16ethtool version 5.8
2查看 pause -anetlink 报错、退出码 1无任何输出、仅退出码 1(静默失败,不打印 netlink 错误行)
3只读 pause -Anetlink 报错、退出码 76(错误行打印一次)netlink 报错、退出码 76(错误行打印两次)
4查看通道 -l先打印一行 netlink 报错,随后自动回退 ioctl 成功输出,退出码 0直接成功,无 netlink 报错行,退出码 0
5--json参数错误 bad command line argument(s),退出码 1,无 stdout退出码 0,--json 被静默忽略,照常输出普通文本
6-c coalesce命令存在,veth 上报 netlink error: Operation not supported命令同样存在,veth 上输出与 Ubuntu 相同
7-k 特性项5.16 输出含 tx-tcp6-segmentation 等更多子项5.8 veth 特性集与 5.16 一致(veth 特性集相同)
8/opt/netdiag-offline/ethtool -S peer_ifindex979980(对端 veth 索引不同)

此外,-i 驱动信息、基础链路参数 ethtool eth0、-k 特性集、-K tso 开关行为、-g/-p/-r/-c 等命令在两版本下的回显基本一致。新发行版(多已升级 ethtool 6.x)会进一步扩展 -S 的 XDP/RX 队列字段并补充 TLS、HW 隧道等更多 -k 功能项;对真实物理网卡(e1000e/ixgbe 等)字段最全。

帮助输出

完整 ethtool --help(Ubuntu 22.04 / ethtool 5.16 实测输出):

ethtool version 5.16
Usage:
        ethtool [ FLAGS ]  DEVNAME      Display standard information about device
        ethtool [ FLAGS ] -s|--change DEVNAME   Change generic options
                [ speed %d ]
                [ lanes %d ]
                [ duplex half|full ]
                [ port tp|aui|bnc|mii|fibre|da ]
                [ mdix auto|on|off ]
                [ autoneg on|off ]
                [ advertise %x[/%x] | mode on|off ... [--] ]
                [ phyad %d ]
                [ xcvr internal|external ]
                [ wol %d[/%d] | p|u|m|b|a|g|s|f|d... ]
                [ sopass %x:%x:%x:%x:%x:%x ]
                [ msglvl %d[/%d] | type on|off ... [--] ]
                [ master-slave preferred-master|preferred-slave|forced-master|forced-slave ]
        ethtool [ FLAGS ] -a|--show-pause DEVNAME       Show pause options
        ethtool [ FLAGS ] -A|--pause DEVNAME    Set pause options
                [ autoneg on|off ]
                [ rx on|off ]
                [ tx on|off ]
        ethtool [ FLAGS ] -c|--show-coalesce DEVNAME    Show coalesce options
        ethtool [ FLAGS ] -C|--coalesce DEVNAME Set coalesce options
                [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]
                [cqe-mode-rx on|off]
                [cqe-mode-tx on|off]
        ethtool [ FLAGS ] -g|--show-ring DEVNAME        Query RX/TX ring parameters
        ethtool [ FLAGS ] -G|--set-ring DEVNAME Set RX/TX ring parameters
                [ rx N ]
                [ rx-mini N ]
                [ rx-jumbo N ]
                [ tx N ]
        ethtool [ FLAGS ] -k|--show-features|--show-offload DEVNAME     Get state of protocol offload and other features
        ethtool [ FLAGS ] -K|--features|--offload DEVNAME       Set protocol offload and other features
                FEATURE on|off ...
        ethtool [ FLAGS ] -i|--driver DEVNAME   Show driver information
        ethtool [ FLAGS ] -d|--register-dump DEVNAME    Do a register dump
                [ raw on|off ]
                [ file FILENAME ]
        ethtool [ FLAGS ] -e|--eeprom-dump DEVNAME      Do a EEPROM dump
                [ raw on|off ]
                [ offset N ]
                [ length N ]
        ethtool [ FLAGS ] -E|--change-eeprom DEVNAME    Change bytes in device EEPROM
                [ magic N ]
                [ offset N ]
                [ length N ]
                [ value N ]
        ethtool [ FLAGS ] -r|--negotiate DEVNAME        Restart N-WAY negotiation
        ethtool [ FLAGS ] -p|--identify DEVNAME Show visible port identification (e.g. blinking)
               [ TIME-IN-SECONDS ]
        ethtool [ FLAGS ] -t|--test DEVNAME     Execute adapter self test
               [ online | offline | external_lb ]
        ethtool [ FLAGS ] -S|--statistics DEVNAME       Show adapter statistics
               [ --all-groups | --groups [eth-phy] [eth-mac] [eth-ctrl] [rmon] ]
        ethtool [ FLAGS ] --phy-statistics DEVNAME      Show phy statistics
        ethtool [ FLAGS ] -n|-u|--show-nfc|--show-ntuple DEVNAME        Show Rx network flow classification options or rules
                [ rx-flow-hash tcp4|udp4|ah4|esp4|sctp4|tcp6|udp6|ah6|esp6|sctp6 [context %d] |
                  rule %d ]
        ethtool [ FLAGS ] -N|-U|--config-nfc|--config-ntuple DEVNAME    Configure Rx network flow classification options or rules
                rx-flow-hash tcp4|udp4|ah4|esp4|sctp4|tcp6|udp6|ah6|esp6|sctp6 m|v|t|s|d|f|n|r... [context %d] |
                flow-type ether|ip4|tcp4|udp4|sctp4|ah4|esp4|ip6|tcp6|udp6|ah6|esp6|sctp6
                        [ src %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]
                        [ dst %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]
                        [ proto %d [m %x] ]
                        [ src-ip IP-ADDRESS [m IP-ADDRESS] ]
                        [ dst-ip IP-ADDRESS [m IP-ADDRESS] ]
                        [ tos %d [m %x] ]
                        [ tclass %d [m %x] ]
                        [ l4proto %d [m %x] ]
                        [ src-port %d [m %x] ]
                        [ dst-port %d [m %x] ]
                        [ spi %d [m %x] ]
                        [ vlan-etype %x [m %x] ]
                        [ vlan %x [m %x] ]
                        [ user-def %x [m %x] ]
                        [ dst-mac %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]
                        [ action %d ] | [ vf %d queue %d ]
                        [ context %d ]
                        [ loc %d]] |
                delete %d
        ethtool [ FLAGS ] -T|--show-time-stamping DEVNAME       Show time stamping capabilities
        ethtool [ FLAGS ] -x|--show-rxfh-indir|--show-rxfh DEVNAME      Show Rx flow hash indirection table and/or RSS hash key
                [ context %d ]
        ethtool [ FLAGS ] -X|--set-rxfh-indir|--rxfh DEVNAME    Set Rx flow hash indirection table and/or RSS hash key
                [ context %d|new ]
                [ equal N | weight W0 W1 ... | default ]
                [ hkey %x:%x:%x:%x:%x:.... ]
                [ hfunc FUNC ]
                [ delete ]
        ethtool [ FLAGS ] -f|--flash DEVNAME    Flash firmware image from the specified file to a region on the device
               FILENAME [ REGION-NUMBER-TO-FLASH ]
        ethtool [ FLAGS ] -P|--show-permaddr DEVNAME    Show permanent hardware address
        ethtool [ FLAGS ] -w|--get-dump DEVNAME Get dump flag, data
                [ data FILENAME ]
        ethtool [ FLAGS ] -W|--set-dump DEVNAME Set dump flag of the device
                N
        ethtool [ FLAGS ] -l|--show-channels DEVNAME    Query Channels
        ethtool [ FLAGS ] -L|--set-channels DEVNAME     Set Channels
               [ rx N ]
               [ tx N ]
               [ other N ]
               [ combined N ]
        ethtool [ FLAGS ] --show-priv-flags DEVNAME     Query private flags
        ethtool [ FLAGS ] --set-priv-flags DEVNAME      Set private flags
                FLAG on|off ...
        ethtool [ FLAGS ] -m|--dump-module-eeprom|--module-info DEVNAME Query/Decode Module EEPROM information and optical diagnostics if available
                [ raw on|off ]
                [ hex on|off ]
                [ offset N ]
                [ length N ]
                [ page N ]
                [ bank N ]
                [ i2c N ]
        ethtool [ FLAGS ] --show-eee DEVNAME    Show EEE settings
        ethtool [ FLAGS ] --set-eee DEVNAME     Set EEE settings
                [ eee on|off ]
                [ advertise %x ]
                [ tx-lpi on|off ]
                [ tx-timer %d ]
        ethtool [ FLAGS ] --set-phy-tunable DEVNAME     Set PHY tunable
                [ downshift on|off [count N] ]
                [ fast-link-down on|off [msecs N] ]
                [ energy-detect-power-down on|off [msecs N] ]
        ethtool [ FLAGS ] --get-phy-tunable DEVNAME     Get PHY tunable
                [ downshift ]
                [ fast-link-down ]
                [ energy-detect-power-down ]
        ethtool [ FLAGS ] --get-tunable DEVNAME Get tunable
                [ rx-copybreak ]
                [ tx-copybreak ]
                [ pfc-precention-tout ]
        ethtool [ FLAGS ] --set-tunable DEVNAME Set tunable
                [ rx-copybreak N]
                [ tx-copybreak N]
                [ pfc-precention-tout N]
        ethtool [ FLAGS ] --reset DEVNAME       Reset components
                [ flags %x ]
                [ mgmt ]
                [ mgmt-shared ]
                [ irq ]
                [ irq-shared ]
                [ dma ]
                [ dma-shared ]
                [ filter ]
                [ filter-shared ]
                [ offload ]
                [ offload-shared ]
                [ mac ]
                [ mac-shared ]
                [ phy ]
                [ phy-shared ]
                [ ram ]
                [ ram-shared ]
                [ ap ]
                [ ap-shared ]
                [ dedicated ]
                [ all ]
        ethtool [ FLAGS ] --show-fec DEVNAME    Show FEC settings
        ethtool [ FLAGS ] --set-fec DEVNAME     Set FEC settings
                [ encoding auto|off|rs|baser|llrs [...]]
        ethtool [ FLAGS ] -Q|--per-queue DEVNAME        Apply per-queue command.
The supported sub commands include --show-coalesce, --coalesce             [queue_mask %x] SUB_COMMAND
        ethtool [ FLAGS ] --cable-test DEVNAME  Perform a cable test
        ethtool [ FLAGS ] --cable-test-tdr DEVNAME      Print cable test time domain reflectrometery data
                [ first N ]
                [ last N ]
                [ step N ]
                [ pair N ]
        ethtool [ FLAGS ] --show-tunnels DEVNAME        Show NIC tunnel offload information
        ethtool [ FLAGS ] -h|--help             Show this help
        ethtool [ FLAGS ] --version             Show version number
        ethtool --monitor               Show kernel notifications
                ( [ --all ]
                  | -s | --change
                  | -k | --show-features | --show-offload | -K | --features | --offload
                  | --show-priv-flags | --set-priv-flags
                  | -g | --show-ring | -G | --set-ring
                  | -l | --show-channels | -L | --set-channels
                  | -c | --show-coalesce | -C | --coalesce
                  | -a | --show-pause | -A | --pause
                  | --show-eee | --set-eee
                  | --cable-test
                  | --cable-test-tdr )
                [ DEVNAME | * ]

FLAGS:
        --debug MASK    turn on debugging messages
        --json          enable JSON output format (not supported by all commands)
        -I|--include-statistics         request device statistics related to the command (not supported by all commands)

常见问题

不是。pause、ring、coalesce 属于网卡硬件级能力,veth 等虚拟网卡不提供实现,ethtool 会通过 netlink 报 Operation not supported(退出码 1)。在真实物理网卡(e1000e/ixgbe 等驱动)上才会返回完整参数。

Q2:ethtool -p 报 Cannot identify NIC: Operation not supported 怎么办?

-p(identify)依赖网卡 LED 指示灯。虚拟网卡无 LED 可闪,故报错(退出码 255);只有在带驱动 LED 的物理网卡上才会闪灯定位物理口。本环境属正常。

Q3:为什么 ethtool -k | grep tso 匹配不到结果?

ethtool -k 输出中的特性名是全称 tcp-segmentation-offload,并不包含 "tso" 字样,所以 grep tso(退出码 1)匹配不到任何行。验证 TSO 状态应使用 grep tcp-segmentation-offload。关闭/开启用 ethtool -K eth0 tso off|on。

Q4:ethtool 5.16 能用 --json 输出吗?

实测不能。--json 虽在 help 的 FLAGS 中列出,但实际执行报 bad command line argument(s)(退出码 1、无 stdout),换参数顺序亦失败。真正的 JSON 输出需 ethtool 6.x 才可用。-S/-i/-k 等子命令默认即输出普通文本格式。

参考链接

Ubuntu 22.04 ethtool 安装与命令参数详解 - Quzuo