目录

​即看即用​

​详细信息​

​软件简介​

​安装​

​ethtool的使用​

​输出详解​

​其他指令​

​将 ethtool 设置永久保存​



即看即用

查看:

ethtool ethx 查看eth0网卡的基本设置,内容包括网卡速率、网卡的工作模式等,其中 x 是对应网卡的编号,如eth0、eth1等等

ethtool -i eth0   查看eth0网卡的驱动信息,内容包括驱动的型号、驱动的版本等

ethtool -d ethx  查询ethx网口注册性信息
ethtool -S ethx  查询ethx网口收发包统计 (注意S是大写)
ethtool –h         //显示ethtool的命令帮助(help)
ethtool –r ethX  //重置ethX网口到自适应模式

设置:

注意:该命令只是临时设置,如果网卡重启就失效了,如果想要永久保存应该配置 /etc/sysconfig/network-scripts/ifcfg-ethx 文件,见后面详细信息。

[root@mysql ~]# ethtool -s eth0 speed [10|100|1000] # 设置网卡的速率,单位是:Mb/s

[root@mysql ~]# ethtool -s eth0 duplex [half|full] # 设置网卡的工作模式,可设置为半双工或全双工

[root@mysql ~]# ethtool -s eth0 autoneg [on|off] # 设置网卡是否自动协商,自动协商的内容主要包括工作模式、网卡速率以及流控等参数

[root@mysql ~]# ethtool -s eth0 autoneg off speed 100 duplex full # 也可以同时写在一起

详细信息

软件简介

ethtool 是一个 Linux 下的网络驱动程序的诊断和调整工具,可获取网络设备的相关信息,包括连接状态、驱动版本、PCI 总线定位等等。

它可以用来:

  • 获取标识和诊断信息
  • 获取扩展的设备统计信息
  • 控制以太网设备的速度、双工、自动协商和流控制
  • 控制校验和卸载及其他硬件卸载功能
  • 控制 DMA 环大小及中断控制
  • 控制多队列设备的接收队列选择
  • 升级闪存中的固件

安装

 

ethtool的使用

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]

参数说明:
-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. 

 

输出详解

ethtool eth0

[root@localhost ~]# 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: No
Supports auto-negotiation: Yes // 支持自动协商
Supported FEC modes: Not reported
 
// 通告模式
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes // 使用自动协商
Advertised FEC modes: Not reported
 
Speed: 1000Mb/s // 当前速率 1000Mb/s
Duplex: Full // 工作模式为全双工
 
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
 
Auto-negotiation: on // 自动协商打开
 
MDI-X: off (auto)
Supports Wake-on: d
Wake-on: d
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes

 

其他指令

 

ethtool -A tx off eth0    停止网卡的发送模块TX

操作完毕后,可输入:ethtool -a eth0,查看tx模块是否已被停止。

 

ethtool -K eth0 rx off 关闭网卡对收到的数据包的校验功能

操作完毕后,可输入:ethtool -k eth0,查看校验功能是否已被停止。

 

ethtool -p eth0 10  如果机器上安装了两块网卡,查看eth0对应着哪块网卡

操作完毕后,看哪块网卡的led灯在闪,eth0就对应着哪块网卡。

ethtool -s eth0 speed 100 将千兆网卡的速度降为百兆

1)[root@linux /]# which ethtool                     //查询 ethtool 存放的路径

    /sbin/ethtool

2)[root@linux /]# rpm -qf /sbin/ethtool        //查询 ethtool 的版本信息

   ethtool-1.6-5

将 ethtool 设置永久保存

 将 ethtool 设置永久保存在网络设备有两种方法,一种是写入网口配置文件中,一种是开机自启动脚本。

 解决方法一:
 ethtool 设置可通过 /etc/sysconfig/network-scripts/ifcfg-ethX 文件保存,从而在设备下次启动时激活选项。 
例如:ethtool -s eth0 speed 100 duplex full autoneg off
此指令将eth0设备设置为全双工自适应,速度为100Mbs。若要eth0启动时设置这些参数, 修改文件/etc/sysconfig/network-scripts/ifcfg-eth0 ,添加如下一行: 
ETHTOOL_OPTS="speed 100 duplex full autoneg off"

解决方法二:
 将ethtool设置写入/etc/rc.d/rc.local之中。