目 录CONTENT

文章目录

【运维】网卡协商速度查看

EulerBlind
2025-09-02 / 0 评论 / 2 点赞 / 281 阅读 / 0 字

在Linux系统中,网卡协商速度是网络性能调优和故障排查的重要指标。本文介绍如何查看和分析网卡的协商状态。

查看网卡接口

首先需要确认系统中的网卡接口名称:

# 查看所有网络接口
ip addr show
# 或者使用传统命令
ifconfig -a

常见的网卡命名规则:

  • eth0, eth1 - 传统命名方式
  • enx + MAC地址 - 基于MAC地址的命名
  • ens33, ens160 - VMware虚拟网卡
  • eno1, eno2 - 板载网卡

查看网卡协商状态

**使用 **ethtool 命令查看网卡的详细信息和协商状态:

# 查看指定网卡的详细信息
ethtool eth0

# 如果网卡名称不同,请替换为实际的接口名
ethtool enx6c1ff759f1ca

输出示例解析

Settings for enx6c1ff759f1ca:
        Supported ports: [ TP    MII ]                    # 支持的端口类型
        Supported link modes:   10baseT/Half 10baseT/Full  # 支持的链路模式
                                100baseT/Half 100baseT/Full
                                1000baseT/Half 1000baseT/Full
                                2500baseT/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
        Advertised pause frame use: No                   # 本端通告的暂停帧使用
        Advertised auto-negotiation: Yes                 # 本端通告的自动协商
        Advertised FEC modes: Not reported               # 本端通告的FEC模式
        Link partner advertised link modes:  10baseT/Half 10baseT/Full  # 对端通告的链路模式
                                             100baseT/Half 100baseT/Full
        Link partner advertised pause frame use: No      # 对端通告的暂停帧使用
        Link partner advertised auto-negotiation: Yes    # 对端通告的自动协商
        Link partner advertised FEC modes: Not reported  # 对端通告的FEC模式
        Speed: 100Mb/s                                   # 当前协商速度
        Duplex: Full                                     # 双工模式
        Auto-negotiation: on                             # 自动协商状态
        Port: MII                                        # 端口类型
        PHYAD: 32                                        # PHY地址
        Transceiver: internal                            # 收发器类型
        Supports Wake-on: pumbg                          # 支持的唤醒模式
        Wake-on: g                                       # 当前唤醒模式
        Current message level: 0x00007fff (32767)       # 当前消息级别

关键参数说明

速度相关参数

  • Speed: 当前协商的实际速度(如100Mb/s、1Gb/s)
  • Supported link modes: 网卡硬件支持的所有链路模式
  • Advertised link modes: 本端向对端通告的链路模式
  • Link partner advertised link modes: 对端通告的链路模式

双工模式

  • Duplex: 双工模式
    • Full: 全双工(同时收发)
    • Half: 半双工(交替收发)

自动协商

  • Auto-negotiation: 自动协商功能状态
    • on: 启用自动协商
    • off: 禁用自动协商

常用查看命令

快速查看速度

# 只查看速度和双工模式
ethtool eth0 | grep -E "Speed|Duplex"

# 查看所有网卡的基本信息
for interface in $(ip link show | grep -E "^[0-9]+:" | cut -d: -f2 | tr -d ' '); do
    echo "=== $interface ==="
    ethtool $interface 2>/dev/null | grep -E "Speed|Duplex" || echo "Not available"
done

查看统计信息

# 查看网卡统计信息
ethtool -S eth0

# 查看网卡驱动信息
ethtool -i eth0

查看网卡状态

# 查看网卡是否启用
ethtool eth0 | grep "Link detected"

# 查看网卡配置
ethtool -g eth0  # 查看环形缓冲区大小

故障排查技巧

1. 速度不匹配问题

如果协商速度低于预期:

# 检查网线质量
ethtool eth0 | grep "Link detected"

# 查看错误统计
ethtool -S eth0 | grep -i error

2. 强制设置速度

# 强制设置为1000M全双工(需要root权限)
sudo ethtool -s eth0 speed 1000 duplex full autoneg off

# 恢复自动协商
sudo ethtool -s eth0 autoneg on

3. 查看网卡驱动

# 查看当前使用的驱动
ethtool -i eth0

# 查看驱动参数
modinfo e1000e  # 以Intel e1000e驱动为例

实际应用场景

网络性能优化

  1. 确认协商速度: 确保网卡以最高速度协商
  2. 检查双工模式: 避免半双工造成的性能损失
  3. 监控错误: 定期检查网卡错误统计

故障诊断

  1. 网络中断: 检查网卡协商状态和错误统计
  2. 速度下降: 分析协商历史和链路质量
  3. 兼容性问题: 对比本端和对端的通告模式

注意事项

  • ethtool 命令需要root权限才能修改网卡设置
  • 修改网卡设置可能导致网络连接中断
  • 某些虚拟网卡可能不支持所有ethtool功能
  • 网卡协商速度受网线质量、交换机端口、驱动版本等因素影响
2

评论区