Give Me Liberty or Give Me Eth

The ethtool utility provides ethernet card information and management to die for.

Do you think you have a network bottleneck that’s somehow related to your NIC’s speed or other settings? If so, ethtool might be the utility that will save the day and many painful conversations. Ethtool is a privileged user only (root), powerful system tool that allows you to query and change settings for your system’s ethernet cards. Using it, you can change almost every aspect of a supported card; from the basic to the esoteric.

The Basics

If ethtool didn’t ship with your distribution, pick it up at: Ethtool’s Sourceforge Site. Whether it comes installed on your distribution or you have to install it from source, you’ll find ethtool a valuable new tool and will soon wonder how you lived without it. You must have root or sudo access to install and use ethtool, since it alters a system component’s settings.

You can alter the speed, duplex modes, autonegotiation, wake on LAN (WoL) options and perform tests to name a few of the things you can do with ethtool.

Note: Ethtool doesn’t work well with virtual machines, so you’ll have to rely on other system tools or the hypervisor’s settings for your virtualized systems. If you find that you can alter your VM’s ethernet settings using ethtool, you should set it to autonegotiate and leave it as such for the best performance.

What’s My Config?

Ethtool, from a read-only perspective, gives you a quick view of your current settings and allows you to perform some basic tests without changing anything. Before changing any parameter, you should capture the initial settings and redirect them to a file for safe keeping. You might need to refer to it later when you tweak the settings a little too much.

The simplest command to query NIC settings is to issue the ethtool command and reference one of your network interfaces. You can see your currently configured network interfaces via the ifconfig command.

$ /sbin/ifconfig
eth0      Link encap:Ethernet  HWaddr 00:50:04:64:E4:49
          inet addr:192.168.1.250  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::250:4ff:fe64:e449/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1178424 errors:408 dropped:0 overruns:0 frame:413
          TX packets:305258 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:154186213 (147.0 MiB)  TX bytes:142713819 (136.1 MiB)
          Interrupt:233

eth0:1    Link encap:Ethernet  HWaddr 00:50:04:64:E4:49
          inet addr:192.168.1.245  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:233

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:159 errors:0 dropped:0 overruns:0 frame:0
          TX packets:159 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:207879 (203.0 KiB)  TX bytes:207879 (203.0 KiB)

As you can see, eth0 is the primary network interface on this system. To check its statistics, use the following command.

$ sudo /usr/sbin/ethtool eth0
Settings for eth0:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Advertised auto-negotiation: Yes
        Speed: 100Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 24
        Transceiver: internal
        Auto-negotiation: on
        Current message level: 0x00000001 (1)
        Link detected: yes

These are the default settings for this system’s primary NIC. Currently the NIC is set to 100Mb/s full duplex and it is connected. You can also view virtual interfaces, such as the one shown from the ifconfig.

$ sudo /sbin/ethtool eth0:1
Settings for eth0:1:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Advertised auto-negotiation: Yes
        Speed: 100Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 24
        Transceiver: internal
        Auto-negotiation: on
        Current message level: 0x00000001 (1)
        Link detected: yes

Ethtool allows you to test certain supported NIC hardware. Here’s an example of such a test.

 $ sudo /sbin/ethtool -t eth0
The test result is PASS
Register test  (offline).......... Passed
EEPROM test    (offline).......... Passed
Interrupt test (offline).......... Passed
Loopback test  (offline).......... Passed
Link test   (on/offline).......... Passed

Be warned that running such a test might knock your NIC offline and cause you to have to connect to the console to reset the NIC manually. And, here’s an example of what you’ll see if NIC testing isn’t supported.

$ sudo /sbin/ethtool -t eth0
Cannot test: Operation not supported

Would you like to know more about your NIC driver? This is helpful when you don’t have local access to the system in question.

$ sudo /sbin/ethtool -i eth0
driver: 3c59x
version:
firmware-version:
bus-info: 0000:01:06.0

To see NIC statistics, for supported NICs, use:

$ sudo /sbin/ethtool -S eth0

NIC statistics:
     tx_deferred: 0
     tx_max_collisions: 0
     tx_multiple_collisions: 0
     tx_single_collisions: 0
     rx_bad_ssd: 735192

This NIC isn’t fully supported by ethtool.

Ethtool has a few other options for dumping information from an EEPROM or the register if your NIC is supported. Now let’s take a look at NIC settings that you can change.

Making Changes

Unless you have some compelling reason to set your NIC to a specific speed, autonegotiate is the preferred setting in most cases. But, knowing that there are always exceptions to accepted practices, let’s look at the parameters that you can change.

Anytime you set a specific speed for your NIC, you have to disable autonegotiation and then set the speed. Fortunately, you can do this with a single command. Set the NIC to 100Mb full duplex.

$ sudo /sbin/ethtool -s eth0 autoneg off speed 100 duplex full

$ sudo /usr/sbin/ethtool eth0
Settings for eth0:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Advertised auto-negotiation: No
        Speed: 100Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 24
        Transceiver: internal
        Auto-negotiation: off
        Current message level: 0x00000001 (1)
        Link detected: yes

That’s for a physical NIC. You can also set speeds for virtual NICs.

$ sudo /sbin/ethtool -s eth0:1 autoneg off speed 10 duplex full

$ sudo /usr/sbin/ethtool eth0:1
Settings for eth0:1:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Advertised auto-negotiation: No
        Speed: 10Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 24
        Transceiver: internal
        Auto-negotiation: off
        Current message level: 0x00000001 (1)
        Link detected: yes

One thing to note when looking at your NIC information is that the supported speeds and modes are shown. You couldn’t, for example, set this NIC to 1000 full. If you attempt to set a NIC with incompatible settings, you’ll receive the following message:

$ sudo /usr/sbin/ethtool -s eth0:1 autoneg off speed 1000 duplex full
Cannot set new settings: Invalid argument
  not setting speed
  not setting duplex
  not setting autoneg

If you ever find yourself in trouble with a NIC setting, you can connect to the system’s console and issue the autonegotiate setting by itself to reset the NIC.

$ sudo /usr/sbin/ethtool -s eth0:1 autoneg on

$ sudo /usr/sbin/ethtool eth0:1
Settings for eth0:1:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
        Advertised auto-negotiation: Yes
        Speed: 100Mb/s
        Duplex: Full
        Port: MII
        PHYAD: 24
        Transceiver: internal
        Auto-negotiation: on
        Current message level: 0x00000001 (1)
        Link detected: yes

This introduction to ethtool gives you a bit of insight into this powerful system tool. System administrators appreciate good tools like ethtool and a we’d like to send a special thanks to David Miller for its creation and to Jeff Garzik, Tim Hockin, Jakub Jelinek, Andre Majorel, Eli Kupermann, Scott Feldman, Andi Kleen for modifications. Godspeed fellow system administrators, full duplex ahead.

Next week, you’ll go rollin’ rollin’ rollin’ with logs.

Fatal error: Call to undefined function aa_author_bios() in /opt/apache/dms/b2b/linux-mag.com/site/www/htdocs/wp-content/themes/linuxmag/single.php on line 62