通过 ethtool 工具深入了解你的网卡  
        
        
        
        
        
        
        基本操作 1.  查看网口基本信息
 
2.  点亮网卡灯
1 2 3 4 5 $ ethtool -p eth0 10 $ ethtool -p eth0 
 
3.  查看网卡驱动
1 2 3 4 5 6 7 8 9 10 11 $ 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.  查询网口收发包详细统计信息
1 2 3 4 5 6 7 8 9 10 11 12 13 $ 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 参数的状态
1 2 3 4 5 6 7 8 9 10 11 12 $ 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 参数
1 2 3 4 5 6 $ 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 配置规则
1 2 3 4 5 6 7 8 9 10 11 $ 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 配置
1 2 3 4 $ 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
1 2 3 4 5 6 7 8 9 10 $ 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 
 
6.  查看网卡队列数量
通过 -l 选项查看网卡队列数:
1 2 3 4 5 6 7 8 9 10 11 12 $ 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  
 
如果需要修改的话,使用 -L 选项
        
         
        
         
        
    
    上一篇 « Linux网卡驱动常用命令与操作 
    
    
    下一篇 » 如何根据网卡名称查看对应 PCI 信息