Fun with ethtool

Time to be honest here for a minute. The open source community really has outdone themselves coming up with some very obscure names for packages. Let's take this list of packages for instance: emacs, gimp, gcc, mutt, grub, kyle rankin, parted, tar, mutt, vim. Nine times out of ten, a common person is going to look at that list and become utterly confused over what package does what. That's just the beauty (and beast) of naming software in the open source community. But every so often a tool comes across my screen with such a blatantly obvious name that I just have to run a 'man' to make sure my eyes are not deceiving me. In this case, it's ethtool. Yes, a simple name, for such a powerful utility. The name itself tells you what it does, an Ethernet Tool. Tada! That's it, ethernet tool.

What Ethtool does is allows you to modify your Ethernet adapter settings inside of Linux. What I'll be writing about today isn't the nitty gritty of ethernet adaptors (coalesce, setting rings, register dumping, etc). But what I will address are some really nifty tips and tricks I have learned over the last decade or so.

So without further adieu, let's get started. First things first we need to determine what Ethernet adaptor you are using.

 ifconfig 

Keep in mind though, ethtool will only work against physical ethernet adapters. This means that bond0, tun0, and any other network device that is not a physical network device will not work with ethtool.

Now that you know your device, lets have some fun, shall we? Note: Most linux kernels mark ethernet devices as ethX, where X is the # (starting at 0) of the physical Ethernet interface.

Driver Information and Statistics

I know I know, start with the least used things first. But hey, someone might find this useful, right? I've probably had to query driver information a dozen times in 10+ years when dealing with kernel level issues, but someone is bound to run across this at some point in their life, and let me tell you, it can be easier to just run a single command, than digging through lsmod and hoping that a module picked up the driver properly.

 ethtool -i ethX 
Example output:

driver: r8169 
version: 2.3LK-NAPI 
firmware-version:
bus-info:0000:02:00.0 

Gathering statistics can also be useful for troubleshooting rx/tx issues with your network card. By running the following command you will get statistics about your network card.

 ethtool -S ethX 
 
	NIC statistics:
     tx_packets: 148683 
     rx_packets: 179489 
     tx_errors: 0 
     rx_errors: 0 
     rx_missed: 0 
     align_errors: 0 
     tx_single_collisions: 0 
     tx_multi_collisions: 0 
     unicast: 116884 
     broadcast: 25361 
     multicast: 61674 
     tx_aborted: 0 
     tx_underrun: 0

From here you can see a list of transmitted, received and errored packets. This can be useful during network troubleshooting, combined with other network utilities such as tcpdump.

Tracing your Card

I'm sure this has happened to many of you, as I know it has happened to me. Ever had a server with more than 2 network cards? Raise your hand. Ever had more than two? Ever had to trace what physical network card was recorded in linux as ethX? Sure, you could do it the hard way: grab the MAC address off of ifconfig, plug all the cables into a managed switch and then dump the tables on the switch to find what MAC address goes where. Or, follow the blinking lights with ethtool. This one little switch has saved my bacon countless times, especially when setting up firewall/router appliances.

ethtool -p ethX [N] *where [N] is Number of seconds to blink. ethtool -p eth0 15 Blink ethernet device 0 for 15 seconds

Look there! Blinking lights at the back of your ethernet adaptor. No need to hunt and peck to figure out what eth0 and eth1 is on your physical adaptor. 'ZO RELAXEN UND WATSCHEN DER BLINKENLICHTEN.'

Testing your Ethernet Adapter

Now, this is one that I haven't had to use before, as it's been a rare day that an Ethernet adapter has gone out on me. But nonetheless, this is still a useful switch to have in the sys admin's bag of tricks. This will run some basic tests against your hardware ethernet interface. There are two options with this test, an online test (tests nvram and a link test) and an offline test (register, memory, loopback, interrupt). The offline test will more than likely boot your ethernet connection offline during testing, so be aware of this if you are running this against a production server or a machine that you only have remote access to.

 ethtool -t ethX [offline|online] 
*Note some Ethernet devices don't support online or offline test. During this blog post I found 4 NIC's that didn't support testing, but a half dozen of them that did.
The test result is PASS 
The test extra info: 
nvram test     (online)          0 
link test      (online)          0 
register test  (offline)         0 
memory test    (offline)         0 
loopback test  (offline)         0 
interrupt test (offline)         0 
Changing Ethernet Settings - If you run ethtool ethX without a switch, you will get the settings for your ethernet device as such:
 Settings for eth0:
	Supported ports: [ TP MII ] 
	Supported link modes:   10baseT/Half
				10baseT/Full 100baseT/Half 100baseT/Full
				1000baseT/Half 1000baseT/Full
	Supports auto-negotiation: Yes 
	Advertised link modes:  10baseT/Half
				10baseT/Full 100baseT/Half 100baseT/Full
				1000baseT/Half 1000baseT/Full
	Advertised pause frame use: No 
	Advertised auto-negotiation: Yes Link
	partner advertised link modes:	10baseT/Half 10baseT/Full
                         	        100baseT/Half 100baseT/Full
	Link partner advertised pause frame use: No 
	Link partner advertised auto-negotiation: Yes 
	Speed: 100Mb/s Duplex: Full 
	Port: MII 
	PHYAD:0
	Transceiver: internal 
	Auto-negotiation: on 
	Supports Wake-on: pumbg
	Wake-on: g 
	Current message level: 0x00000033 (51) 
	Link detected: yes

This is a lot to process, but granted ethtool just prints it out line by line, sucking up as much space as it can. It can be summed up as such: Device supports TP and MII, up to 1000baseT/Full, Auto-Negotiation. Partner (Switch) support up to 100baseT/Full, and auto negotiation. Actual settings of device: 100Mb/s, Full Duplex, Running MII, Physical Address 0, Set to Auto negotiation, WoL is enabled and link is detected. Of course there are some more parts, but these are pretty much the juicy tidbits that you need to know.

When I have a device that is acting up, I tend to run: ethtool ethX, check the Supported link modes, the Link partner advertised link modes and the actual speed and Duplex. If my Supported link mode is set low (say 10/Half for some reason) but my switch supports 1000baseT/Full then I'll use ethtool -s ethX to change my ethernet settings to 1000baseT/Full. Just about anything you see from: ethtool ethX, can be changed with ethtool -S ethX. In this case you would use the following:

ethtool -S eth0 speed 1000 duplex full autoneg on

Note: I set autoneg on just in case. The device should have auto negotiated properly when powered up, but it didn't. So for my own sanity I tend to just set auto-negotiation on.

What you can also do with this switch is set Wake-On-Lan. I won't be getting into Wake-On-Lan today as I have heavily documented it in a personal blogpost located at www.jaysonbroughton.com.

Conclusion

I hope by know you have figured out that this is just a basic introduction to ethtool, and not a full course on ethernet standards, as I have left out some information and substituted what I felt was necessary information based on the years that I have been using ethernet utilities. There is so much more that you can use with ethtool, and combined with other such tools this can become one deadly tool in a sys admin's bag of tricks.

______________________

www.jaysonbroughton.com

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

user-defined commands using ethtool

ss's picture

Hi,

Is there a provision to send user-defined commands to the driver using ethtool? For example, if I don't want to use ioctl interface and I want to send a special command to the driver, how could I send it using ethtool?

Thanks,
-SS

set ethernet settings

Siggi's picture

Hi,
Good article. The last command didnt work on my ubuntu box, used ethtool -s instead and when I set speed to 1000 my network connection died. Guess the router doesnt support gigabit connections. Set it back and it worked fine. Thanks for the info.

Nice article.

Anonymous's picture

Nice article.

parted

Anonymous's picture

parted is an obscure name for a partition editor?

Nice article. Didn't know about "-p"

Rafael Varela's picture

Didn't know about -p option. I'll try it on my servers. Thanks for the tip.

Hope it works because it failed in my home computer:


# ethtool -p eth0 15
Cannot identify NIC: Operation not supported


# ethtool -i eth0
driver: r8169
version: 2.3LK-NAPI
firmware-version:
bus-info: 0000:04:00.0

Yea, I noticed some of the

jbroughton's picture

Yea, I noticed some of the machines at the house didn't work with the -p, but some did. I think it had to do with the type of NIC you have installed in your machine. Same thing with testing the nic as I outlined in the article, sometimes it worked and sometimes it didn't. But if you can get it to work at your job, that's a bonus :-) Nothing like having blinking lights to trace ethernet adapters.

Agreed

Rafael Varela's picture

Yes, -p it's a great feature that I'd love to have it working in my servers.

Thanks for your article.

Good Article

Anonymous's picture

Very useful information.I learned new options from this post.Thank you.

The best part of this is that

Anonymous's picture

The best part of this is that I was finally able to find in its entirety one of the funniest signs I have ever seen that was on one of my computer engineering teachers office wall due to a reference in this article...

Cool article!

Angel Lightbringer's picture

This was a really nice piece. I learned of a new tool today, and specially the blinking bit :)

Thanks for this.

Your Welcome

jbroughton's picture

Glad you enjoyed it :-)

Actually ethtool is not

Anonymous's picture

Actually ethtool is not completely useless with bonded interfaces. It can, for example, tell you if the bonded interface link is up (i.e. at least on of the underlying physical links is up) or down (i.e. all the underlying physical links are down).

Bonded interfaces

jbroughton's picture

That's true, you can use it to see bonded interface link. You can also use it to see what ethernet device (eth0 or eth1) is active on the bond with ethtool and what is on standby (with linkup as a response from ethtool). But as far as the utilities that I went over here, testing on bond0 was a no-go. Thanks for bringing that up though :-)

Gooooooood Article

Datta's picture

Gooooooood Article

without further -adieu- ado

Anonymous's picture

without further -adieu- ado

Yes, Ado. My bad ;-) My

jbroughton's picture

Yes, Ado. My bad ;-) My better half is french, and our son is french. I just know I'm going to catch crap for putting Adieu in place of Ado. Silly me, thanks for bringing that one up

Ethtool

Wrigsster's picture

Good article - nice and clear and not too meaty. Thanks for the heads up - much appreciated

Ethtool

Wrigsster's picture

Good article - nice and clear and not too meaty. Thanks for the heads up - much appreciated

ipconfig is obsolete

pcoq's picture

On my Fedora system, man ifconfig says that ipconfig is obsolete and that one should use ip addr and ip link instead.

pcoq, yes you are correct.

jbroughton's picture

pcoq,
yes you are correct. Man's been talking about ifconfig being obsolete since Kernel level 2.0 I believe (and I could be wrong about that as well). If for some reason the newer version of Fedora doesn't let you use ifconfig (should be ifconfig, not ipconfig). Then you can try: 'ip addr show' and that should list your ethernet interfaces.

kyle rankin

metalx2000's picture

kyle rankin! HAHAHA!!!

http://filmsbykris.com/
Everything you ever need to know about Open-Source Software.

Correction

Isaac's picture

I believe that you meant for
"I hope by know you have..."
to be
"I hope by now you have..."

Yup, that is what it should

jbroughton's picture

Yup, that is what it should have said. But the real question is, did you learn something about ethtool that you didn't know before? That's what I get for editing 3x and missing that one. Good eye! ;-)

It was honestly more of a

Isaac's picture

It was honestly more of a refresher for me, as I'm a Linux sysadmin/network admin professionally, but it is well written and should be very handy for those who are newer or don't usually have to deal with this stuff. I got here because saw the article in the LJ RSS feed and decided to check it out.

Believe me, I know how easy it can be to miss an error when you're proofing your own text. Your brain tends to read what you meant to type instead of what is actually there. Good job on the article :)

Intresting article! Btw: Your

Anonymous's picture

Intresting article!

Btw:
Your comment system needs a way to report spam!

logged in users can report

Webmistress's picture

logged in users can report spam.

Katherine Druckman is webmistress at LinuxJournal.com. You might find her on Twitter or at the Southwest Drupal Summit

This was awesome! Didn't know

Anonymous's picture

This was awesome! Didn't know about this before.. now i do ;)

Good to hear! Glad you

jbroughton's picture

Good to hear! Glad you learned something new about Linux :-)

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState