nixCraft Poll

Topics

Linux add ethtool duplex settings to a network card permanently

Posted by Vivek Gite [Last updated: July 16, 2007]

I have already written about how to find and change your network interface speed (NIC), duplex or auto negotiate settings on Linux using ehttool command line options.

However, these settings are not permanent. If you reboot the system or if you just
need to upgrade/downgrade your port speed, run the ehtool command once your port change by network administrator. (If you want to read about how to make Windows 2000/2003 server port speed change, read my previous article.)

Changing your Network Interface Speed, Duplex or Auto Negotiate settings on Red Hat Linux

To set the interface speed, duplex or auto negotiation on Linux system boot up (make settings permanent), you need edit /etc/sysconfig/network-scripts/ifcfg-eth0 file for eth0 interface. This file used by Red Hat enterprise Linux, Fedora core, Cent Os etc.

Open the file:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0

Append following line:
ETHTOOL_OPTS="speed 100 duplex full autoneg off"

Save and close the system. It will set the eth0 device to 100Mbs, full duplex, with the auto negotiation off at boot time. You can simply restart the networking (it will disconnect all ssh or ftp session) or restart the server. Depend upon traffic and load it may take upto 1 minute to setup a new port speed:
# /etc/init.d/network restart

If you want 1000Mbs set line as follows:
ETHTOOL_OPTS="speed 1000 duplex full autoneg off"Update: if above command failed to work for 1000Mbps use following command (see below in comment sections for discussion) :ETHTOOL_OPTS="speed 1000 duplex full autoneg on"

Debian or Ubuntu Linux permanent settings

Under Debian or Ubuntu Linux just create a script as follows:
# vi /etc/init.d/100Mbs
OR
$ sudo vi /etc/init.d/100Mbs
Append following lines:
#!/bin/sh
ETHTOOL="/usr/sbin/ethtool"
DEV="eth0"
SPEED="100 duplex full"
case "$1" in
start)
echo -n "Setting eth0 speed 100 duplex full...";
$ETHTOOL -s $DEV speed $SPEED;
echo " done.";;
stop)
;;
esac
exit 0
Save and close the file. Setup executable permission:
# chmod +x /etc/init.d/100MbsOR$ sudo chmod +x /etc/init.d/100Mbs

Now run script when Debian or Ubuntu Linux boots up. Use update-rc.d command install System-V style init script links:# update-rc.d 100Mbs defaultsOR# sudo update-rc.d 100Mbs defaultsOutput:

 Adding system startup for /etc/init.d/100Mbs ...
   /etc/rc0.d/K20100Mbs -> ../init.d/100Mbs
   /etc/rc1.d/K20100Mbs -> ../init.d/100Mbs
   /etc/rc6.d/K20100Mbs -> ../init.d/100Mbs
   /etc/rc2.d/S20100Mbs -> ../init.d/100Mbs
   /etc/rc3.d/S20100Mbs -> ../init.d/100Mbs
   /etc/rc4.d/S20100Mbs -> ../init.d/100Mbs
   /etc/rc5.d/S20100Mbs -> ../init.d/100Mbs

Reboot the system to take effect or just type scrit name:
# /etc/init.d/100Mbs startOR$ sudo /etc/init.d/100Mbs start

See also:

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. Roshan Shariff Says:

    In Debian or Ubuntu, it’s much easier to add a pre-up line to /etc/network/interfaces. Something like this:

    iface eth0 inet static
    pre-up /usr/sbin/ethtool -s $IFACE 10 duplex half
    address ...

  2. nixcraft Says:

    Roshan

    Good tip; my bad I should have thought about it.

    Appreciate your post.

  3. Jon Scobie Says:

    A few weeks ago, I did the same thing in SuSE as the switch in work reports the wrong settings.
    Just add a script in /etc/sysconfig/network/scripts called ethtool-settings (for example) and link to it in /etc/sysconfig/network/if-up.d
    The contents could be something like :-

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

  4. Thomas Edman Says:

    Your example for 1000 speed will not work.
    ETHTOOL_OPTS=”speed 1000 duplex full autoneg off”

    speed 1000 REQUIRES autonegotiate.

    Read up on your ethernet networking fundamentals here:
    http://www.cisco.com/univercd/cc/td/doc/cisintwk/ito_doc/ethernet.htm#wp1020985

  5. nixcraft Says:

    Noop, command is right. I have tested these commands lots of times. I have Intel NIC (e1000 driver) and it works w/o problem.

    ethtool -s ethx autoneg off speed 1000 duplex full

    Changing speed or duplex settings almost may require disabling auto negotiation with \’autoneg off\’. However you may need to turn on autoneg for 1000Mbps; it did work for my Intel card. But failed to work for other make NIC. So try both options.

    Appreciate your post.

  6. anand Says:

    Very thank , i used this.

  7. Stefano Says:

    Hi,
    i added a ethtool option (ETHTOOL_OPTS=”wol g”) in the file /etc/sysconfig/network-scripts/ifcfg-eth0 to have wol automatic enabled, but if i have eth0 configured with dhcp options i can’t get the “wol g” option active. On the contrary if i configure the eth0 nic with static ip address the ethtool option is well set.
    I have a sme-server (CentOS based) and i’m going to be crazy to have wol g enabled with dhcp on… how can i get it to work?
    Thanks,
    Stefano - Italy

  8. Ryan Says:

    I don’t have ethtool on my version of RedHat so the ETHTOOL_OPTS won’t automate the settings for me. How do I automate the mii-tool options in the etc/sysconfig/network-scripts/ifcfg-eth0 file?

  9. vivek Says:

    mii-tool is obsolete and it will be removed from future version or updates. You can easily install ethtool by running any one of the following command:

    yum install ethtool

    or (for rhel 4.x or older )

    up2date -i ethtool

    To automate mii-tool …
    Add mii-tool command to /etc/rc.local with speed, which will run mii-tool on fly after Linux boots up. For eg following will set eth0 to 100Mbps FD

    mii-tool -F 100baseTx-FD

    HTH

  10. Ryan Says:

    Thanx so much Vivek I already added the command to rc.local I was just wondering if there was another method. I’ll definitely upgrade to ethtool.

  11. Hema Says:

    simply superb

  12. Joe Says:

    If you’re unable to permanently set the wol option:
    Stefano, I have a similar issue with the ethtool in Debian/Ubuntu 7.10:
    I noticed that the ethtool setting for WOL kept getting turned off each time I rebooted. Then I realized this happened each time I turned turned the adapter on or off (ifdown eth0 | ifup eth0)… wol was getting disabled.

    Workaround: Add this line to “/etc/network/interfaces”:
    post-up /usr/sbin/ethtool -s eth0 wol g

    John Scobie’s resolution should also work…
    But using Roshan Shariff’s code (but with the wol option instead of speed) didn’t work if I used the variable $IFACE… I had to specify eth0 instead.

    Hope this helps anyone who is unable to permanently the WOL option in ethtool; I’ve spent the last 3 hours doing google searches and trying to troubleshoot before finding this.

  13. Harka Says:

    Debian:
    /etc/network/interfaces

    up ethtool -s eth0 speed 100 duplex full autoneg off

    Worked for me. Our servers with out-of-the-box OS settings always went half-duplex during auto-negotiation with the router. So this line fixes that.
    Ditto for ETHTOOL_OPTS line from article for Redhat.

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , , ,

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.