ethtool 网卡诊断和调整工具总结
ethtool 是一个 Linux 下的网络驱动程序的诊断和调整工具,可获取网络设备的相关信息,包括连接状态、驱动版本、PCI 总线定位等等。
1. ethtool
使用ethtool工具设置和查询网卡参数,参考资料路径:https://blog.csdn.net/u011857683/article/details/83758689
1.1 语法参数
ethtool [ -a | -c | -g | -i | -d | -k | -r | -S |] ethX
ethtool [-A] ethX [autoneg on|off] [rx on|off] [tx on|off]
ethtool [-C] ethX [adaptive-rx on|off] [adaptive-tx on|off] [rx-usecs N]
[rx-frames N] [rx-usecs-irq N] [rx-frames-irq N] [tx-usecs N]
[tx-frames N] [tx-usecs-irq N] [tx-frames-irq N] [stats-block-usecs N]
[pkt-rate-low N][rx-usecs-low N] [rx-frames-low N] [tx-usecs-low N]
[tx-frames-low N] [pkt-rate-high N] [rx-usecs-high N] [rx-frames-high N]
[tx-usecs-high N] [tx-frames-high N] [sample-interval N]
ethtool [-G] ethX [rx N] [rx-mini N] [rx-jumbo N] [tx N]
ethtool [-e] ethX [raw on|off] [offset N] [length N]
ethtool [-E] ethX [magic N] [offset N] [value N]
ethtool [-K] ethX [rx on|off] [tx on|off] [sg on|off] [tso on|off]
ethtool [-p] ethX [N]
ethtool [-t] ethX [offline|online]
ethtool [-s] ethX [speed 10|100|1000] [duplex half|full] [autoneg on|off]
[port tp|aui|bnc|mii] [phyad N] [xcvr internal|external]
[wol p|u|m|b|a|g|s|d...] [sopass xx:yy:zz:aa:bb:cc] [msglvl N]
1.2 常见参数说明
参数 | 说明 |
---|---|
-a | 查看网卡中接收模块RX、发送模块TX和Autonegotiate模块的状态:启动on 或 停用off。 |
-A | 修改网卡中 接收模块RX、发送模块TX和Autonegotiate模块的状态:启动on 或 停用off。 |
-c | display the Coalesce(聚合、联合) information of the specified ethernet card.聚合网口信息,使看起来更有规律。 |
-C | Change the Coalesce setting of the specified ethernet card.修改网卡聚合信息。 |
-g | Display the rx/tx ring parameter information of the specified ethernet card. 显示网卡的接收/发送环形参数。 |
-G | Change the rx/tx ring setting of the specified ethernet card. 修改网卡的接收/发送环形参数。 |
-i | 显示网卡驱动的信息,如驱动的名称、版本等。 |
-d | 显示register dump信息, 部分网卡驱动不支持该选项。 |
-e | 显示EEPROM dump信息,部分网卡驱动不支持该选项。 |
-E | 修改网卡EEPROM byte. |
-k | 显示网卡Offload参数的状态:on 或 off,包括rx-checksumming、tx-checksumming等。 |
-K | 修改网卡Offload参数的状态 |
-p | 用于区别不同ethX对应网卡的物理位置,常用的方法是使网卡port上的led不断的闪;N指示了网卡闪的持续时间,以秒为单位。 |
-r | 如果auto-negotiation模块的状态为on,则restarts auto-negotiation. |
-s | 修改网卡的部分配置,包括网卡速度、单工/全双工模式、mac地址等。加上-s选项修改的内容才会生效 |
-S | 显示NIC- and driver-specific 的统计参数,如网卡接收/发送的字节数、接收/发送的广播包个数等。 |
-t | 让网卡执行自我检测,有两种模式:offline or online. |
2. 工具使用举例
2.1 查询网卡基本设置
ethtool 网卡名称
2.2 查询网口驱动相关信息
ethtool -i 网卡名称
2.3 查询网口注册信息
ethtool -d 网卡名称
2.4 查询网口收发包统计
ethtool -S 网卡名称
2.5 设置网卡工作方式
ethtool -s 网卡名称 [speed 10|100|1000] [duplex half|full] [autoneg on|off]
设置网口速率10/100/1000M、设置网口半/全双工、设置网口是否自协商。自动协商关闭后,重新打开即可恢复原来的选项。
2.6 指定自动协商的速率和双工方式
ethtool -s 网卡名称advertise N
指定通过自动协商机制通告的速度和双工方式。N为十六进制值,如0x008表示100Mb/s+全双工、0x020表示1000Mb/s+全双工。
2.7 其他
- 停止网卡发送模块Tx,可以发送 ethtool –A Tx off 网卡名称
操作完毕后,可输入:
ethtool -a eth0
查看tx模块是否已被停止
- 关闭网卡对收到数据包的校验功能,输入命令:
ethtool –K 网卡名称 rx off
操作完毕后,可输入:
ethtool -k eth0
查看校验功能是否已被停止。
- 如果机器上有2个网卡,如何查看eth0对应那个网卡,输入命令:
ethtool –p eth0 10
操作完毕后,看那个网卡的led灯在闪,操作的就是这个网卡
- 查看网卡,在接收和发送数据时有没有出错
ethtool –S 网卡名称
- 将千兆网卡降为百兆网卡
ethtool –S speed 100
- 永久保存配置
将网卡的配置永久保存的方式有2种,一种是将配置写入网卡配置文件中,一种是将配置写入开机自启动脚本中。
Ethtool 设置可以保存在/etc/sysconfig/network-scripts/ifcfg-ethx 文件中,从而在下次启动时激活选项
例如:ethtool -s eth0 speed 100 duplex full autoneg off
(1)此指令将eth1设备设置为全双工自适应,速度为100Mbs。若要eth0启动时设置这些参数, 修改文件/etc/sysconfig/network-scripts/ifcfg-eth1 ,添加如下一行:
ETHTOOL_OPTS="speed 100 duplex full autoneg off"
(2)将ethtool设置写入/etc/rc.d/rc.local之中,开机自动执行命令设置
ethtool -s eth0 speed 100 duplex full autoneg off