【计算机网络】10、ethtool

ethtool是一个用于查询和控制网络设备驱动及硬件设置的工具,特别是有线以太网设备。文章介绍了如何展示设备属性,如Auto-negotiation、Speed等,并展示了如何改变网卡属性,如关闭Auto-negotiation和调整Speed。此外,还提到了排除网络故障的方法和通过网口LED识别网卡,以及如何进行持久化配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述

一、ethtool

ethtool is used to query and control network device driver and hardware settings, particularly for wired Ethernet devices.

devname is the name of the network device on which ethtool should operate.

man 文档
参考

1.1 常见操作

1.1.1 展示设备属性

# root@ubuntu:~# ifconfig
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

# ethtool eno1
Settings for eno1:
	Supported ports: [ TP	 MII ]
	Supported link modes:   10baseT/Half 10baseT/Full
	                        100baseT/Half 100baseT/Full
	                        1000baseT/Full
	Supported pause frame use: Symmetric Receive-only
	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: Symmetric Receive-only
	Advertised auto-negotiation: Yes
	Advertised FEC modes: Not reported
	Speed: Unknown!
	Duplex: Unknown! (255)
	Auto-negotiation: on
	master-slave cfg: preferred slave
	master-slave status: unknown
	Port: Twisted Pair
	PHYAD: 0
	Transceiver: external
	MDI-X: Unknown
	Supports Wake-on: pumbg
	Wake-on: d
	Link detected: no

# ethtool docker0
Settings for docker0:
	Supported ports: [  ]
	Supported link modes:   Not reported
	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: Unknown! (255)
	Auto-negotiation: off
	Port: Other
	PHYAD: 0
	Transceiver: internal
	Link detected: yes

# ethtool lo
Settings for lo:
	Link detected: yes

其中全双工、半双工、自动协商的区别如下:

  • Full duplex : Enables sending and receiving of packets at the same time. This mode is used when the ethernet device is connected to a switch(交换机).
  • Half duplex : Enables either sending or receiving of packets at a single point of time. This mode is used when the ethernet device is connected to a hub(集线器).
  • Auto-negotiation : If enabled, the ethernet device itself decides whether to use either full duplex or half duplex based on the network the ethernet device attached to.

1.1.2 改变网卡属性

1.1.2.1 Auto-negotiation

上文展示的 Auto-negotiation 为 true,可通过 -s autoneg 关闭它。

# ifdown eth0
    eth0      device: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
    eth0      configuration: eth-bus-pci-0000:0b:00.0

# ethtool -s eth0 autoneg off # -s 指定网卡名称, 设置 autoneg = off

# ethtool eno1
Settings for eno1:
	Supported ports: [ TP	 MII ]
	Supported link modes:   10baseT/Half 10baseT/Full
	                        100baseT/Half 100baseT/Full
	                        1000baseT/Full
	。。。
	Auto-negotiation: off # 此处信息已变为 off
	Link detected: down # 此处信息已变为 down

# ifup eno1
1.1.2.2 Speed

改变网卡速度,注意不要设置超过网卡的 limited capacity

# ethtool eth0 | grep Speed
	Speed: 1000Mb/s

# ethtool -s eth0 speed 100 autoneg off

# ethtool eth0 | grep Speed
	Speed: Unknown! (65535) # 注意:如果网卡在 online 时,被改了 speed 则会自动变为 offline,此时需要手动 ifup

# ifup eth0
    eth0      device: Broadcom Corporation NetXtreme II BCM5709 Gigabit Ethernet (rev 20)
    eth0      configuration: eth-bus-pci-0000:0b:00.0
	Checking for network time protocol daemon (NTPD):                     running

# ethtool eth0 | grep Speed
	Speed: 100Mb/s

# 可看到设置后从 1000Mb/s 变为 100Mb/s

可通过 ifconfig 设置 MTU

1.1.3 展示网卡驱动设置

# ethtool  -i eno1
driver: r8169
version: 5.19.1-051901-generic
firmware-version: rtl8168h-2_0.0.2 02/26/15
expansion-rom-version:
bus-info: 0000:59:00.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: yes
supports-priv-flags: no

1.1.4 只展示 Auto-negotiation, RX and TX

# ethtool -a eno1
Pause parameters for eno1:
Autonegotiate:	on
RX:		off
TX:		off

# 参数含义如下:
-a --show-pause
        Queries the specified Ethernet device for pause parameter information.

1.1.5 展示统计

# ethtool -S eno1
NIC statistics:
     tx_packets: 6199
     rx_packets: 16548
     tx_errors: 0
     rx_errors: 1
     rx_missed: 0
     align_errors: 0
     tx_single_collisions: 0
     tx_multi_collisions: 0
     unicast: 4228
     broadcast: 10859
     multicast: 1461
     tx_aborted: 0
     tx_underrun: 0

1.1.7 排除网络故障

连接成功后,我们期望 Speed 是明确的值,Duplex 是 Full/Half,Link detection 是 Yes。如果不是(如Speed、Duplex 为 Unknow 时,Link detection 为 No 时),可能交换机或网络设置有问题。

此时可以用 tcpdump 抓包分析。

1.1.8 通过网口的 LED 区分网卡

如果机器有很多网口,设置后,对应的网口即会亮灯,即可区分对应关系

ethtool -p eth0

# 参数含义如下:
       -p --identify
              Initiates adapter-specific action intended to enable an operator to easily identify the adapter by sight.  Typically this involves blinking one or more LEDs on the specific network port.
              启动特定于适配器的操作,以使操作员能够轻松地通过视觉识别适配器。这通常涉及闪烁特定网络端口上的一个或多个LED。

           [N]   Length of time to perform phys-id, in seconds.

1.1.9 持久化配置(无需 reboot)

通过 ethtool 设置后,reboot 仍会恢复为设置前的状态。但可通过写配置文件的方式来持久化。

  • ubuntu 设置如下:在 /etc/network/interfaces 配置则会持久化。
# vim /etc/network/interfaces
post-up ethtool -s eno1 speed 1000 duplex full autoneg off # 此行应为本文件的最后一行
  • SUSE 设置如下:
    modify the /etc/sysconfig/network/ifcfg-eth-id file and include a new script using POST_UP_SCRIPT variable as shown below. Include the below line as the last line in the corresponding eth1 adpater config file.
# vim /etc/sysconfig/network/ifcfg-eth-id
POST_UP_SCRIPT='eth1'

Then, create a new file scripts/eth1 as shown below under /etc/sysconfig/network directory. Make sure that the script has execute permission and ensure that the ethtool utility is present under /sbin directory.

# cd /etc/sysconfig/network/

# vim scripts/eth1
#!/bin/bash
/sbin/ethtool -s duplex full speed 100 autoneg off
### 判断计算机网络是否为以太网 要确认某个计算机网络是否属于以太网类型,可以从以下几个方面进行验证: #### 1. 标准化机构 如果该网络遵循由 IEEE 802.3 工作组制定的标准,则可以初步断定其为以太网的一部分[^1]。 #### 2. 物理拓扑结构 最初形式的以太网采用单一总线型物理布局,即所有设备通过一条共享介质相连。这种设计简化了安装并提高了可靠性,因为整个系统中不存在主动电子组件[^2]。 #### 3. 媒介访问控制方式 以太网使用载波监听多址/冲突检测 (CSMA/CD) 协议来管理同一时间只有一个节点发送数据的情况;当两个或更多节点尝试同时传输时会发生冲突,并触发重传机制。 #### 4. 扩展特性 现代以太网可以通过光纤实现远距离连接,或者利用集线器构建更大规模的星形拓扑结构。此外,还可以借助于以太网交换机进一步增强性能,在保持原有优势的同时减少碰撞域大小并支持不同速率之间的互联[^3]。 为了具体测试某张局域网是不是基于以太网技术建立起来的,技术人员通常会查看硬件接口(比如RJ-45端口)、查阅制造商文档以及分析实际运行中的协议栈行为等手段来进行综合评估。 ```bash # 使用命令行工具ethtool检查网络接口详情 $ ethtool eth0 Settings for eth0: Supported ports: [ TP ] Supported link modes: ... Supports auto-negotiation: Yes Advertised link modes: ... Speed: 100Mb/s Duplex: Full Port: Twisted Pair PHYAD: 0 Transceiver: internal Auto-negotiation: on ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

呆呆的猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值