Linux change the speed and duplex settings of an Ethernet card | linux change duplex settings
Q: I need to change the speed and duplex settings for my network card, is this possible?
A: Under Linux you can use the built-in tool ethtool to display and change the duplex settings for your network card under Linux, depending on the NIC installed on your system you could try to use the mii-tool as well. In my experience ethtool works for most of the modern network cards so I will describe only the use of this tool
Install ethtool
Depending on your system ethtool could be already present and so you will be able to change duplex settings right away, in case it is not present you can easily install with the following command:
yum install ethtool
Or if you are using Debian or Ubuntu with the command :
apt-get install ehtool
Get information of duplex settings for network card
Once you have installed the tools of the trade is time to show test they are functioning, the syntax of the command is pretty straightforward all you have to do for a basic test is launch the command ethtool followed by the name of the interface for which we want to get information here’s output for my eth0 interface :
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: Symmetric Receive-only Advertised auto-negotiation: Yes Speed: 10Mb/s Duplex: Half Port: MII PHYAD: 0 Transceiver: internal Auto-negotiation: on Supports Wake-on: pumbg Wake-on: g Current message level: 0x00000033 (51) drv probe ifdown ifup Link detected: no
In the above output you can see all important information about the network card, it is disconnected so your output could be slightly different, assuming that you need to configure you card to operate on full duplex at a speed of 100 Mbps you would use the following command :
ethtool -s eth0 speed 100 duplex full ethtool -s eth0 speed 100 duplex half ethtool -s eth0 speed 10 duplex full
As you can see above I gave multiple examples on how to use ethtool to configure various duplex setting for the network card, be aware that changes made this way will not survive a reboot and so are a good way to test different settings.
Make Duplex Settings change permanent
Once you have configured your network card to the correct duplex settings you will want to make the changes permanent, to do so you will need to change the configuration file for your network card in our example the file will be /etc/sysconfig/network-scripts/ifcfg-eth0 on a Red Hat based system and add the following text :
ETHTOOL_OPTS="speed 100 duplex full autoneg off" service networking restart
The above will set the speed of the network card to 100 Mbps with full duplex enabled disabling auto negotiation, the last command is needed so that Linux will pick up the duplex changes, of course you could also reboot the server but I prefer to leave that to the Windows world
Under Debian/Ubuntu the needed steps are slightly different, in this case you will need to create a bash script and put something like the following code :
#!/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
Once saved the script make it executable and copy it under the /etc/init.d/ directory and finally add it to the startup sequence with the command :
update-rc.d <your_script> defaults
You can try to restart the system to check the results of the new configuration.
That’s all you need to change duplex settings under Linux, ethtool is invaluable when testing and troubleshooting network related problems and I hope this post will help you as well.
In case you face any problem feel free to write me or leave a command and I will be more than glad to help you out.
Cheers Lethe.
Pingback: Linux change the speed and duplex settings of an Ethernet card | linux change duplex settings | UnixProfs