Linux add ethtool duplex settings to a network card permanently

by on September 28, 2006 · 38 comments· LAST UPDATED July 16, 2007

in , ,

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:

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 38 comments… read them below or add one }

1 Roshan Shariff September 28, 2006 at 8:38 pm

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 ...

Reply

2 Ville Walveranta March 6, 2013 at 10:54 pm

“Speed” keyword seems to be needed (could be a more recent requirement since this thread is many years old), like so:

pre-up /usr/sbin/ethtool -s $IFACE speed 10 duplex half

Reply

3 nixCraft September 28, 2006 at 9:36 pm

Roshan

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

Appreciate your post.

Reply

4 Jon Scobie September 29, 2006 at 1:31 pm

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

Reply

5 Thomas Edman September 29, 2006 at 7:26 pm

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

Reply

6 nixCraft September 30, 2006 at 4:50 am

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.

Reply

7 anand June 26, 2007 at 12:20 pm

Very thank , i used this.

Reply

8 Stefano July 12, 2007 at 8:25 am

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

Reply

9 Ryan July 19, 2007 at 5:30 pm

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?

Reply

10 nixCraft July 19, 2007 at 5:48 pm

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

Reply

11 Ryan July 19, 2007 at 6:07 pm

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.

Reply

12 Hema November 18, 2007 at 10:42 am

simply superb

Reply

13 Joe May 26, 2008 at 6:07 am

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.

Reply

14 Harka July 3, 2008 at 9:06 am

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.

Reply

15 Vasudeva August 12, 2008 at 2:09 pm

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?

Reply

16 trimethy November 16, 2008 at 12:49 pm

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

Reply

17 wuchale December 16, 2008 at 2:55 pm

Thx for the arcticle. Helped me out.

Reply

18 Hector May 22, 2009 at 3:56 pm

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.

Reply

19 Ciprian Pantea June 17, 2009 at 9:31 pm

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?

Reply

20 digus July 16, 2009 at 5:30 pm


In Ubuntu/Debian for 100-Full, this works for a static IP in /etc/network/interfaces:
—————————-

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo eth0
iface lo inet loopback

# The primary network interface
iface eth0 inet static
pre-up /usr/sbin/ethtool -s eth0 speed 100 duplex full autoneg off
address 192.168.1.101
netmask 255.255.255.0
broadcast 192.168.1.255
network 192.168.1.0
gateway 192.168.1.1

——————–
this should work for DHCP/Auto setup:
——————–

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo eth0
iface lo inet loopback

# The primary network interface
iface eth0 inet dhcp
pre-up /usr/sbin/ethtool -s eth0 speed 100 duplex full autoneg off

Reply

21 Prachi September 2, 2009 at 7:48 am

Hi,

I have 2 ethernets (eth0 and eth1) with bouding done as bond0.

# ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
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 auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: g
Wake-on: g
Current message level: 0x000000ff (255)
Link detected: yes

# ethtool eth1
Settings for eth1:
Supported ports: [ TP ]
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 auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: g
Wake-on: g
Current message level: 0x000000ff (255)
Link detected: yes

[root@amuswatnas01 ~]# ethtool bond0
Settings for bond0:
No data available

I want to hard-code the speed to 1000 MBps Full duplex, how can I do that on bouded network,
Do I need to simply edit ifcfg-eth0 and ifcfg-eth1 file with following entries.
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Append following line:
ETHTOOL_OPTS=”speed 100 duplex full autoneg on”

Let me know if any other changes are required.

ethtool shows its 1000 Mbps FD, Do I still need to hard-code, From which file, it shows such configiration?

Thanks,
Prachi

Reply

22 Jordan October 1, 2009 at 10:26 pm

What do I need to add to the Debian script to turn autonegot off?

Reply

23 Sergio Luiz Araujo Silva May 17, 2010 at 6:07 pm

if device is eth1 generate error, to solve:

DEV=`netstat -i | awk ‘/eth/ {print $1}’`

Reply

24 Rafael Guedes June 4, 2010 at 3:06 am

Hi, nice post! For Debian, I think that you just need append the follow line at /etc/network/interfaces file:

post-up ethtool -s eth0 speed 10 duplex half

I tested it , and for me it works very well. Regards from Brazil.

Reply

25 Tiago MDRizzo July 27, 2010 at 1:35 pm

For Debian, like Rafael Guedes said, isn’t it easier to append in /etc/network/interfaces?

Not just it, but you can add routes and delete them too using post-up and post-down option in Debian… I never tested in Ubuntu though…

By the way, Cyberciti is my favorite site :D

Regards from Brazil!!

Reply

26 arunmanoj December 22, 2010 at 5:57 am

could pls tel ,how to set the speed to 10mbps full duplex, i tried ur above script & steps (with 10 instead of 100),but its not working..

OS : Ubuntu 10.4 LTS

Thanx in advance

Reply

27 FishMaster3000 January 19, 2011 at 11:12 pm

Thanks for the tip. I applied it to my hardware and I am happy that the speed it blazing in my VM. I will keep watch on whether the ethernet card drops the connection as it has been doing in the past. If it remands up, I am extremely happy.

(AMD Phenom II X4 940, 8G memory, 2 gig ethernet, 3 Tb of harddrive, nvidia cards)

Reply

28 Gogule March 3, 2011 at 10:29 pm

on centos 5.4 final this command work
mii-tool -F 100baseTx-FD

thk for help

Reply

29 dotpointer March 14, 2011 at 6:43 pm

Ubuntu 10.10, a Marvell Gigabit Ethernet and gigabit 1000mbit speed:

– Manual change while working on it:
ethtool -s eth0 speed 1000 duplex full autoneg off

– Hopefully permanent – /etc/network/interfaces:
auto lo
iface lo inet loopback
iface eth0 inet dhcp
pre-up /sbin/ethtool -s $IFACE speed 1000 duplex full autoneg off

– Testing the file (NOTICE: ifconfig eth0 down/up does NOT test the file):
ifdown eth0
ifup eth0

Reply

30 dotpointer March 14, 2011 at 6:49 pm

(All above is run as administrator -do ‘sudo passwd root’ to set your password, then ‘su’)

Another notice, if you already have done the above tip with /etc/init.d/, here is how to remove that:

rm /etc/init.d/100mbit
update-rc.d 100mbit remove (notice the actual file removal must be done before)

Reply

31 Dhileesh March 21, 2011 at 1:31 pm

Good option

Reply

32 Seb176 December 15, 2011 at 11:21 am

Thank you!!
Very usefull for my old laptop!

Reply

33 Peter January 10, 2012 at 2:34 pm

Added ETHTOOL_OPTS=”speed 1000 duplex full autoneg off” to ifcfg-eth1 to force gigabit. After a restart I get these messages. What’s wrong with eth1 (Realtek RTL-8169), working fine on 100 Mbs though…?

# etc/init.d/network restart
Shutting down interface eth1: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0:
Determining IP information for eth0… failed; no link present. Check cable?
[FAILED]
Bringing up interface eth1: Cannot get current device settings: Operation not supported
not setting speed
not setting duplex
not setting autoneg

Reply

34 andrej May 7, 2012 at 4:25 pm

@Peter try autoneg on since setting speed to 1000 needs autoneg on

Reply

35 Peter May 8, 2012 at 5:59 am

Hi andrej,

Thank you for your help! I have to try ‘autoneg on’ later. I had to remove the Realtek card because of rebooting problems. So, sadly my secondary 3Com 100Mbps card became primary again… As soon as I know the result of your suggestion, I’ll let you know. Regards, Peter.

Reply

36 Damián Viano September 18, 2012 at 2:19 pm

For lastests Debian or debian based distributions I strongly recommend reading /usr/share/doc/ethtool/README.Debian

Reply

37 Nehemoth April 2, 2013 at 2:07 am

@Damián Viano, thank you, after a lot of search, this was the only way to do it.

Reply

38 Paras Watts December 5, 2013 at 11:25 am

Hi,

Switching autoneg (off) on a interface is showing no link , when i switch on autoneg , link is shown

Reply

Leave a Comment

Tagged as: , , , , , , , , , ,

Previous post:

Next post: