Here is a script to find the maximum MTU (the value before the packet is fragmented). I was not particularly satisfied with dlsreports guide. The command given for us linux might not work most of the time (doesn’t prohibit fragmentation at time) as well as it is not an automatic operation but relies on trial and error.
=================================================================================
#!/bin/bash PKT_SIZE=1472 HOSTNAME="www.dslreports.com" count=`ping -M do -c 1 -s $PKT_SIZE $HOSTNAME | grep -c "Frag needed"` while [ $count -eq 1 ]; do ((PKT_SIZE--)) count=$((`ping -M do -c 1 -s $PKT_SIZE $HOSTNAME | grep -c "Frag needed"`)) done printf "Your Maximum MTU is [ $((PKT_SIZE + 28)) ] \n"
=============================================================================================
This script will neatly print out the maximum MTU at the end of the operation after finding the optimal value of the packet size.
Explaination:
-M do : Select Path MTU Discovery strategy do (pro‐hibit fragmentation, even local one)
-c : to stop ping when you are done sending information.
Thank you!
I think “-M do” doesn’t work on my mac? Maybe “-D” is better on a mac?
This one-liner works for me:
$ ping -c1 -M do -s 10000 http://www.google.com | grep mtu | awk ‘{ print $NF }’ | sed -e s/\)//
1500
HTH
[…] https://idyllictux.wordpress.com/2009/06/19/script-find-maximum-mtu/ […]
That is a slow implementation
function maximale_Paketgroesse_ermitteln () {
upper_limit=1500
lower_limit=1
middle=750
while [[ $lower_limit != $middle ]]
do
ping6 -M do -s $middle -c 1 &> /dev/null
if [ $? == “0” ]
then
lower_limit=$middle
else
upper_limit=$middle
fi
middle=$(( ($upper_limit + $lower_limit) / 2 ))
done
echo $middle
}
That just needs around eleven packages to find the threshold.
Regards,
Matthias