Last active
February 14, 2024 22:41
-
-
Save ThinGuy/30d33f7ed4a5faaf5a5c08184bce4c69 to your computer and use it in GitHub Desktop.
systemd-networkd script to disable TSO, GSO, and GRO on all NICs reporting up
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sudo install -o0 -g0 -m0755 /dev/null /etc/networkd-dispatcher/routable.d/99-disable-tso-gso-gro.sh | |
cat <<'EOF' |sudo tee /etc/networkd-dispatcher/routable.d/99-disable-tso-gso-gro.sh | |
#!/bin/bash | |
# | |
# This script will be placed in /etc/networkd-dispatcher/routable.d/ | |
# and made exectuable | |
# | |
# This script disables the following features on all NICs except virtual: | |
# - tcp-segmentation-offload (TSO) | |
# - generic segmentation offload (GSO) | |
# - generic receive offload (GRO) | |
# Create array of NICs that report being up. | |
declare -ag NICS=($(ip -br l|awk '!/lo/&&/ UP /{print $1}'|sort -uV)) | |
for N in ${NICS[@]};do | |
printf "\n\e[1mChanging Offload Settings for ${N}\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\e[0m\n" | |
[[ $(ethtool --show-offload ${N}|awk '/tcp-segmentation-offload/{print $2}') =~ on ]] && { printf "\\e[3G- TCP Segmentation Offload (TSO) is currently enabled for NIC ${N}. Disabling...\n";ethtool -K ${N} tso off; } || { printf "\e[3G- TCP Segmentation Offload (TSO) is already disabled for NIC ${N}. Skipping....\n";true; } | |
[[ $(ethtool --show-offload ${N}|awk '/generic-segmentation-offload/{print $2}') =~ on ]] && { printf "\e[3G- Generic Segmentation Offload (GSO) is currently enabled for NIC ${N}. Disabling...\n";ethtool -K ${N} gso off; } || { printf "\e[3G- Generic Segmentation Offload (GSO) is already disabled for NIC ${N}. Skipping....\n";true; } | |
[[ $(ethtool --show-offload ${N}|awk '/generic-receive-offload/{print $2}') =~ on ]] && { printf "\e[3G- Generic Receive Segmentation Offload (GRO) is currently enabled for NIC ${N}. Disabling...\n";ethtool -K ${N} gro off; } || { printf "\e[3G- Generic Receive Offload (GRO) is already disabled for NIC ${N}. Skipping....\n";true; } | |
printf "\n\e[5G\e[1mNew Offload Settings for ${N}\n\e[5G━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\e[0m\n" | |
ethtool --show-offload ${N}|awk '/generic-segmentation-offload|generic-receive-offload|tcp-segmentation-offload/{gsub(/generic-segmentation-offload/,"gso",$1);gsub(/generic-receive-offload/,"gro",$1);gsub(/tcp-segmentation-offload/,"tso",$1);print $1,$2}'|sed -r 's/^/ - /g'; | |
done | |
exit 0 | |
EOF | |
# Test with the following: | |
# sudo /etc/networkd-dispatcher/routable.d/99-disable-tso-gso-gro.sh |
Author
ThinGuy
commented
Feb 14, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment