Last active
February 14, 2024 22:25
-
-
Save ThinGuy/ec4589ff985c9beec48ff17b63bbd803 to your computer and use it in GitHub Desktop.
Disables Energy Efficient Ethernet (EEE) on all NICs that support it. For use with Netplan (via networkd-dispatcher)
This file contains hidden or 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 | |
# Install ethtool if needed | |
[[ $(command -v ethtool 2>/dev/null) ]] || { printf "\nInstalling ethtool. One moment...\n\n";sudo apt install ethtool -yqf; } | |
# Create an empty networkd dispatcher script with correct owner and permissions | |
sudo install -o0 -g0 -m0755 /dev/null /etc/networkd-dispatcher/routable.d/99-disable-eee.sh | |
cat <<'EOF' |sudo tee 1>/dev/null /etc/networkd-dispatcher/routable.d/99-disable-eee.sh | |
#!/bin/bash | |
# | |
# This script will be placed in /etc/networkd-dispatcher/routable.d/ | |
# and made exectuable | |
# | |
# This script disables Energy Efficient Ethernet (EEE) on *physical* NICs | |
# that support that setting | |
# Create array of physical NICs | |
declare -ag NICS=($(find /sys/class/net -type l ! -lname "*virtual*" ! -lname "*/wl*" -printf '%P\n'|sort -uV)) | |
for N in ${NICS[@]};do | |
if [[ $(sudo ethtool &>/dev/null --show-eee ${N};echo $?) -eq 0 ]];then | |
[[ $(sudo ethtool --show-eee ${N}|awk '/status:/{print $NF}') = disabled ]] && { printf "\nEEE settings for ${N}:\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\e[3G- Energy Efficient Ethernet (EEE) is already disabled for ${N}. Skipping...\n";true; } | |
[[ $(sudo ethtool --show-eee ${N}|awk '/status:/{print $NF}') = disabled ]] || { sudo ethtool --show-eee ${N}|sed -r 's/^EEE.*$/\n&\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━/g';printf "\n\e[3G- Setting Energy Efficient Ethernet (EEE) to disabled for ${N}\n";sudo ethtool --set-eee ${N} eee off; } | |
else | |
printf "\nEEE settings for ${N}:\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\e[3G- NIC ${N} does not support Energy Efficient Ethernet (EEE) Skipping.\n";true; | |
fi | |
echo | |
done | |
exit 0 | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example 1:
Example 2: