ethtool 命令管理以太网卡
# ethtool
命令管理以太网卡
ethtool
用于查看和修改网络设备(尤其是有线以太网设备)的驱动参数和硬件设置.你可以根据需要更改以太网卡的参数,包括自动协商、速度、双工和局域网唤醒等参数.通过对以太网卡的配置,你的计算机可以通过网络有效地进行通信.该工具提供了许多关于接驳到你的 Linux 系统的以太网设备的信息.
太网卡的工作原理:
- 半双工:半双工模式允许设备一次只能发送或接收数据包.
- 全双工:全双工模式允许设备可以同时发送和接收数据包.
- 自动协商:自动协商是一种机制,允许设备自动选择最佳网速和工作模式(全双工或半双工模式).
- 速度:默认情况下,它会使用最大速度,可以根据自己的需要改变它.
- 链接检测:链接检测可以显示网卡的状态.如果显示为
no
,请尝试重启网卡.如果链路检测仍显示no
,则检查交换机与系统之间连接的线缆是否有问题.
# 一、Linux
上安装ethtool
默认情况下,大多数系统上应该已经安装了 ethtool
.
# RHEL/CentOS和Fedora系统(高版本系统使用dnf进行安装)
sudo yum install -y ethtool
# Debian的系统使用apt命令或apt-get命令
sudo apt-get install ethtool
# openSUSE系统,使用zypper命令
sudo zypper install -y ethtool
# Arch Linux系统,使用pacman命令
## 参考博文: https://www.2daygeek.com/pacman-command-examples-manage-packages-arch-linux-system/
sudo pacman -S ethtool
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 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]
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
常用选项
-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(显示指定网卡的rx/tx环参数信息).
-G change the rx/tx ring setting of the specified ethernet card(更改指定以太网卡的 rx/tx 环设置).
-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地址等.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 二、检查Linux
上的可用网络接口
- 可以使用ip 命令 (opens new window)或
ifconfig
命令来验证可用的、活动的网卡的名称和其他细节
$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> 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 forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:6a:5a:4a brd ff:ff:ff:ff:ff:ff
altname enp2s1
inet 192.168.254.202/24 brd 192.168.254.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe6a:5a4a/64 scope link
valid_lft forever preferred_lft forever
$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.254.202 netmask 255.255.255.0 broadcast 192.168.254.255
inet6 fe80::20c:29ff:fe6a:5a4a prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:6a:5a:4a txqueuelen 1000 (Ethernet)
RX packets 1074688 bytes 1475487824 (1.4 GB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 321560 bytes 24956043 (24.9 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 7555 bytes 6386746 (6.3 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 7555 bytes 6386746 (6.3 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 三、检查Linux
上的网卡(NIC
)信息
在Linux
系统中,每个网卡(NIC
)都被分配了唯一的名称,如ethX、enpXXX
等.
- 旧的
Linux
发行版使用的是eth[X]
格式.例如,RHEL 6
和它们的旧版本. - 现代的
Linux
发行版使用enp[XXX]
或ens[XXX]
格式.例如,大多数现代Linux
发行版都使用这种格式,包括RHEL 7、Debian 10、Ubuntu 16.04 LTS
.
$ ethtool ens33
Settings for ens33:
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
Duplex: Full
Auto-negotiation: on
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
MDI-X: off (auto)
Supports Wake-on: d
Wake-on: d
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 四、检查以太网卡的驱动程序和固件版本
- 可以使用
ethtool
命令的-i
选项检查驱动程序版本、固件版本和总线的详细信息
$ ethtool -i ens33
driver: e1000
version: 5.15.0-43-generic
firmware-version:
expansion-rom-version:
bus-info: 0000:02:01.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: no
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 五、检查网络使用情况统计
- 使用
ethtool
命令中的-S
选项来查看网络使用情况统计.它可以显示传输的字节数、接收的字节数、错误数等.
$ ethtool -S ens33
NIC statistics:
rx_packets: 1074837
tx_packets: 321668
rx_bytes: 1479734684
tx_bytes: 24973283
rx_broadcast: 0
tx_broadcast: 0
rx_multicast: 0
tx_multicast: 0
rx_errors: 0
tx_errors: 0
tx_dropped: 0
multicast: 0
collisions: 0
rx_length_errors: 0
rx_over_errors: 0
rx_crc_errors: 0
rx_frame_errors: 0
rx_no_buffer_count: 0
rx_missed_errors: 0
tx_aborted_errors: 0
tx_carrier_errors: 0
tx_fifo_errors: 0
tx_heartbeat_errors: 0
tx_window_errors: 0
tx_abort_late_coll: 0
tx_deferred_ok: 0
tx_single_coll_ok: 0
tx_multi_coll_ok: 0
tx_timeout_count: 0
tx_restart_queue: 0
rx_long_length_errors: 0
rx_short_length_errors: 0
rx_align_errors: 0
tx_tcp_seg_good: 426
tx_tcp_seg_failed: 0
rx_flow_control_xon: 0
rx_flow_control_xoff: 0
tx_flow_control_xon: 0
tx_flow_control_xoff: 0
rx_long_byte_count: 1479734684
rx_csum_offload_good: 1073609
rx_csum_offload_errors: 0
alloc_rx_buff_failed: 0
tx_smbus: 0
rx_smbus: 0
dropped_smbus: 0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 六、改变以太网设备的速度
- 根据需要改变以太网的速度.当进行此更改时,网卡将自动掉线,需要使用ifup 命令 (opens new window)或
ip
命令或nmcli
命令将其重新上.
$ ethtool -s ens33 speed 100
$ ip link set ens33 up
1
2
2
# 七、Linux
上启用/禁用以太网卡的自动协商
ethtool
命令中的autoneg
选项启用或禁用自动协商
$ ethtool -s ens33 autoneg off
$ ethtool -s ens33 autoneg on
1
2
2
# 八、同时更改多个参数
ethtool
同时更改以太网多个参数
Syntax:
ethtool –s [device_name] speed [10/100/1000] duplex [half/full] autoneg [on/off]
$ ethtool –s ens33 speed 1000 duplex full autoneg off
1
2
3
4
2
3
4
# 九、检查特定网卡的自动协商、RX
和TX
- 查看指定以太网设备的自动协商等详细信息
$ ethtool -a ens33
Pause parameters for ens33:
Autonegotiate: on
RX: off
TX: off
# -g Display the rx/tx ring parameter information of the specified ethernet card(显示指定网卡的rx/tx环参数信息).
# -G change the rx/tx ring setting of the specified ethernet card(更改指定以太网卡的 rx/tx 环设置).
ethtool -G eth0 rx 4096 tx 4096
ethtool -G eth1 rx 4096 tx 4096
ethtool -g eth0
ethtool -g eth1
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# 十、从多个设备中识别出特定的网卡(闪烁网卡上的LED
)
- 如果想识别一个特定的物理接口,这个选项非常有用.如下
ethtool
命令会使ens33
端口的LED
灯闪烁
$ ethtool -p ens33
1
# 十一、在Linux
中永久设置这些参数
系统重启后,之前使用ethtool
做的更改将被默认恢复.
要使自定义设置永久化,需要更新网络配置文件中的值.根据不同Linux
发行版,需要将此值更新到正确的文件中.
RHEL
系统.必须使用ETHTOOL_OPTS
变量
$ vim /etc/sysconfig/network-scripts/ifcfg-ens33
ETHTOOL_OPTS="speed 1000 duplex full autoneg off"
1
2
3
2
3
Debian
的系统
$ vim /etc/network/interfaces
post-up ethtool -s eth0 speed 1000 duplex full autoneg off
1
2
3
2
3
上次更新: 2024/04/09, 16:48:42
- 01
- AWS NAT-NetWork-Firwalld配置(一)04-09
- 02
- AWS NAT-NetWork-Firwalld配置(二)04-09
- 03
- kubernetes部署minio对象存储01-18