ethtool 了解网卡参数

通过 ethtool 工具深入了解你的网卡

基本操作

1. 查看网口基本信息

ethtool eth0

2. 点亮网卡灯

# 亮 10 秒
$ ethtool -p eth0 10

3. 查看网卡驱动

# driver:网卡的驱动名称
$ ethtool -i eth0
driver: e1000
version: 5.15.0-88-generic
firmware-version:
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: no

4. 查询网口收发包详细统计信息

# 查看网口所有统计相关信息
$ ethtool -S eth0

# 查看网卡各个队列收包数据
$ ethtool -S eth0 | grep rx_queue | grep packets
    rx_queue_0_packets: 117947
    rx_queue_1_packets: 3050
    rx_queue_2_packets: 1098
    rx_queue_3_packets: 1204
    rx_queue_4_packets: 9679
    rx_queue_5_packets: 1172
    rx_queue_6_packets: 7435
    rx_queue_7_packets: 2403

高级操作

1. 查看网卡 offload 参数的状态

$ ethtool -k eth0
    Features for eth0:
    rx-checksumming: on
    tx-checksumming: on
    tcp-segmentation-offload: on
    udp-fragmentation-offload: off [fixed]
    generic-segmentation-offload: on
    generic-receive-offload: off
    large-receive-offload: off [fixed]
    ... ...
    ntuple-filters: off [fixed]
    receive-hashing: on

参数解释如下:

  • rx-checksumming: 接收包校验和
  • tx-checksumming: 发送包校验和
  • tcp-segmentation-offload: 简称为 TSO,利用网卡对 TCP 数据包分片
  • udp-fragmentation-offload: 简称为 UFO,针对 UDP 的
  • generic-segmentation-offload: 简称 GSO,基本思想就是尽可能的推迟数据分片直至发送到网卡驱动之前,检查网卡是否支持分片功能(如 TSO、UFO),如果支持直接发送到网卡,如果不支持就进行分片后再发往网卡。这样大数据包只需走一次协议栈,而不是被分割成几个数据包分别走,这就提高了效率
  • generic-receive-offload: 简称 GRO,基本思想跟 LRO 类似,克服了 LRO 的一些缺点,更通用。后续的驱动都使用 GRO 的接口,而不是 LRO
  • large-receive-offload: 简称 LRO,通过将接收到的多个 TCP 数据聚合成一个大的数据包,然后传递给网络协议栈处理,以减少上层协议栈处理 开销,提高系统接收 TCP 数据包的能力
  • ntuple-filters: ntuple

2. 配置网卡 offload 参数

$ ethtool -K eth0 rx-checksum on|off
$ ethtool -K eth0 tx-checksum-ip-generic on|off
$ ethtool -K eth0 tso on|off
$ ethtool -K eth0 ufo on | off
$ ethtool -K eth0 gso on | off
$ ethtool -K eth0 ntuple on | off

3. 查看网卡 ntuple 配置规则

$ ethtool -n eth5
24 RX rings available
Total 480 rules
Filter: 100
        Rule Type: Raw IPv4
        Src IP addr: 0.0.0.0 mask: 255.255.255.255
        Dest IP addr: 10.79.229.11 mask: 255.255.0.0
        TOS: 0x0 mask: 0xff
        Protocol: 0 mask: 0xff
        L4 bytes: 0x0 mask: 0xffffffff
        Action: Direct to queue 11

4. 查看现有 flow-hash 配置

$ ethtool -n eth5 rx-flow-hash tcp4
    TCP over IPV4 flows use these fields for computing Hash flow key:
    IP SA
    IP DA

5. 配置 flow-hash

$ ethtool -N eth5 rx-flow-hash udp4 sd
$ ethtool -N eth5 rx-flow-hash tcp4 sd
$ ethtool -N eth5 rx-flow-hash udp4 sdfn
$ ethtool -N eth5 rx-flow-hash tcp4 sdfn

# 选项含义:
# s  Hash on the IP source address of the rx packet.
# d  Hash on the IP destination address of the rx packet.
# f  Hash on bytes 0 and 1 of the Layer 4 header of the rx packet.
# n  Hash on bytes 2 and 3 of the Layer 4 header of the rx packet.

6. 查看网卡队列数量

通过 -l 选项查看网卡队列数:

$ ethtool -l eth4
Channel parameters for eth4:
Pre-set maximums:
RX:             16
TX:             16
Other:          1
Combined:       16
Current hardware settings:
RX:             0
TX:             0
Other:          1
Combined:       8 # 当前网卡队列数是 8

如果需要修改的话,使用 -L 选项

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

robin5911

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值