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/shSave and close the file. Setup executable permission:
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
# 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:
- Email this to a friend
- Printable version
- Rss Feed
- Last Updated: Jul/16/2007
{ 18 comments… read them below or add one }
In Debian or Ubuntu, it’s much easier to add a pre-up line to /etc/network/interfaces. Something like this:
iface eth0 inet staticpre-up /usr/sbin/ethtool -s $IFACE 10 duplex half
address ...
Roshan
Good tip; my bad I should have thought about it.
Appreciate your post.
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
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
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.
Very thank , i used this.
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
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?
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:
or (for rhel 4.x or older )
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
HTH
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.
simply superb
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.
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.
My questions is: my /etc/sysconfig/network-scripts/ifcfg-eth0 is not having details of the NIC speed but when i issue command ethtool eth0 i am getting NIC speed. Where could be this information picking from? Is there any place which ethtool command picks this information?
A variant on the script that handles multiple interfaces and reads the interdfaces from a configuration file.
Enjoy.
Cheers
Interface entry in /etc/default/100Mbs:
INTERFACES=”eth0 eth1 eth3″
/etc/init.d/100Mbs startup script:#!/bin/sh
# Startup script for changing netowork interface parameters
#
ETHTOOL=”/usr/sbin/ethtool”
OPTIONS=”speed 100 duplex full autoneg off”
# Check for a configuration file in /etc/default
if [ ! -f /etc/default/100Mbs ]; then
echo “/etc/default/100Mbs does not exist! – Aborting…”
exit 1
fi
. /etc/default/100Mbs
case “$1″ in
start)
if test “$INTERFACES” != “”; then
for I in $INTERFACES; do
echo -n “Setting ${I} $OPTIONS …”;
$ETHTOOL -s ${I} $OPTIONS;
echo ” done.”
done
fi
;;
stop)
;;
esac
exit 0
Thx for the arcticle. Helped me out.
Hi!! I have some question about this script, I’m enter in this script but some expression I don’t understand.
Well gooo.
#!/bin/sh
ETHTOOL=”/usr/sbin/ethtool”
DEV=”eth0″ // well here in the end the expression no coming “;” well in each expression.
SPEED=”100 duplex full”
case “$1″ in
start) //well here not is start()
echo -n “Setting eth0 speed 100 duplex full…”;
$ETHTOOL -s $DEV speed $SPEED;
echo ” done.”;;
stop) // here too stop ()
;;
esac
exit 0
well this script I’ll work but no change the base 100TX to 10T when restart my Debian, Now I’m use the tools like ethtool for change in the moment, well send me the solution and thank for the post is good information.
Hmmm… I have 2.6.25 and and I just managed to cut myself access from the server by issuing
ethtool -s eth0 autoneg off speed 1000 duplex full
even when I got this:
ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: umbg
Wake-on: g
Current message level: 0×00000007 (7)
Link detected: yes
I have a new gbit switch there but I can’t get the desired speed… any bright ideas?