Linux - change the speed and duplex settings of an Ethernet card Print

  • 27

Q: I am not getting the speed you advertise.
A: We operate a Cisco only environment and sometimes when we force speeds on Ports the Linux Server will negotiate to Half Duplex.

Q: How can I check what my network card is set to?
A: You need to install ethtool. Here are some examples on how to check you interface settings.

Q: How do I change the speed, duplex on for my Ethernet card?

A: Under Linux you can use mii-tool or ethtool to modify/change and view the negotiated speed of your network card.

Q: How do I make these changes permanent?
A: Depending on your OS you will need to make changes to your configuration file or create a script that runs when your server boots.
    Instructions for Red Had Based systems (Red Hat enterprise Linux, Fedora core, Cent Os) can be found here
    Instructions for Debian or Ubuntu can be found here

Q: My server stopped responding to ping, help?
A: If your server stopped responding to ping something went wrong you need to use IPMI to connect to your server.
    Please log in to your IPMI or if you colocate and your server has no IPMI you can request a loaner to be connected.
    Over IPMI you will have access to your configuration files to undo your settings and to start over again.
    Please open a ticket if you require assistancefrom one of our Technicians.

Install mii-tool and ethtool tools


If you are using Debian Linux you can install both of these package with following command:

# apt-get install ethtool net-tools

If you are using Centos Linux you can install both of these package with following command:

# yum install ethtool net-tools


How to check your network card settins

You first need to find out what your network card is named.
Most of the time the name is eth0 or em1

Ifconfig will ist all your network cards.

# ifconfig

Sample output:

eth0      Link encap:Ethernet  HWaddr 00:25:00:00:00:00
          inet addr:199.193.14.XXX  Bcast:199.193.14.XXX  Mask:255.255.255.XXX
          inet6 addr: XXXXXXXXXXXXXXXXXX/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6056710787 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6052150805 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:110  TX bytes:200
          Memory:fb920000-fb93ffff

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)


Now to check your network card setting you want to use ethtools.
It will list you the supported modes, its advertised link modes and what the current setting on the network card is
.
In this sample below eth0 Auto-negotiated at 1000Mb/s and Full Duplex.
Running a all Cisco environment you might need to turn off Auto-negotiate and manually set your speed to 10Mb/s or 100Mb/s
to match the setting on our switch port.
Click here to find out how.

# ethtool eth0

Sample output:

Settings for eth0:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Supported pause frame use: Symmetric
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Full
        Advertised pause frame use: Symmetric
        Advertised auto-negotiation: Yes
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: off (auto)
        Supports Wake-on: pumbg
        Wake-on: g
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: yes



Change the speed and duplex settings - temporarily


Setup eth0 negotiated speed with mii-tool
Disable auto negotiation, and force the MII to either 100baseTx-FD or 10baseT-FD:

# mii-tool -F 100baseTx-FD
# mii-tool -F 10baseT-FD

Setup eth0 negotiated speed with ethtool:

# ethtool -s eth0 speed 100 duplex full
# ethtool -s eth0 speed 10 duplex full


These setting changes are temporarily. If you reboot your Server all changes will default back to its original setting!

Change the speed and duplex settings - permanent

On Red Hat Linux (Red Hat enterprise Linux, Fedora core, Cent Os):

You will need to know your network interface name (please follow this example to find your interface name, most cases it is eth0 or em1)
You will need to edit /etc/sysconfig/network-scripts/ifcfg-eth0 and Append the ethtool options to statically set your speed and duplex setting.
We use "vi" to open the configuration file for eth0.


# vi /etc/sysconfig/network-scripts/ifcfg-eth0

To set your speed to 10Mb/s, Duplex, Auto-Negotiation off append the following line:

ETHTOOL_OPTS="speed 10 duplex full autoneg off"


Save and exit the editor.
If you used vi you hit shift and : at the same time. : appers at the bottom of the page and you type wq to write and quit (lowercase).
This will get you back to your # prompt.
If you get stuck with error messages, press ESC until you are back to the editor and try again.

To set your speed to 100Mb/s, Duplex, Auto-Negotiation off append the following line:

ETHTOOL_OPTS="speed 100 duplex full autoneg off"

After you made your changes please restart your network by using this command:

# /etc/init.d/network restart

This will reset all connections (SSH, FTP, HTTP(S), IMAP, POP, ect) to your server. This might take up to 1 Minute to complete.

On Debian or Ubuntu based systems:

on Debian or Ubuntu Linux you need to create a script that gets executed everytime your server boots.
Any commands you enter you might need to append sudodepending what permition you have on your current user. Please create the following file:

# vi /etc/init.d/network-speed

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

You need to change the speed to 10 if you ordered a 10Mb/s port.
Save and close the file. If you used VI as your editor please press shift and : Then type wq and press enter.
Setup executable permission:

# chmod +x /etc/init.d/network-speed


Now run script when Debian or Ubuntu Linux boots up. Use update-rc.d command to install System-V style init script links:

# update-rc.d network-speed defaults

Output:

 Adding system startup for /etc/init.d/network-speed ...
   /etc/rc0.d/K20network-speed -> ../init.d/network-speed
   /etc/rc1.d/K20network-speed -> ../init.d/network-speed
   /etc/rc6.d/K20network-speed -> ../init.d/network-speed
   /etc/rc2.d/S20network-speed -> ../init.d/network-speed
   /etc/rc3.d/S20network-speed -> ../init.d/network-speed
   /etc/rc4.d/S20network-speed -> ../init.d/network-speed
   /etc/rc5.d/S20network-speed -> ../init.d/network-speed


Execute your script for the changes to take affect.


# /etc/init.d/network-speed start

Everytime your server boots it will execute your script and apply these changes.



If you have any problems or question please contact support@whitesandshosting.com.

Was this answer helpful?

« Back