Set Ethernet Speed And Duplex Mode In Linux Using Ethtool / Mii Tool

What is Duplex setting?

By default, NICs used in Linux negotiate their speed and duplex with the switch through the exchange of Fast Link Pulses (FLP). When speed and duplex are set forcibly, these FLPs are not sent. This results in errors when NIC is in an auto negotiation mode and detects no FLP. It then sets the duplex to half -duplex and the speed to the lowest allowed value. To avoid this, it is better to force switch port and server NIC at the same speed and duplex values, or auto-negotiate.

Changing NIC Speed and Duplex

For Linux platforms, nothing is better than a perfectly compatible NIC card. Most of the Linux vendor's have a list of compatible hardware on their websites. Linux distributions automatically negotiate the speed and duplex of the NIC card with the switch to which it is connected. As there are differences in the implementation of protocols, it is not sufficient to configure a switch port to auto-negotiate speed and duplex mode. However, NIC with failed negotiation will work even though many errors with ifconfig –a command will be displayed.

Depending on the type of Ethernet card installed on your system, you can use either mii-tool or ethtool to set the speed and duplex mode.

1. Using mii-tool:

Mii-tool is the original tool used to set the speed and duplex of the NIC card. This tool has been replaced by the ethtool command but some older NICs still support mii-tool. In order for it to display a brief report, simply run the command without arguments:

[[email protected] ~]# mii-tool
SIOCGMIIPHY on 'eth0' failed: Operation not supported
eth1: 100 Mbit, half duplex, link ok

NICs that do not support mii-tool still work but in order to set the speed and duplex, you have to go through the manufacturer’s guide.

You can find out more details by using the mii-tool command with –v option:

# mii-tool –v
eth1: negotiated 100baseTx-FD, link ok
product info: vendor 00:10:18, model 33 rev 2
basic mode: autonegotiation enabled
basic status: autonegotiation complete, link ok
capabilities: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
advertising: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
link partner: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control

You can forcefully set your NIC to a specific speed and duplex using –F option, but keep in mind that by doing so you may lose connectivity to server, if the desired speed and duplex doesn’t match that of your switch.

# mii-tool –F 100baseTx-FD eth0

However, these changes are not permanent and get lost during system reboot. To make these settings permanent across shut downs, you need to place the command in /etc/rc.local file to let the command run during the booting process.

2. Using Ethtool

The ethtool command has successfully replaced the mii-tool command. Using this command, you can find out all the details about the interface given as its argument.

# ethtool eth0

Settings for eth0:
Supported ports: [ TP MII ] Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Advertised auto-negotiation: No
Speed: 100Mb/s
Duplex: Full
Port: MII
Transceiver: internal
Auto-negotiation: off
Supports Wake-on: g
Wake-on: g
Current message level: 0x00000007 (7)
Link detected: yes

In the above output, we can see interface eth0 is not doing auto-negotiation and is set to a speed of 100 Mbps, full duplex. A list of supported modes is also provided at the top of the output.
NIC speed and duplex can be set as:

# ethtool –s eth0 speed 100 duplex full

# ethtool –s eth0 speed 10 duplex half

To have these settings during next boot, you need to set them with ETHTOOL_OPTS variable as follows:

# Vi /etc/sysconfig/network-scripts/ifconfig-eth0

ETHTOOL_OPTS="speed 100 duplex full autoneg off"

You can test the settings by shutting down the interface and then activating it again with ifup and ifdown commands.

You can also change speed and duplex mode using –s option as follows:

# ethtool –s eth0 speed 100 duplex full autoneg on

Bobbin Zachariah 9:58 pm

About Bobbin Zachariah

Founder of LinOxide, passionate lover of Linux and technology writer. Started his career in Linux / Opensource from 2000. Love traveling, blogging and listening music. Reach Bobbin Zachariah about me page and google plus page.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.