ethtool
指令详细使用指南
ethtool
是 Linux 系统中用于查询和修改以太网设备参数的命令行工具,广泛用于网络管理、调试和优化。
基本用法
ethtool [options] <interface>
<interface>
:需要操作的网络接口名称(如eth0
、ens33
等)。[options]
:具体的功能选项,决定对接口执行何种操作。
常用选项
1. 显示接口的基本信息
ethtool <interface>
功能:显示网卡的基础信息,包括速度、双工模式、自协商状态等。
示例:
ethtool eth0
输出示例:
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Supported pause frame use: Symmetric
Supports auto-negotiation: Yes
Advertised link modes: 1000baseT/Full
Advertised pause frame use: Symmetric
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
2. 查询支持的功能
ethtool -i <interface>
功能:显示网卡驱动相关信息。
示例:
ethtool -i eth0
输出示例:
driver: e1000
version: 3.2.6-k
firmware-version: 1.5-0
expansion-rom-version:
bus-info: 0000:00:03.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: yes
3. 显示统计信息
ethtool -S <interface>
功能:查询设备的统计信息(如包计数、错误计数等)。
示例:
ethtool -S eth0
输出示例:
NIC statistics:
rx_packets: 100000
tx_packets: 98000
rx_bytes: 8000000
tx_bytes: 7600000
rx_errors: 5
tx_errors: 2
4. 修改网卡速度和双工模式
ethtool -s <interface> speed <speed> duplex <mode> autoneg <on|off>
功能:设置网卡速度、双工模式及是否启用自协商。
选项说明:
<speed>
:指定速度(10、100、1000等,单位 Mbps)。<mode>
:双工模式(full
或half
)。autoneg
:是否开启自动协商(on
或off
)。
示例:
ethtool -s eth0 speed 100 duplex full autoneg off
注意:
- 修改后可能会导致网络中断,应小心使用。
- 确保网卡和交换机支持所设置的参数。
5. 获取网卡的当前消息级别
ethtool -g <interface>
功能:显示网卡支持的接收和发送缓冲区大小。
示例:
ethtool -g eth0
输出示例:
Ring parameters for eth0:
Pre-set maximums:
RX: 4096
TX: 4096
Current hardware settings:
RX: 256
TX: 256
6. 设置网卡接收和发送队列大小
ethtool -G <interface> rx <value> tx <value>
功能:修改网卡的接收和发送缓冲区大小。
示例:
ethtool -G eth0 rx 512 tx 512
7. 设置 Wake-on-LAN(WOL)功能
ethtool -s <interface> wol <options>
功能:启用或禁用 Wake-on-LAN 功能。
选项说明:
p
:支持基于 Magic Packet 的唤醒。u
:支持基于未校验的 Magic Packet。g
:支持广播唤醒。
示例:
ethtool -s eth0 wol g
查询当前 WOL 设置:
ethtool eth0
输出示例:
Wake-on: g
8. 调整网卡的消息级别
ethtool -s <interface> msglvl <value>
功能:设置网卡驱动的日志输出级别,用于调试。
9. 设置数据包的卸载特性
ethtool -k <interface> # 查看卸载状态
ethtool -K <interface> feature on|off # 设置卸载特性
功能:查询和设置网卡的硬件卸载特性,例如 TCP 校验和卸载(checksum offload)或分段卸载(TSO)。
示例:
-
查询卸载特性:
ethtool -k eth0
输出示例:
Features for eth0: rx-checksumming: on tx-checksumming: on scatter-gather: on tcp-segmentation-offload: off
-
禁用分段卸载(TSO):
ethtool -K eth0 tso off
10. 测试网卡功能
ethtool -t <interface> [offline|online]
功能:运行网卡的在线或离线自检(由驱动支持)。
11. 查询网卡 EEPROM 信息
ethtool -e <interface>
功能:显示 EEPROM 的内容(某些网卡可能需要管理员权限)。
12. 查看网卡注册表转储
ethtool -d <interface>
功能:显示网卡的寄存器内容(用于硬件调试)。
综合示例
显示网卡 eth0 的所有功能和状态:
ethtool eth0
ethtool -S eth0
ethtool -k eth0
ethtool -i eth0
修改网卡的速度和卸载特性:
ethtool -s eth0 speed 1000 duplex full autoneg on
ethtool -K eth0 tso off rx-checksumming off
调整缓冲区大小:
ethtool -G eth0 rx 1024 tx 512