所在位置:首页 → 电脑知识 → Linux命令之:ethtool命令

Linux命令之:ethtool命令

发布: 更新时间:2022-12-20 20:31:19

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

一、准备工作

首先,我们需要获取网卡信息:使用ip aifconfig查看可用的、活动的网卡的名称和其他细节

这里我们可以看到有三块网卡,分别是:ens160/ens192/ens224

得到网卡的名称后,就可以使用ethtool 命令来查看或修改一些东西了。

二、常用操作

查看网卡与对应物理端口

这个功能我觉得是最有用的一个小技巧,可以使网卡对应的端口上的led不断的闪,方便我们找到物理端口

ethtool -p ens160

操作完毕后,看哪块网卡的led灯在闪,ens160就对应着哪个物理端口。

查看机器上网卡的速度

ethtool 网卡名称,查看机器上网卡的速度:百兆还是千兆

检查以太网卡的驱动程序和固件版本

ethtool -i 网卡名称,查看驱动程序版本、固件版本和总线的详细信息

检查网络使用情况统计

你可以使用 ethtool 命令中的 -S 选项来查看网络使用情况统计。它可以显示传输的字节数、接收的字节数、错误数等。

改变以太网设备的速度

你可以根据需要改变以太网的速度。当你进行此更改时,网卡将自动掉线,你需要使用 ifup命令 或 ip 命令或 nmcli 命令将其重新上。

ethtool -s ens160 speed 100

ip link set ens160 up

三、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-lowN] [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 显示NIC- and driver-specific 的统计参数,如网卡接收/发送的字节数、接收/发送的广播包个数等。
-t 让网卡执行自我检测,有两种模式:offline or online。
-s 修改网卡的部分配置,包括网卡速度、单工/全双工模式、mac地址等。
标签:, ,
文章排行