Skip to content

Instantly share code, notes, and snippets.

@henning
Created May 2, 2015 21:26
Show Gist options
  • Save henning/d53d18de6c8be264cc35 to your computer and use it in GitHub Desktop.
Save henning/d53d18de6c8be264cc35 to your computer and use it in GitHub Desktop.
fix-mtu script
#!/bin/bash
# script to find and set the right mtu
#
# Usage
# fix-mtu [INTERFACE]
#
# When not INTERFACE given, wlan0 is used as default.
# check if an interface was given
if [ -z $1 ]; then
INTERFACE=wlan0
echo "not interface given, using default"
else
INTERFACE=$1
fi
set -u
echo "checking for good mtu setting for $INTERFACE"
# Start with 1500 size
NUM=1500
# ping with non defrag packets and decrease
# until fitting size is found
while ! ping -I $INTERFACE -c 1 -s $NUM www.google.com -M do; do
(( NUM -= 1 ))
done
let RIGHT=NUM+28
echo "setting calculated working MTU as $RIGHT"
sudo ip link set dev $INTERFACE mtu $RIGHT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment