Managing your network interface with ethtool
NIC Check
If ping won't solve your network configuration issues, try ethtool, a powerful utility that lets you manage configuration settings for your network interface card.
The sheer volume of traffic on a super-busy and ever-changing production network makes any oddities very tricky to diagnose. Many of the more serious networking headaches are devastatingly disruptive to business operations. Additionally, the constantly changing nature of busy networks, coupled with the 24/7 attacks of varying competency, mean you need to know your stuff and maintain eagle-eyed diligence in order to catch issues.
If you're like me, though, you probably try to solve these kinds of issues in a simple and elegant way. To alter the network settings on a NIC (Network Interface Card), you have almost certainly used the now deprecated ifconfig
command and its successor the ip
command.
Another useful utility you can use to troubleshoot network problems is ethtool
. The malleable ethtool isn't concerned with IP addresses, VLANs, and subnets. Instead, ethtool lets you manage and configure software drivers and hardware settings that control network interfaces.
If you want to know what the main network interface, eth0
, is up to at this moment, you can enter the following command as root:
ethtool eth0
The output is shown in Listing 1.
Listing 1
Standard Info for etho
As you can see, the output in Listing 1 provides information on the network configuration, including the speed of the network card, as well as details such as the MDI-X
setting, which allows a network interface to figure out if a "straight-through" or "crossover" cable might be necessary to complete the connection.
Probably of greatest benefit of the information presented in Listing 1 is that you can determine the network card settings without breaking a sweat. The following facts are quite useful for understanding the network connection:
Speed: 10000Mb/s Duplex: Full Auto-negotiation: off Link detected: yes
Note that this system is managing to speak to the next device in the chain at a massive 10Gb/s. That device might be some kind of networking kit, such as a switch.
This super-fast speed occurs simultaneously in both directions because it's a full-duplex link, which is just what I'm looking for to achieve the highest data transfers speed possible on the NIC. Finally, the link is detected as being up
, and the settings are forced onto the card, rather than acquired through the occasionally-problematic auto-negotiation.
Changes
In addition to telling you what the NIC is doing, ethtool also lets you change the configuration settings. If you want to make sure your precious primary interface doesn't try to connect to the upstream switch using auto-negotiation, enter the following:
# ethtool -s eth0 autoneg off
The -s
option specifies that you're making a change. In case it's a stumbling block in the future, the -s
switch is needed to apply any new settings that you make, so feel free to use it readily (but with care). The other parts of the command should be self-explanatory.
The capitalized version of the -s
option, the uppercase -S
, is nothing like its baby brother and is used to request some exceptionally useful statistics.
Listing 2 shows the abbreviated output of the ethtool -S
command ( the full output is actually about two thirds longer). The statistics shown in Listing 2 are invaluable when troubleshooting a malfunctioning NIC. I've even created a cron
job just to email these verbose statistics to me on a daily basis. That way, when I'm doing my preflight checks in the morning, I can scan the error sections for peace of mind that a change I made previously is working as expected.
Listing 2
Abbreviated -S Statistics Request
The most common use of ethtool is to alter the speed and duplex of a network interface. Imagine the scenario where your 100Mbps NIC is causing all sorts of reliability issues and you desperately need it to continue working, even if that means working more slowly. One thing to try is to switch off auto-negotiation, but you can also consider forcing the link speed to much slower by dropping it all the way down to 10Mbps:
# ethtool -s eth0 speed 10 autoneg off
Or, throw duplex preference into the mix:
# ethtool -s eth0 speed 10 duplex half autoneg off
This command slows the link down to its minimum and also disables auto-negotiation, giving a better chance for some form of connectivity, even if it is much slower.
If you can access the machine out-of-band (dial-up through "mgetty," for instance, is perfectly suitable for this kind of test), try a few settings and revert them quickly if they prove to be unsuitable. This type of troubleshooting is often the fastest approach if you are debugging the NIC for a server located many miles away in a data center.
Persistence
The examples I've described so far are not persistent changes and will disappear following a reboot.
On RHEL and its associative flavors, you can add a line to the end of your networking config file (which is /etc/sysconfig/network-scripts/ifcfg-eth0
for the eth0
interface):
ETHTOOL_OPTS="speed 10 duplex half autoneg off"
You could then (carefully, to avoid being locked out) stop and start your NIC (preferably by using /etc/init.d/network restart
or service network restart
in the first instance) with a natty little command such as:
# ifdown eth0 && ifup eth0
You can achieve a similar result on Debian-based systems, although it's a pretty nasty hack that's about as graceful as an elephant high-diving into a swimming pool full of custard.
Append the following lines into the long-serving Unix-like hidden file /etc/rc.local
, and your NIC settings should survive a reboot. Obviously, you can adjust them to your needs.
ethtool -s eth0 autoneg off ethtool -s eth0 speed 10 ethtool -s eth0 duplex half
With different versions, your mileage may well vary, so be prepared for some potential head-scratching.
Another approach is to write a custom init
script that will run at boot time (and then adjust it as needed when you upgrade to a systemd
-based version). Also, a more suitable way might be to insert the config into the file /etc/network/interfaces
.
Once you've found the section where the pertinent NIC is mentioned (I'll stick with the trusty eth0
), you can append the pre-up
line, as shown below, adjusting it as needed:
auto eth0 iface eth0 inet static pre-up /sbin/ethtool -s eth0 speed 10 duplex half autoneg off
In the worst case, you could always use the nasty /etc/rc.local
fix, which has been a bone of contention since time immemorial. If there were version headaches, I would cobble together a simple init
script instead, which is only one rung higher up on the laziness ladder.
More Options
I've barely scratched the surface of the useful reporting that the excellent ethtool can offer. My favorite part about ethtool is you can easily combine the output into a script in order to display the current status of a network card. I can imagine some of these configurable settings also being easily changeable within a web interface, along the lines of GUIs, such as Webmin, for example. Listing 3 shows ethtool with the -i
switch, which reveals driver details for the NIC.
Listing 3
Viewing NIC Driver Details
You can use ethtool for lots of other configuration changes. The Fedora documentation provides a useful summary of some of the most important options [2].
The Fedora page offers a useful setting for how to quickly change your MAC address; ethtool refers to this type of address as a physical address and uses the following syntax:
--phyad HEX-VALUE devname
Simply replace HEX-VALUE
with a hexadecimal MAC address like 00:20:12:1a:9f:de
and replace devname
with eth0
.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.