In this article, we’ll be looking at the ethtool command in Linux. Specifically, we’ll demonstrate the tool’s capability through the commands it offers.
The ethtool usually comes with any distribution of Linux. But if it’s missing, we can install it with the distro’s package manager. For example, we install with the apt-get command in Debian-based Linux:
$ sudo apt-get install -y ethtool
Then, we run the command with –version to verify the installation:
$ sudo ethtool --version ethtool version 5.16
If the version is displayed without any errors, we’ve successfully installed the ethtool in our Linux.
3. Querying Network Interface Device
Some of the subcommands and options offered by the ethtool can be categorized as querying commands. It extracts and reports information related to the network interface device or its driver.
3.1. Obtaining Network Interface Device Properties
To get the general properties of a network interface device, we simply run ethtool followed by its name:
$ sudo ethtool enp0s3 Settings for enp0s3: 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 Port: Twisted Pair PHYAD: 0 Transceiver: internal Auto-negotiation: on MDI-X: off (auto) Supports Wake-on: umbg Wake-on: d Current message level: 0x00000007 (7) drv probe link Link detected: yes
In the command above, we use ethtool to obtain the device properties of the enp0s3 network interface. From the output, we see that it shows the device’s speed, duplexity, and supported link modes, among other properties. Additionally, we can quickly verify our interface is connected by ensuring the “Link detected” is yes.
As a little experiment, we can unplug the cable from the network interface, and we should see that it will now show “Link detected: false” when we rerun the same command.
3.2. Obtaining Device’s Driver Properties
The ethtool command could also report the device’s driver properties with the –driver option:
$ sudo ethtool --driver enp0s3 driver: e1000 version: 5.13.0-48-generic firmware-version: expansion-rom-version: bus-info: 0000:00:03.0 supports-statistics: yes supports-test: yes supports-eeprom-access: yes supports-register-dump: yes supports-priv-flags: no
From the output, we can see the device’s driver name as well as its version. Additionally, it also tells us whether it supports some of the features we would expect, such as statistics collection, tests, and others.
3.3. Obtaining Device Statistics
Most of the network interface devices collect statistics. For example, it records how many packets have been transmitted and received. To retrieve these statistics, we can invoke ethtool with the –statistics option:
$ sudo ethtool --statistics enp0s3 NIC statistics: rx_packets: 353208 tx_packets: 60115 rx_bytes: 515998054 tx_bytes: 3951578 rx_broadcast: 0 tx_broadcast: 10 rx_multicast: 0 tx_multicast: 126 rx_errors: 0 tx_errors: 0 tx_dropped: 0 multicast: 0 ...(more statistics)
The statistics we can obtain from this command are device-specific. But at the minimum, we’ll always get the basic statistics like packet received and transmitted (rx_packets and tx_packets), bytes received and transmitted (rx_bytes and tx_bytes), and dropped packets.
4. The Ethernet PAUSE Parameters
In Ethernet, the PAUSE frame mechanism is a way to relieve traffic congestion during transfer. When one end of the data link cannot catch up, it can send a pause frame to the other end to slow down the transmission rate. The ethtool command offers multiple options that we can use to query and configure the parameters associated with the PAUSE frame mechanism.
4.1. Obtaining the PAUSE Parameters
To obtain the configured PAUSE parameters of a given ethernet device, we use the –show-pause option:
$ sudo ethtool --show-pause enp0s3 Pause parameters for enp0s3: Autonegotiate: on RX: on TX: off
From the console, we can see that the ethernet device enp0s3 has both the RX and Autonegotiation turned on, and TX turned off. Let’s look at how we can modify these parameters.
4.2. Changing PAUSE Parameters
To modify the PAUSE parameters, we use the –pause option followed by the parameter name we want to configure for and its state (on or off). For example, to configure the PAUSE’s auto-negotiation parameter, we specify the autoneg:
$ sudo ethtool --pause enp0s3 autoneg off $ sudo ethtool --pause enp0s3 autoneg on
For the RX parameter, we use the rx argument:
$ sudo ethtool --pause ethtool rx off $ sudo ethtool --pause ethtool rx on
Finally, we use the tx argument for the TX parameter:
$ sudo ethtool --pause enp0s3 tx off $ sudo ethtool --pause enp0s3 tx on
5. Running Self Test on Network Interface Device
For network interface devices that support testing, we can use the –test option of the ethtool to run some tests on the device. The possible modes are offline and online.
The offline mode offers a more comprehensive test, but it might interrupt the working of the device through a reboot. It includes the register test, EEPROM test, interrupts test, loopback test, and link test. For example, to run the offline test on the enp0s3 device:
$ sudo ethtool --test enp0s3 offline
On the other hand, the online mode ensures no interruption to the operation of the device. However, it only performs the link test:
$ sudo ethtool --test enp0s3 online
6. Configuring Other Settings
With ethtool, we can also change settings like speed, duplexity, and toggling auto-negotiation. Concretely, we configure those device settings through the -s option followed by the argument key-value pairs.
For example, we can change the speed of the network interface to 10Mbit/s and set the duplexity to half using the -s option:
$ sudo ethtool -s enp0s3 speed 10 duplex half
The command above sets the enp0s3 device’s speed to 10Mbit/s and its duplexity to half.
Do note that we are only allowed to set the speed according to the supported link modes of the devices. For example, attempting to set the speed to 50Mbit/s using the same command would yield an error:
$ sudo ethtool -s enp0s3 speed 50 duplex half Cannot advertise speed 50 duplex half
Additionally, we can also toggle the state of auto-negotiation of this network interface using the autoneg argument:
$ sudo ethtool -s enp0s3 autoneg off $ sudo ethtool -s enp0s3 autoneg on
In this tutorial, we’ve taken a look at the ethtool command-line tool in Linux. Particularly, we’ve looked at some of the commands to query and configure the network interface device.