How to write a NetworkManager dispatcher script to apply commands on interface start?
Environment
- Red Hat Enterprise Linux 9
- Red Hat Enterprise Linux 8
- Red Hat Enterprise Linux 7
- NetworkManager used to manage network connections
- Network interface supporting configurable offload via
ethtool -Kcommands
Issue
- How to write a NetworkManager dispatcher script to apply
ethtoolcommands? - Need to apply
ethtooloffloading to a network interface at boot or startup? - What is the correct syntax for a NM dispatcher script to enable or disable offloading like checksumming or large receive (GSO/LRO) or segmentation (GRO/LSO)?
Resolution
- Some versions of NetworkManager have support for ethtool parameters. Please see solution https://access.redhat.com/solutions/2127401 for details. Red Hat recommend using native support if possible.
- Otherwise create a unique executable file in the
/etc/NetworkManager/dispatcher.d/directory, for example:
touch /etc/NetworkManager/dispatcher.d/30-ethtool
chmod +x /etc/NetworkManager/dispatcher.d/30-ethtool
For a standalone network interface:
#!/bin/bash
if [ "$1" == "eth0" ] && [ "$2" == "up" ]; then
ethtool -K "$1" rx off gro off lro off
fi
For 2 standalone network interfaces:
#!/bin/bash
if [ "$1" == "eth0" -a "$2" == "up" ] || [ "$1" == "eth1" -a "$2" == "up" ] ; then
ethtool -K "$1" rx off gro off lro off
fi
For a bonding or teaming network interface:
#!/bin/bash
if [ "$1" == "bond0" ] && [ "$2" == "up" ]; then
for INTERFACE in bond0 eth0 eth1; do
ethtool -K "$INTERFACE" rx off gro off lro off
done
fi
Modify the list of interfaces as required, ensure the parent bond/team device and all slave devices have settings applied to them.
Note that some interface types are not compatible with all ethtool options.
Root Cause
Dispatcher scripts are explained in man NetworkManager, including the parameters passed to the dispatcher script.
Usually this sort of offloading only needs to be applied at interface start, so match the device name as the first script parameter, and the up action as the second script parameter.
The dispatcher script can be any language and perform any command, they are not restricted to bash or to ethtool commands.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.