-
-
Save mcspring/a00b36db6baba45844181f7089228f5a to your computer and use it in GitHub Desktop.
Ubuntu enable BBR
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 | |
set -eu | |
SYSCTL_FILE=/etc/sysctl.d/90-tcp-bbr.conf | |
# check root | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" | |
exit 1 | |
fi | |
# check OS version | |
source /etc/lsb-release | |
KERNEL_VERSION=$(uname -r) | |
if [ "$DISTRIB_ID" != "Ubuntu" ]; then | |
echo "This script must be run under Ubuntu" | |
exit 1 | |
fi | |
# install newest kernel | |
if [ "$DISTRIB_RELEASE" == "12.04" ]; then | |
apt-get update -y | |
apt-get install -y --install-recommends linux-generic-lts-trusty | |
apt-get autoremove -y | |
elif [ "$DISTRIB_RELEASE" == "14.04" ]; then | |
apt-get update -y | |
apt-get install -y --install-recommends linux-generic-lts-xenial | |
apt-get autoremove -y | |
elif [ "$DISTRIB_RELEASE" == "16.04" ]; then | |
apt-get update -y | |
apt-get install -y --install-recommends linux-generic-hwe-16.04 | |
apt-get autoremove -y | |
else | |
# check kernel version | |
if dpkg --compare-versions "$KERNEL_VERSION" "ge" "4.9"; then | |
echo "WARNING: Non-LTS versions are not supported. Continuing since you have a compatible kernel." | |
else | |
echo "ERROR: Kernel auto install on Non-LTS versions is not supported. Please manually install kernel >= 4.9." | |
exit 1 | |
fi | |
fi | |
if grep -q "tcp_bbr" "/etc/modules-load.d/modules.conf"; then | |
echo "tcp_bbr" >> /etc/modules-load.d/modules.conf | |
fi | |
echo "Current configuration: " | |
sysctl net.ipv4.tcp_available_congestion_control | |
sysctl net.ipv4.tcp_congestion_control | |
# apply new config | |
if ! grep -q "net.core.default_qdisc=fq" "$SYSCTL_FILE"; then | |
echo "net.core.default_qdisc=fq" >> $SYSCTL_FILE | |
fi | |
if ! grep -q "net.ipv4.tcp_congestion_control=bbr" "$SYSCTL_FILE"; then | |
echo "net.ipv4.tcp_congestion_control=bbr" >> $SYSCTL_FILE | |
fi | |
# check if we can apply the config now | |
if lsmod | grep -q "tcp_bbr"; then | |
sysctl -p $SYSCTL_FILE | |
echo "BBR is available now." | |
elif modprobe tcp_bbr; then | |
sysctl -p $SYSCTL_FILE | |
echo "BBR is available now." | |
else | |
echo "Please reboot to enable BBR." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment