feat: add MTU finder script for optimal network configuration

Introduced a new script to determine the optimal Maximum Transmission Unit (MTU) size for a given destination IP. The script includes a function to display usage help, checks for a mandatory destination IP argument, and calculates the optimal MTU using binary search and ping tests.

This tool assists in configuring network parameters for efficient data transmission, thereby potentially reducing packet fragmentation and improving network performance.
This commit is contained in:
Kumi 2024-07-13 18:34:30 +02:00
commit eb57503871
Signed by: kumi
GPG key ID: ECBCC9082395383F

54
mtufinder Executable file
View file

@ -0,0 +1,54 @@
#!/bin/bash
# Function to display help text
display_help() {
echo "Usage: $0 [options] <destination_ip>"
echo
echo "This script determines the optimal MTU size for a given destination IP."
echo
echo "Options:"
echo " -h, --help Show this help text and exit."
echo
echo "Example:"
echo " $0 192.168.1.1"
}
# Check if help is requested
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
display_help
exit 0
fi
# Check for the mandatory destination IP argument
if [[ -z "$1" ]]; then
echo "Error: Destination IP is required."
echo
display_help
exit 1
fi
# Destination IP from command line argument
DESTINATION_IP="$1"
# Function to find the optimal MTU size
find_optimal_mtu() {
local max_mtu=1500
local min_mtu=1200
local optimal_mtu=$max_mtu
while [[ $min_mtu -le $max_mtu ]]; do
local current_mtu=$(( (min_mtu + max_mtu) / 2 ))
if ping -c 1 -M do -s $((current_mtu - 28)) $DESTINATION_IP >/dev/null 2>&1; then
optimal_mtu=$current_mtu
min_mtu=$((current_mtu + 1))
else
max_mtu=$((current_mtu - 1))
fi
done
echo $optimal_mtu
}
# Run the function and print the optimal MTU
optimal_mtu=$(find_optimal_mtu)
echo $optimal_mtu