linux怎么使用ethtool命令管理以太网卡

发布时间:2021-10-23 10:30:49 作者:小新
来源:亿速云 阅读:470

小编给大家分享一下linux怎么使用ethtool命令管理以太网卡,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

ethtool  用于查看和修改网络设备(尤其是有线以太网设备)的驱动参数和硬件设置。你可以根据需要更改以太网卡的参数,包括自动协商、速度、双工和局域网唤醒等参数。通过对以太网卡的配置,你的计算机可以通过网络有效地进行通信。该工具提供了许多关于接驳到你的  Linux 系统的以太网设备的信息。

我们将告诉你如何更改以下的参数以及如何查看这些参数。这篇文章将帮助你在 Linux 系统中排除与以太网卡相关的问题。

下面的信息将帮助你了解以太网卡的工作原理。

如何在 Linux 上安装 ethtool

默认情况下,大多数系统上应该已经安装了 ethtool。如果没有,你可以从发行版的官方版本库中安装。

对于 RHEL/CentOS 6/7 系统,请使用 s-systems/" class="ext" rel="external nofollow" target="_blank">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或# ifconfig 1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00    inet 127.0.0.1/8 scope host lo       valid_lft forever preferred_lft forever2: eth0: mtu 1500 qdisc mq state UP group default qlen 1000    link/ether 00:10:22:35:23:sf brd ff:ff:ff:ff:ff:ff    inet 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 等。

# ethtool eth0 Settings for eth0:        Supported ports: [ TP ]        Supported link modes: 1000baseT/Full                              10000baseT/Full        Supported pause frame use: No        Supports auto-negotiation: No        Supported FEC modes: Not reported        Advertised link modes: Not reported        Advertised pause frame use: No        Advertised auto-negotiation: No        Advertised FEC modes: Not reported        Speed: 10000Mb/s        Duplex: Full        Port: Twisted Pair        PHYAD: 0        Transceiver: internal        Auto-negotiation: off        MDI-X: Unknown        Supports Wake-on: uag        Wake-on: d        Link detected: yes

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

你可以使用 ethtool 命令的 -i 选项检查驱动程序版本、固件版本和总线的详细信息,如下所示:

# ethtool -i eth0 driver: 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 eth0 NIC 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: 0          too many frags: 0          giant hdr: 0          hdr err: 0          tso: 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: 0          too many frags: 0          giant hdr: 0          hdr err: 0          tso: 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: 0          err: 0          fcs: 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: 0          err: 0          fcs: 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-eth0 ETHTOOL_OPTS="speed 1000 duplex full autoneg off"

对于基于 Debian 的系统:

# vi /etc/network/interfaces post-up ethtool -s eth0 speed 1000 duplex full autoneg off

以上是“linux怎么使用ethtool命令管理以太网卡”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. 如何在Linux中使用LVM管理命令
  2. 如何在Linux中使用命令管理进程

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ethtool命令 linux

上一篇:在Windows 10照片应用中如何查找和标记人物

下一篇:在Windows 10中怎样删除备份文件

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》