Examine Network Interface Settings with ethtool in Linux

CompTIABeginner
Practice Now

Introduction

In this lab, you will learn how to use the ethtool command-line utility to examine and manage network interface settings in a Linux environment. You will start by installing the tool and identifying your primary network interface. Following this, you will practice viewing the current interface speed and duplex mode, manually setting these parameters to a specific configuration like 10Mbps half-duplex, and then reverting the interface back to its default auto-negotiation state.

By completing these steps, you will gain practical skills in diagnosing physical layer network issues. The lab concludes by teaching you how to analyze the supported link modes of your network card, which is essential for troubleshooting potential performance problems caused by speed or duplex mismatches between network devices.

Install ethtool and Identify Your Network Interface

In this step, you will begin by installing ethtool, a crucial command-line utility for examining and modifying network interface controller parameters. After ensuring the tool is available, you will learn how to identify the name of the primary network interface on your system, which is a prerequisite for any further network analysis.

First, let's update the package list and install ethtool. It's a good practice to run apt update before installing new packages to ensure you are getting the latest available versions from the repositories.

Open a terminal, which should already be open in your ~/project directory. Execute the following commands:

sudo apt update
sudo apt install ethtool -y

The -y flag automatically answers "yes" to the installation prompt, making the process non-interactive. You should see output indicating that the package lists are being read and ethtool is being installed.

Now that ethtool is installed, you need to determine which network interface you want to examine. A system can have multiple interfaces, such as a loopback interface (lo), a wired Ethernet interface (eth0 or enp0s3), and others. The ip command is the modern standard for displaying and manipulating network devices, addresses, and routes.

To list all network interfaces and their configurations, use the ip a command (a shorthand for ip addr):

ip a

You will see a list of all network interfaces. Look for an interface that is not lo (the loopback interface) and has a state of UP. This is typically your primary network connection. The name is usually eth0 or a name starting with enp.

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: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:16:3e:01:b1:ae brd ff:ff:ff:ff:ff:ff
    altname enp0s5
    altname ens5
    inet 172.16.50.232/24 metric 100 brd 172.16.50.255 scope global dynamic eth0
       valid_lft 1892159922sec preferred_lft 1892159922sec
    inet6 fe80::216:3eff:fe01:b1ae/64 scope link
       valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:da:5e:55:d4 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever

From the example output above, the primary network interface name is eth0. You may also see other interfaces like docker0, but for this lab, we will focus on eth0. Make a note of your interface name, as you will need it in the following steps. You have now successfully installed the necessary tool and identified your target network interface.

View Current Interface Speed and Duplex with ethtool

In this step, you will use the ethtool utility you just installed to inspect the current operational state of your network interface. Specifically, you will focus on two critical parameters: Speed and Duplex.

Network interface cards (NICs) operate at specific speeds (e.g., 10 Mbps, 100 Mbps, 1000 Mbps) and in one of two duplex modes:

  • Half-duplex: The interface can only send or receive data at a given time, but not both simultaneously.
  • Full-duplex: The interface can send and receive data at the same time, which significantly improves throughput.

Modern networks almost always use a process called auto-negotiation, where the NIC and the connected network device (like a switch) automatically communicate to determine the highest possible speed and duplex mode that both support.

Now, let's view these settings for the network interface you identified in the previous step (we will use eth0 as the example). In your terminal, run the following command. Remember to replace eth0 with your actual interface name if it's different.

ethtool eth0

After pressing Enter, you will see detailed information about the interface. In some virtual environments, you may see many "Not reported" or "Unknown" values, which indicates the virtual network interface has limited features. This is normal for this lab environment.

Settings for eth0:
        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: Unknown!
        Duplex: Unknown! (255)
        Auto-negotiation: off
        Port: Other
        PHYAD: 0
        Transceiver: internal
netlink error: Operation not permitted
        Link detected: yes

Observe the output carefully. The key lines for this step are:

  • Speed: Unknown!: The current speed is not reported by the driver.
  • Duplex: Unknown! (255): The duplex mode is also not reported.
  • Auto-negotiation: off: This is important. It shows that the interface is not set to auto-negotiate, which is why we will be able to set the speed and duplex manually in the next step.
  • netlink error: Operation not permitted: This error is common in containerized or virtual environments with restricted permissions. It will not prevent us from completing the lab.

The Link detected: yes line confirms that a physical connection to the network is active. These settings are fundamental to how the Physical Layer (Layer 1) operates.

Manually Set Interface Speed to 10Mbps Half-Duplex

In this step, you will learn how to manually override the auto-negotiated settings. While auto-negotiation is the standard for modern networks, there are rare situations, such as connecting to older legacy hardware or troubleshooting specific link issues, where you might need to force a particular speed and duplex mode.

Important Note: Manually setting these parameters can cause network connectivity issues if not done correctly. Forcing a setting that doesn't match the device on the other end of the cable (e.g., a switch port) can lead to a duplex mismatch, which severely degrades network performance, or it can cause the link to fail entirely. In this virtual environment, the change should be safe to attempt.

To change the settings, you will use the ethtool command with the -s flag, which stands for "settings". This operation requires administrator privileges, so you must use sudo.

Let's attempt to set the interface speed to 10 Mbps and the duplex mode to half. Remember to replace eth0 with your interface name if it is different.

sudo ethtool -s eth0 speed 10 duplex half

This command does not produce any output on success. To confirm if the change was applied, you must inspect the interface settings again using the command from the previous step:

ethtool eth0

Now, examine the output. Look for the Speed and Duplex lines. Even with the initial errors, you will see that the command to set the speed and duplex was successful.

Settings for eth0:
        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: 10Mb/s
        Duplex: Half
        Auto-negotiation: off
        Port: Other
        PHYAD: 0
        Transceiver: internal
netlink error: Operation not permitted
        Link detected: yes

You should now see Speed: 10Mb/s and Duplex: Half. Notice also that Auto-negotiation is still off, which is expected since you have manually set the parameters. This confirms that you can successfully modify the network interface settings.

View and Modify Offload Features with ethtool -k

In this step, you will learn how to inspect and modify network offload features. These are advanced NIC capabilities that allow the hardware to perform tasks that would otherwise be handled by the CPU, such as calculating checksums or segmenting data. Offloading these tasks can improve network performance.

First, let's view the current offload settings for your interface using the -k (or --show-features) flag.

ethtool -k eth0

You'll see a list of features, some of which are on and some off. A [fixed] status means the setting cannot be changed by the user.

Features for eth0:
rx-checksumming: on [fixed]
tx-checksumming: on
        tx-checksum-ipv4: off [fixed]
        tx-checksum-ip-generic: on
        tx-checksum-ipv6: off [fixed]
        tx-checksum-fcoe-crc: off [fixed]
        tx-checksum-sctp: off [fixed]
scatter-gather: on
        tx-scatter-gather: on
        tx-scatter-gather-fraglist: off [fixed]
tcp-segmentation-offload: on
        tx-tcp-segmentation: on
        tx-tcp-ecn-segmentation: on
        tx-tcp-mangleid-segmentation: off
        tx-tcp6-segmentation: on
generic-segmentation-offload: on
generic-receive-offload: on
large-receive-offload: off [fixed]
... (output is long and may vary)

Now, let's practice modifying one of these settings. We will temporarily disable TX checksumming. This operation requires administrator privileges, so you must use sudo and the -K (or --features) flag.

sudo ethtool -K eth0 tx-checksumming off

The command now reports the changes it made. Notice that disabling tx-checksumming automatically disabled other related features. This is because some features depend on others.

Actual changes:
tx-checksum-ip-generic: off
tx-tcp-segmentation: off [not requested]
tx-tcp-ecn-segmentation: off [not requested]
tx-tcp6-segmentation: off [not requested]

To verify the change in the full list, you can run ethtool -k eth0 again.

Now, let's re-enable it to restore the default, performance-enhancing behavior.

sudo ethtool -K eth0 tx-checksumming on

Again, the output shows the actual changes. You may see that even though you requested a feature on, it remains off if the hardware has it fixed. It also shows related features being re-enabled automatically.

Actual changes:
tx-checksum-ipv4: off [requested on]
tx-checksum-ip-generic: on
tx-checksum-ipv6: off [requested on]
tx-tcp-segmentation: on [not requested]
tx-tcp-ecn-segmentation: on [not requested]
tx-tcp6-segmentation: on [not requested]
tx-checksum-fcoe-crc: off [requested on]
tx-checksum-sctp: off [requested on]

By completing this step, you have learned how to examine and modify the hardware offload features of your network card and have seen how feature dependencies and hardware limitations affect the outcome.

Examine Interface Statistics with ethtool -S

In this final step, you will learn how to view detailed statistics for your network interface. This is one of the most common uses of ethtool for day-to-day network troubleshooting. The tool provides a wealth of information, including the number of packets sent and received, byte counts, and perhaps most importantly, error counts.

To view these statistics, use the -S (or --statistics) flag. Remember to replace eth0 with your interface name.

ethtool -S eth0

The output will be a long list of counters. In this environment, the NIC uses multiple queues, so statistics are reported per queue. Let's focus on the rx_queue_ and tx_queue_ packet counters.

NIC statistics:
     rx_queue_0_packets: 63768
     rx_queue_0_bytes: 93307801
     ...
     rx_queue_1_packets: 77180
     rx_queue_1_bytes: 111222183
     ...
     tx_queue_0_packets: 14363
     tx_queue_0_bytes: 4229599
     ...
     tx_queue_1_packets: 5287
     tx_queue_1_bytes: 1262219
     ... (many other statistics)

Note: Your numbers will be different, as they reflect all traffic since the interface was brought up.

Now, let's generate some network traffic to see these counters change. We will use the ping command to send a few packets to the loopback address (127.0.0.1), which is the local machine itself. The -c 4 flag tells ping to send exactly 4 packets.

ping -c 4 127.0.0.1

You will see output showing the 4 packets being sent and received.

PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.038 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.040 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.039 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.037 ms

--- 127.0.0.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3052ms
rtt min/avg/max/mdev = 0.037/0.038/0.040/0.001 ms

Now that you've generated some traffic, let's check the statistics again:

ethtool -S eth0

Examine the rx_queue_*_packets and tx_queue_*_packets values again.

NIC statistics:
     rx_queue_0_packets: 63879
     ...
     rx_queue_1_packets: 77227
     ...
     tx_queue_0_packets: 14460
     ...
     tx_queue_1_packets: 5328
     ... (many other statistics)

You should see that the total number of packets across the receive and transmit queues has increased. Due to background system activity, the increase may be more than the 4 packets from our ping command, but the change confirms that the interface is sending and receiving data correctly. This is a fundamental technique for verifying link health. If you were troubleshooting a problem and saw error counters increasing, it would be a clear sign of a problem.

Summary

In this lab, you learned how to manage network interface settings using the ethtool utility in Linux. You began by installing the ethtool package and identifying your primary network interface name with the ip a command. Following this, you used ethtool to examine the current operational parameters of the interface and then manually set its speed and duplex mode.

The lab then guided you through exploring more advanced features. You learned how to view and modify hardware offload settings, such as tx-checksumming, using the -k and -K flags. Finally, you learned how to inspect detailed interface statistics with ethtool -S and how to generate traffic with ping to see those statistics change in real-time, providing a practical method for verifying link health and troubleshooting connectivity issues.