
1. Basic Usage of the ethtool Command
The basic syntax of the ethtool command is as follows:
ethtool (options) <interface>
Here, <interface> refers to the name of the network interface you want to operate on, such as the common eth0, ens33, etc. The (options) are specific functional options that determine what operation you perform on that interface.
2. Common Functional Options Explained
(1) Display Basic Information of the Interface
Simply enter ethtool <interface> to obtain basic information about the network card, such as speed, duplex mode, and auto-negotiation status. For example, to query eth0:
ethtool eth0Settings for eth0: Supported ports: ( TP ) Supported link modes: 10baseT/Half 10baseT/Full Supported pause frame use: Symmetric Supports auto-negotiation: Yes Advertised link modes: 1000baseT/Full Advertised pause frame use: Symmetric Advertised auto-negotiation: Yes Speed: 1000Mb/s Duplex: Full Port: Twisted Pair Transceiver: internal Auto-negotiation: on
From the output, we can clearly see the port type of eth0 (TP, i.e., twisted pair), supported link modes, current speed (1000Mb/s), duplex mode (Full), and auto-negotiation status (enabled), among other key information.
(2) Query Supported Features
To learn about the network card driver-related information, use ethtool -i <interface>. For example, to query eth0:
ethtool -i eth0driver: e1000version: 3.2.6-kfirmware-version: 1.5-0expansion-rom-version: bus-info: 0000:00:03.0supports-statistics: yessupports-test: yessupports-eeprom-access: yessupports-register-dump: yessupports-priv-flags: yes
This displays the driver name (e1000), version number, firmware version, bus information, and whether the network card supports statistics queries, tests, EEPROM access, register dumps, and private flags.
(3) Display Statistics Information
By using ethtool -S <interface>, you can query the device’s statistics information, such as packet counts and error counts, which is very helpful for network troubleshooting. Executing ethtool -S eth0, the output example is as follows:
NIC statistics: rx_packets: 100000 tx_packets: 98000 rx_bytes: 8000000 tx_bytes: 7600000 rx_errors: 5
From this data, we can intuitively understand the number of packets and bytes received and sent by eth0, as well as the number of errors that occurred during reception.
(4) Modify Network Card Speed and Duplex Mode
If you need to adjust the network card’s speed, duplex mode, and whether to enable auto-negotiation, you can use the command ethtool -s <interface> speed <speed> duplex <mode> autoneg <on|off>.
<speed>: Specify the speed, options include 10, 100, 1000, etc., in Mbps.
<mode>: Duplex mode, full indicates full duplex, half indicates half duplex.
autoneg: Determines whether to enable auto-negotiation, on for enabling, off for disabling.
For example, to set eth0 to a speed of 100Mbps, full duplex mode, and disable auto-negotiation, the command is as follows:
ethtool -s eth0 speed 100 duplex full autoneg off
However, be aware that modifying these settings may cause network interruptions, so proceed with caution. Also, ensure that both the network card and switch support the parameters you set, or network anomalies may occur.
(5) Get Current Message Level of the Network Card
Using ethtool -g <interface>, you can display the sizes of the receive and transmit buffers supported by the network card. For example, executing
ethtool -g eth0: Ring parameters for eth0:Pre-set maximums:RX: 4096TX: 4096Current hardware settings:RX: 256TX: 256
From the output, we can see that the preset maximum sizes for the receive and transmit buffers of eth0 are both 4096, while the current hardware settings show sizes of 256.
(6) Set Receive and Transmit Queue Sizes of the Network Card
If you want to modify the sizes of the receive and transmit buffers of the network card, use ethtool -G <interface> rx <value> tx <value>. For example, to set the receive buffer size of eth0 to 512 and the transmit buffer size also to 512, the command is as follows:
ethtool -G eth0 rx 512 tx 512
Reasonable adjustment of buffer sizes helps optimize network performance, especially in high-load network environments.
(7) Set Wake-on-LAN (WOL) Functionality
By using ethtool -s <interface> wol <options>, you can enable or disable Wake-on-LAN functionality, allowing the computer to be awakened over the network even when it is powered off.
p: Supports wake-up based on Magic Packet.
u: Supports wake-up based on unverified Magic Packet.
g: Supports broadcast wake-up.
For example, to enable broadcast wake-up functionality for eth0, the command is:
ethtool -s eth0 wol g
If you want to query the current WOL settings, execute ethtool eth0, and the output will show Wake-on: g, indicating that the current WOL functionality of eth0 is based on broadcast wake-up.
(8) Adjust the Message Level of the Network Card
ethtool -s <interface> msglvl <value> is used to set the log output level of the network card driver, facilitating debugging work. However, it is important to set an appropriate message level; too high may generate a large number of logs, consuming excessive system resources; too low may not provide enough debugging information.
(9) Set Packet Offload Features
Using ethtool -k <interface> you can view the offload status, and ethtool -K <interface> feature on|off is used to set offload features. Hardware offload features of the network card, such as TCP checksum offload or segmentation offload (TSO), can reduce CPU load and improve network processing performance.
To query the offload features of eth0, execute ethtool -k eth0:
Features for eth0: rx-checksumming: on tx-checksumming: on scatter-gather: on tcp-segmentation-offload: off
From the results, we can see that eth0 currently has receive checksum, transmit checksum, and scatter-gather features enabled, but TCP segmentation offload (TSO) is disabled. To disable TCP segmentation offload (TSO) for eth0, the command is:
ethtool -K eth0 tso off
(10) Test Network Card Functionality
ethtool -t <interface> (offline|online) can run online or offline self-tests of the network card, but this requires support from the network card driver. This feature is very useful when troubleshooting hardware faults of the network card.
(11) Query Network Card EEPROM Information
By using ethtool -e <interface>, you can display the contents of the EEPROM. However, some network cards may require administrative privileges to perform this operation. The EEPROM stores some important configuration information of the network card, and viewing this information helps to gain deeper insights into the characteristics and status of the network card.
(12) View Network Card Register Dump
Using ethtool -d <interface>, you can display the contents of the network card’s registers, which is mainly used for hardware debugging. Register information is very valuable for professional hardware engineers or those deeply researching the underlying principles of network devices.
3. Comprehensive Examples
(1) Comprehensive View of Network Card Status
If you want to fully understand all functions and statuses of the network card eth0, you can sequentially execute the following commands:
ethtool eth0ethtool -S eth0ethtool -k eth0ethtool -i eth0
These commands query eth0 in detail from multiple dimensions, including basic information, statistics, offload features, and driver information, allowing you to have a comprehensive understanding of the network card’s status.
(2) Modify Multiple Parameters of the Network Card
Suppose you want to set the speed of eth0 to 1000Mbps, full duplex mode, enable auto-negotiation, while disabling TCP segmentation offload and receive checksum functionality, you can follow these steps:
ethtool -s eth0 speed 1000 duplex full autoneg onethtool -K eth0 tso off rx-checksumming off
With these two commands, you have modified multiple parameters of the network card to meet specific network configuration requirements.
(3) Adjust Buffer Sizes
Set the receive buffer size of eth0 to 1024 and the transmit buffer size to 512, the command is as follows:
ethtool -G eth0 rx 1024 tx 512
Reasonable adjustment of buffer sizes can optimize the data processing capability of the network card based on actual network traffic conditions, improving network performance.
Previous Recommendations:
[Linux Learning] Three Steps to Mount a USB Drive on a Server
[Linux Learning] Performance Optimization, Detailed Explanation of the iostat Command
[Linux Learning] CentOS 7/8 Firewall Configuration Tutorial~1
[Linux Learning] Ubuntu Firewall Configuration Tutorial
[Linux Learning] Disk Partitioning: fdisk or parted?
[Linux Learning] Unable to Access System, What is journalctl -xb?
[Linux Learning] Load Monitoring Commands: top, vmstat, iostat Explained
[Linux Learning] Forgot CentOS 7.8 Password!
[Linux Learning] Detailed Guide to Configuring bond1 on CentOS 7