Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
2  
put it in a start script somewhere. – Zoredache Jan 4 '13 at 19:08
up vote 11 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
1  
Hey that's my blog! Thanks for the link credit :) – suprjami Nov 5 '14 at 10:47
    
also note about ETHTOOL_OPTS described here access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/… However by some reason it doesn't work on my machine yet superuser.com/questions/995200/… – javapowered Nov 9 '15 at 20:59

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

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

For RHEL7 in /etc/sysconfig/network-scripts/ifcfg-* you may have:

ETHTOOL_OPTS="-K ${DEVICE} gso off gro off tso off"

if more options then use like

ETHTOOL_OPTS="-K ${DEVICE} gso off;-K ${DEVICE} gro off;-K ${DEVICE} tso off"

you have to have naturally DEVICE defined in your ifcfg file.

No rc.local nor extra ifup scripts needed. Easy to you in generic deployment systems.

share|improve this answer

I found that setting this kind of configuration in /etc/network/interfaces actually works for Ubuntu (granted I used it for turning off large-receive-offload, but that shouldn't really matter):

auto eth1
iface eth1 inet static
    address xxx.xxx.xxx.xxx
    netmask xx
    pre-up /sbin/ethtool -K $IFACE lro off
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

If you are on RHEL7 (or alike) and use Network Manager instead of /etc/init.d/network to control your interfaces the proposed answer will not work, since /sbin/ifup-local (as well as ifdown-pre-local and ifdown-local) will never get executed.

Instead put your scripts into /etc/NetworkManager/dispatcher.d/ and make sure the NetworkManager-dispatcher service is enabled

systemctl enable NetworkManager-dispatcher

Hint: The dispatcher will only kick in once NetworkManager makes changes to an interface, it doesn't need to be running or anything, so if the status reads

Active: inactive (dead)

that's completely fine!

Also make sure your script is:

  1. executable (chmod +x)
  2. owned by root (chown root:root)
  3. writable by root only (chmod 755)

Now NetworkManager will pass two (2) variables to the dispatcher:

$1 being the interface (eno16777984, eth0, ppp0, etc...)

$2 holding the status (either up or down)

and it allows chaining the scripts (just like /etc/rc...) to have some control over the order in which the dispatcher will execute them:

10-first, 20-second and so on...

The order will be ascending on a connect

if [$2 = "up"] its 10-first followed by 20-second

and descending on a disconnect

if [$2 = "down"] you get 20-second followed by 10-first

and so on.

So to accomplish what OP was looking for you could put something like this:

#!/bin/bash
if [ "$1" = "eth0" && "$2" = "up" ]; then
  /sbin/ethtool --offload eth0 tso off
fi

in /etc/NetworkManager/dispatcher.d/20-ethtool

And call it a day.

Cheers

share|improve this answer
    
Please note that this question is very old and that it already has an accepted answer and your answer does not really add new. Please try to avoid answering very old posts as it tends to clutter up the front page. – Catherine MacInnes 13 hours ago
    
Search Google for "ifup-local" and you get this as the 6th hit. Nothing i would consider "old" – user1972814 13 hours ago

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.