好的,阿杰 👍
下面我来给你写一份 Linux 命令之 ethtool 用法详解,带上常见参数、实战示例以及应用场景。
🔧 Linux 命令之 ethtool 用法详解
1. ethtool 简介
ethtool
是 Linux 下一个常用的 网卡管理工具,主要用于:
- 查看网卡驱动信息、链路状态
- 配置网卡速率、双工模式
- 开启/关闭自协商
- 查看/修改网卡的队列、缓存、卸载能力
- 诊断网络问题(如线缆测试)
相比 ifconfig
或 ip
命令,ethtool
更偏向于 驱动层和物理层的参数调试。
2. 基本用法
ethtool <网卡名称>
示例:
ethtool eth0
输出示例:
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: Symmetric
Supports auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Auto-negotiation: on
Link detected: yes
这里能看到网卡是否连通(Link detected)、速率(Speed)、双工模式(Duplex)。
3. 常用参数
(1)查看网卡信息
ethtool eth0
作用:查看网卡速率、双工、自协商、驱动信息。
(2)设置速率与双工模式
ethtool -s eth0 speed 100 duplex full autoneg off
说明:
speed
:设置速率(10 / 100 / 1000 / 10000)duplex
:full
全双工,half
半双工autoneg
:是否开启自协商(on/off)
⚠️ 注意:某些物理网卡/驱动不支持手动设置。
(3)查看驱动信息
ethtool -i eth0
输出:
driver: e1000e
version: 3.2.6-k
firmware-version: 0.13-3
bus-info: 0000:00:19.0
(4)查看网卡统计信息
ethtool -S eth0
常见统计:
rx_packets
:接收的数据包数tx_packets
:发送的数据包数rx_errors
:接收错误数tx_errors
:发送错误数rx_dropped
:丢包数
(5)测试网卡
ethtool -t eth0
可测试网卡自检情况。
(6)查看环形缓冲区大小
ethtool -g eth0
修改缓冲区:
ethtool -G eth0 rx 4096 tx 4096
(7)关闭网卡卸载功能(排查问题时常用)
ethtool -K eth0 tso off gso off gro off
tso
:TCP 分段卸载gso
:大包分片gro
:接收端合并
关闭后能避免某些特殊场景的丢包问题。
(8)查看 Wake-on-LAN 支持
ethtool eth0 | grep Wake-on
启用 Wake-on-LAN:
ethtool -s eth0 wol g
4. 实战场景
- 网络速率异常时
使用ethtool eth0
查看是否速率协商错误,如本应千兆但实际只有 100Mb/s。 - 排查丢包/性能问题
ethtool -S eth0
查看rx_errors
、tx_errors
是否异常。 - 调优大流量应用
通过ethtool -G eth0
调整接收缓冲区,避免丢包。 - 测试网卡功能
使用ethtool -t eth0
进行自检。
5. 总结
ethtool
是网络工程师和运维常用工具,能查看和配置网卡的物理层和驱动层参数。- 常用场景包括:速率/双工调整、错误排查、驱动诊断、性能调优。
- 在现代 Linux 系统中,
ip
命令替代了ifconfig
,但ethtool
仍然是不可替代的。
好的,阿杰 👍
我来给你整理一个 ethtool
常用命令速查表 (Cheat Sheet),图表形式,一看就懂,方便平时排查或调试。
📌 ethtool 常用命令速查表
功能 | 命令 | 说明 |
---|---|---|
查看网卡基本信息 | ethtool eth0 | 显示速率、双工、自协商、链路状态 |
查看驱动信息 | ethtool -i eth0 | 驱动名、版本、固件、总线信息 |
查看网卡统计数据 | ethtool -S eth0 | 查看收发包数、错误包、丢包 |
查看支持速率 | ethtool eth0 | Supported link modes 中可见 |
设置速率/双工模式 | ethtool -s eth0 speed 100 duplex full autoneg off | 强制设置 100Mb/s 全双工,关闭自协商 |
启用自协商 | ethtool -s eth0 autoneg on | 交由网卡自动协商速率和模式 |
查看环形缓冲区 | ethtool -g eth0 | 显示 RX/TX 缓冲区大小 |
修改环形缓冲区 | ethtool -G eth0 rx 4096 tx 4096 | 提高缓冲区,减少丢包 |
查看网卡卸载功能 | ethtool -k eth0 | 查看 TSO/GSO/GRO 是否开启 |
关闭卸载功能 | ethtool -K eth0 tso off gso off gro off | 避免部分协议异常或丢包 |
网卡自检 | ethtool -t eth0 | 运行网卡自测试 |
查看链路状态 | `ethtool eth0 | grep “Link detected”` |
查看/设置 WOL | `ethtool eth0 | grep Wake-on/ ethtool -s eth0 wol g` |
监控实时速率 | `watch -n 1 “ethtool eth0 | grep Speed”` |
⚡ 小技巧
- 速率不对 → 用
ethtool -s
手动指定速率和双工。 - 丢包严重 → 用
ethtool -S
检查rx_errors
、rx_dropped
。 - 高并发服务 → 调整
-G
缓冲区 + 合理关闭卸载功能。 - 疑似网卡坏了 → 用
-t
运行网卡自检。
发表回复