[Computer Network] 10. ethtool

insert image description here

1. 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 documentation
reference

1.1 Common operations

1.1.1 Display device properties

# 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

The differences between full-duplex, half-duplex and auto-negotiation are as follows:

  • 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 Change network card properties

1.1.2.1 Auto-negotiation

The Auto-negotiation shown above is true, it can be turned off by -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

Change the speed of the network card, be careful not to set more than the limited capacity of the network card

# 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

MTU can be set by ifconfig

1.1.3 Display network card driver settings

# 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 Only show 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 Display statistics

# 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 Troubleshooting the Network

After a successful connection, we expect Speed ​​to be a clear value, Duplex to be Full/Half, and Link detection to be Yes. If not (for example, when Speed ​​and Duplex are Unknown, and Link detection is No), there may be problems with the switch or network settings.

At this time, you can use tcpdump to capture and analyze the packets.

1.1.8 Distinguish the network card through the LED of the network port

If the machine has many network ports, after setting, the corresponding network port will light up to distinguish the corresponding relationship

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 Persistent configuration (no reboot required)

After setting through ethtool, reboot will still restore to the state before setting. But it can be persisted by writing configuration files.

  • The ubuntu settings are as follows: the configuration in /etc/network/interfaces will be persistent.
# 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

Guess you like

Origin blog.csdn.net/jiaoyangwm/article/details/131995949