ethtool 用于查看和修正网络设备(尤其是有线以太网设备)的驱动参数和硬件设置。
来源:https://linux.cn/article-12290-1.html作者:Magesh Maruthamuthu译者:Xingyu.Wangethtool 用于查看和修正网络设备(尤其是有线以太网设备)的驱动参数和硬件设置。你可以根据须要变动以太网卡的参数,包括自动协商、速率、双工和局域网唤醒等参数。通过对以太网卡的配置,你的打算机可以通过网络有效地进行通信。该工具供应了许多关于接驳到你的 Linux 系统的以太网设备的信息。
在这篇文章中,我们将见告你如何变动以下的参数以及如何查看这些参数。这篇文章将帮助你在 Linux 系统中打消与以太网卡干系的问题。

下面的信息将帮助你理解以太网卡的事情事理。
半双工:半双工模式许可设备一次只能发送或吸收数据包。全双工:全双工模式许可设备可以同时发送和吸收数据包。自动协商:自动协商是一种机制,许可设备自动选择最佳网速和事情模式(全双工或半双工模式)。速率:默认情形下,它会利用最大速率,你可以根据自己的须要改变它。链接检测:链接检测可以显示网卡的状态。如果显示为 no,请考试测验重启网卡。如果链路检测仍显示 no,则检讨交流机与系统之间连接的线缆是否有问题。如何在 Linux 上安装 ethtool默认情形下,大多数系统上该当已经安装了 ethtool。如果没有,你可以从发行版的官方版本库中安装。
对付 RHEL/CentOS 6/7 系统,请利用 yum 命令 安装 ethtool:
$ sudo yum install -y ethtool
对付 RHEL/CentOS 8 和 Fedora 系统,请利用 dnf 命令 安装 ethtool:
$ sudo yum install -y ethtool
对付基于 Debian 的系统,请利用 apt 命令 或 apt-get 命令 安装 ethtool:
$ sudo apt-get install ethtool
对付 openSUSE 系统,利用 zypper 命令 安装 ethtool:
$ sudo zypper install -y ethtool
对付 Arch Linux 系统,利用 pacman 命令 安装 ethtool:
$ sudo pacman -S ethtool
如何检讨 Linux 上的可用网络接口
你可以利用 ip 命令 或 ifconfig 命令(在当代发行版中已被淘汰)来验证可用的、活动的网卡的名称和其他细节:
# ip a或# ifconfig1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever2: eth0: mtu 1500 qdisc mq state UP group default qlen 1000link/ether 00:10:22:35:23:sf brd ff:ff:ff:ff:ff:ffinet 192.164.23.100/24 brd 192.164.23.255 scope global eth0 valid_lft forever preferred_lft forever
如何检讨 Linux 上的网卡(NIC)信息
节制了以太网卡名称后,就可以利用 ethtool 命令轻松查看其详细信息,如下所示。
在 Linux 系统中,每个网卡(NIC)都被分配了唯一的名称,如 ethX、enpXXX 等。
旧的 Linux 发行版利用的是 eth[X] 格式。例如,RHEL 6 和它们的旧版本。当代的 Linux 发行版利用 enp[XXX] 或 ens[XXX] 格式。例如,大多数当代 Linux 发行版都利用这种格式,包括 RHEL 7、Debian 10、Ubuntu 16.04 LTS。# ethtool eth0Settings for eth0:Supported ports: [ TP ]Supported link modes: 1000baseT/Full10000baseT/FullSupported pause frame use: NoSupports auto-negotiation: NoSupported FEC modes: Not reportedAdvertised link modes: Not reportedAdvertised pause frame use: NoAdvertised auto-negotiation: NoAdvertised FEC modes: Not reportedSpeed: 10000Mb/sDuplex: FullPort: Twisted PairPHYAD: 0Transceiver: internalAuto-negotiation: offMDI-X: UnknownSupports Wake-on: uagWake-on: dLink detected: yes
如何检讨以太网卡的驱动程序和固件版本
你可以利用 ethtool 命令的 -i 选项检讨驱动程序版本、固件版本和总线的详细信息,如下所示:
# ethtool -i eth0driver: vmxnet3version: 1.4.16.0-k-NAPIfirmware-version:expansion-rom-version:bus-info: 0000:0b:00.0supports-statistics: yessupports-test: nosupports-eeprom-access: nosupports-register-dump: yessupports-priv-flags: no
如何检讨网络利用情形统计
你可以利用 ethtool 命令中的 -S 选项来查看网络利用情形统计。它可以显示传输的字节数、吸收的字节数、缺点数等。
# ethtool -S eth0NIC statistics: Tx Queue#: 0 TSO pkts tx: 2053 TSO bytes tx: 7167572 ucast pkts tx: 4028081 ucast bytes tx: 399093197 mcast pkts tx: 0 mcast bytes tx: 0 bcast pkts tx: 0 bcast bytes tx: 0 pkts tx err: 0 pkts tx discard: 0 drv dropped tx total: 0too many frags: 0giant hdr: 0hdr err: 0tso: 0 ring full: 0 pkts linearized: 0 hdr cloned: 0 giant hdr: 0 Tx Queue#: 1 TSO pkts tx: 1955 TSO bytes tx: 6536945 ucast pkts tx: 3711838 ucast bytes tx: 346309662 mcast pkts tx: 0 mcast bytes tx: 0 bcast pkts tx: 1186 bcast bytes tx: 49812 pkts tx err: 0 pkts tx discard: 0 drv dropped tx total: 0too many frags: 0giant hdr: 0hdr err: 0tso: 0 ring full: 0 pkts linearized: 0 hdr cloned: 0 giant hdr: 0 Rx Queue#: 0 LRO pkts rx: 0 LRO byte rx: 0 ucast pkts rx: 5084776 ucast bytes rx: 4673133395 mcast pkts rx: 0 mcast bytes rx: 0 bcast pkts rx: 154143 bcast bytes rx: 45415676 pkts rx OOB: 0 pkts rx err: 0 drv dropped rx total: 0err: 0fcs: 0 rx buf alloc fail: 0 Rx Queue#: 1 LRO pkts rx: 0 LRO byte rx: 0 ucast pkts rx: 6346769 ucast bytes rx: 4835534292 mcast pkts rx: 0 mcast bytes rx: 0 bcast pkts rx: 3464 bcast bytes rx: 714646 pkts rx OOB: 0 pkts rx err: 0 drv dropped rx total: 0err: 0fcs: 0 rx buf alloc fail: 0 tx timeout count: 0
如何改变以太网设备的速率
你可以根据须要改变以太网的速率。当你进行此变动时,网卡将自动掉线,你须要利用 ifup 命令 或 ip 命令或 nmcli 命令将其重新上。
# ethtool -s eth0 speed 100# ip link set eth0 up
如何在 Linux 上启用/禁用以太网卡的自动协商?
你可以利用 ethtool 命令中的 autoneg 选项启用或禁用自动协商,如下图所示:
# ethtool -s eth0 autoneg off# ethtool -s eth0 autoneg on
如何同时变动多个参数
如果你想利用 ethtool 命令同时变动以太网卡的多个参数,请利用下面的格式:
Syntax:ethtool –s [device_name] speed [10/100/1000] duplex [half/full] autoneg [on/off]
# ethtool –s eth0 speed 1000 duplex full autoneg off
如何检讨特定网卡的自动协商、RX 和 TX
要查看关于特定以太网设备的自动协商等详细信息,请利用以下格式:
# ethtool -a eth0
如何从多个设备中识别出特定的网卡(闪烁网卡上的 LED)
如果你想识别一个特定的物理接口,这个选项非常有用。下面的 ethtool 命令会使 eth0 端口的 LED 灯闪烁:
# ethtool -p eth0
如何在 Linux 中永久设置这些参数
在系统重启后,你利用 ethtool 所做的变动将被默认规复。
要使自定义设置永久化,你须要更新网络配置文件中的值。根据你的 Linux 发行版,你可能须要将此值更新到精确的文件中。
对付基于 RHEL 的系统。你必须利用 ETHTOOL_OPTS 变量:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0ETHTOOL_OPTS="speed 1000 duplex full autoneg off"
对付基于 Debian 的系统:
# vi /etc/network/interfacespost-up ethtool -s eth0 speed 1000 duplex full autoneg off
via: https://www.2daygeek.com/linux-ethtool-command-view-change-ethernet-adapter-settings-nic-card/
作者: Magesh Maruthamuthu 选题: lujun9972 译者: wxy 校正: wxy
本文由 LCTT 原创编译, Linux中国 名誉推出
点击“理解更多”可访问文内链接