Skip to content

Instantly share code, notes, and snippets.

@ThinGuy
Last active February 14, 2024 22:25
Show Gist options
  • Save ThinGuy/ec4589ff985c9beec48ff17b63bbd803 to your computer and use it in GitHub Desktop.
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)
#!/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
@ThinGuy
Copy link
Author

ThinGuy commented Feb 14, 2024

Example 1:

$ sudo /etc/networkd-dispatcher/routable.d/99-disable-eee.sh

EEE settings for enp0s25:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
        EEE status: enabled - inactive
        Tx LPI: 17 (us)
        Supported EEE link modes:  100baseT/Full
                                   1000baseT/Full
        Advertised EEE link modes:  100baseT/Full
                                    1000baseT/Full
        Link partner advertised EEE link modes:  Not reported
        
  - Setting Energy Efficient Ethernet (EEE) to disabled for enp0s25


EEE settings for enx8cae4cfdd0dd:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  - Energy Efficient Ethernet (EEE) is already disabled for enx8cae4cfdd0dd.  Skipping...


EEE settings for enx8cae4cfdd0fa:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  - Energy Efficient Ethernet (EEE) is already disabled for enx8cae4cfdd0fa.  Skipping...

Example 2:

$ sudo /etc/networkd-dispatcher/routable.d/99-disable-eee.sh

EEE settings for enp0s25:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  - Energy Efficient Ethernet (EEE) is already disabled for enp0s25.  Skipping...


EEE settings for enx8cae4cfd9e47:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  - Energy Efficient Ethernet (EEE) is already disabled for enx8cae4cfd9e47.  Skipping...


EEE settings for enx8cae4cfd9f27:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  - Energy Efficient Ethernet (EEE) is already disabled for enx8cae4cfd9f27.  Skipping...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment