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.
-M do : Select Path MTU Discovery strategy do (pro‐hibit fragmentation, even local one)
-c : to stop ping when you are done sending information.