# ethtool **Repository Path**: itopen/ethtool ## Basic Information - **Project Name**: ethtool - **Description**: ethtool的鸿蒙编译适配 - **Primary Language**: Unknown - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2025-03-05 - **Last Updated**: 2025-03-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 简介 ethtool是一个 Linux 下功能强大的网络管理工具,目前几乎所有的网卡驱动程序都有对 ethtool 的支持,可以用于网卡状态/驱动版本信息查询、收发数据信息查询及能力配置以及网卡工作模式/链路速度等查询配置。 它可以用来: - 获取标识和诊断信息 - 获取扩展的设备统计信息 - 控制以太网设备的速度、双工、自动协商和流控制 - 控制校验和卸载及其他硬件卸载功能 - 控制 DMA 环大小及中断控制 - 控制多队列设备的接收队列选择 - 升级闪存中的固件 ## 查看: ``` 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网口到自适应模式 ethtool -g ethx 显示网卡的接收/发送环形参数。 ``` ## 设置: 注意:该命令只是临时设置,如果网卡重启就失效了,如果想要永久保存应该配置 /etc/sysconfig/network-scripts/ifcfg-ethx 文件,见后面详细信息。 ``` ethtool -s eth0 speed [10|100|1000] # 设置网卡的速率,单位是:Mb/s ethtool -s eth0 autoneg [on|off] # 设置网卡是否自动协商 自动协商的内容主要包括工作模式、网卡速率以及流控等参数 ethtool -s ethX [speed 10|100|1000] [duplex half|full] [autoneg on|off] //设置网口速率10/100/1000M、设置网口半/全双工、设置网口是否自协商 ethtool -s eth0 autoneg off speed 100 duplex full # 也可以同时写在一起 ethtool -s eth0 duplex [half|full] # 设置网卡的工作模式,可设置为半双工或全双工 ethtool -G eth0 rx 4096 /ethtool -G eth0 tx 4096 //修改网卡的接收/发送环形参数。 ethtool -E eth0 magic 0x10798086 offset 0x10 value 0x1A 修改网卡EEPROM内容(0x1079 网卡device id , 0x8086网卡verdor id ) ethtool -e eth0 : dump网卡EEPROM内容 ``` | ethX | 查询ethx网口基本设置,其中x是对应网卡的编号,如eth0、eth1等。 | | ---- | ------------------------------------------------------------ | | -k | 查询网卡的Offload信息。 | | -K | 修改网卡的Offload信息。 | | -c | 查询网卡聚合信息。 | | -C | 修改网卡聚合信息。 | | -l | 查看网卡队列数。 | | -L | 设置网卡队列数。 | ``` -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 -k eth0 Features for eth0: rx-checksumming: on tx-checksumming: on scatter-gather: on tcp-segmentation-offload: on # ethtool -l eth0 Channel parameters for eth0: Pre-set maximums: … Current hardware settings: … Combined: 8 # ethtool -c eth0 Coalesce parameters for eth0: Adaptive RX: off TX: off … rx-usecs:30 rx-frames:50 … tx-usecs:30 tx-frames:1 ``` | **参数** | **说明** | | ------------------------ | ---------------------------------------------------- | | rx-checksumming | 接收包校验和。 | | tx-checksumming | 发送包校验和。 | | scatter-gather | 分散-聚集功能,是网卡支持TSO的必要条件之一。 | | tcp-segmentation-offload | 简称为TSO,利用网卡对TCP数据包分片。 | | Combined | 网卡队列数。 | | adaptive-rx | 接收队列的动态聚合执行开关。 | | adaptive-tx | 发送队列的动态聚合执行开关。 | | tx-usecs | 产生一个中断之前至少有一个数据包被发送之后的微秒数。 | | tx-frames | 产生中断之前发送的数据包数量。 | | rx-usecs | 产生一个中断之前至少有一个数据包被接收之后的微秒数。 | | rx-frames | 产生中断之前接收的数据包数量。 | #### 其他命令 ``` 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就对应着哪块网卡。 ```