Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I would like to turn off tcp segmentation offload on a CentOS5 server. Using ethtool the command is ethtool -K eth0 tso off However, this setting only persists for this session. How can I make it persist through reboots?

share|improve this question
1  
put it in a start script somewhere. –  Zoredache Jan 4 '13 at 19:08

4 Answers 4

up vote 7 down vote accepted

From this webpage:

You can enter the ethtool commands in /etc/rc.local (or your distribution's equivalent) where commands are run after the current runlevel completes, but this isn't ideal. Network services may have started during the runlevel and ethtool commands tend to interrupt network traffic. It would be more preferable to have the commands applied as the interface is brought up.

The network service in CentOS has the ability to do this. The script /etc/sysconfig/network-scripts/ifup-post checks for the existence of /sbin/ifup-local, and if it exists, runs it with the interface name as a parameter (eg: /sbin/ifup-local eth0)

We can create this file with touch /sbin/ifup-local make it executable with chmod +x /sbin/ifup-local set its SELinux context with chcon --reference /sbin/ifup /sbin/ifup-local and then open it in an editor.

A simple script to apply the same settings to all interfaces would be something like

#!/bin/bash
if [ -n "$1" ]; then
/sbin/ethtool -G $1 rx 4096 tx 4096
/sbin/ethtool -K $1 tso on gso on
fi

Keep in mind this will attempt to apply settings to ALL interfaces, even the loopback.

If we have different interfaces we want to apply different settings to, or want to skip the loopback, we can make a case statement

#!/bin/bash
case "$1" in
eth0)
/sbin/ethtool -G $1 rx 16384 tx 16384
/sbin/ethtool -K $1 gso on gro on
;;
eth1)
/sbin/ethtool -G $1 rx 64 tx 64
/sbin/ethtool -K $1 tso on gso on
/sbin/ip link set $1 txqueuelen 0
;;
esac
exit 0

Now ethtool settings are applied to interfaces as they start, all potential interruptions to network communication are done as the interface is brought up, and your server can continue to boot with full network capabilities.

share|improve this answer
    
Hey that's my blog! Thanks for the link credit :) –  suprjami Nov 5 at 10:47

Off-topic, for Ubuntu users who came here, like me, this as a note:

On Ubuntu, the textbook way to do it is to edit the /etc/network/interfaces file which in turn is read by the init.d/pre-up -up, etc. scripts. So an /etc/network/interfaces file might look like this:

auto eth0
iface eth0 inet static
pre-up /sbin/ethtool -s eth0 speed 10 duplex full

That's what the docs say, but it does not work. Might be that the parsing logic in the pre-up and up scripts is a bit dated and they don't parse out the required settings from the interfaces file. Don't know. At least, it was not working for me.

So the hack-ish but working solution for now is still to create/edit a local /etc/rc.local file and stating the command to be exuted there (but note that this may interrupt networking for a seconds after the interface has already been brought up). So having this:

ethtool -s eth0 speed 10 duplex full autoneg on

in /etc/rc.local is the working solution to slow down an interface as intended above.

share|improve this answer

I ran into problems with the accepted answer (which, I hasten to add, I found very helpful) because I was using bonded interfaces.

It took me a while to discover what was happening but I found that when bringing up a bond, or even when bringing up a bond slave individually, the ifup-local script would not be called for the slave interfaces. I assume that this is because the slave interfaces did not have any IP addresses assigned to them.

To get round this I modified my ifup-local to parse the contents of /proc/bonding/bondX for the interface which had been brought up, if it was a bond, to get the slave interface names, and then did the necessary stuff with them.

In the end my ifup-local looked like the following:

#!/bin/bash

if [ -n "$1" ]
then
  IFACE="$1"

  # If interface is physical
  if [[ $IFACE =~ ^eth[0-9]+$ ]]
  then
    # Do whatever you need for a physical interface here
    # example below
    /sbin/ethtool -K $IFACE rx off    

  # Else if it's a bond
  elif [[ $IFACE =~ ^bond[0-9]+$ ]]
  then
    # Do whatever you need for the bond here
    # example below
    /sbin/ethtool -K $IFACE gso off

    # Now deal with slaves
    # Pull out slave interface names from /proc/net/bonding/bondX
    SLAVES=$(/bin/grep -oP "Slave Interface: \K(eth[0-9]+)" /proc/net/bonding/$IFACE)
    for SLAVE in $SLAVES
    do
      # Do whatever you need with the slave here
      # example below
      /sbin/ethtool -K $SLAVE tso off gso off
    done
  fi
fi

Caveat: the contents of /proc/net/bonding/bondX may be different for different versions of RedHat/Fedora/CentOS to the one I was using when I wrote the script, so the command to pull out the slave interface names may not work.

share|improve this answer

Yeah, it can't be done using configuration files for the moment. You can put up the command in /etc/init.d/rc.local and it should be done.

That file is executed at the last of the booting sequence and so tso would be turned off for the interface.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.