Skip to content

Instantly share code, notes, and snippets.

@hasanparasteh
Last active January 18, 2022 18:16
Show Gist options
  • Save hasanparasteh/2fb9e5fc936365038884cd6b5a871bec to your computer and use it in GitHub Desktop.
Save hasanparasteh/2fb9e5fc936365038884cd6b5a871bec to your computer and use it in GitHub Desktop.
Fix MTU size in ArvanCloud servers permanently
#!/bin/sh
# Root access?
[ "$UID" -eq 0 ] || exec sudo bash "$0" "$@"
# set tab size to 4 spaces
tabs 4
echo "Enter your network name: "
read NETPLAN_NAME
echo "Enter pereferd mtu size: "
read NETPLAN_MTU
MAC_ADDR=$(ip addr show | grep -A1 'eth0:' | awk 'FNR==2 {print $2}')
echo "Starting to configure netplan..."
echo "Your network name is $NETPLAN_NAME and mac address is $MAC_ADDR"
NETPLAN_CONFIG=$(cat <<-END
network:\n
\tversion: 2\n
\tethernets:\n
\t\t$NETPLAN_NAME:\n
\t\t\tdhcp4: true\n
\t\t\tmatch:\n
\t\t\t\tmacaddress: $MAC_ADDR\n
\t\t\tmtu: $NETPLAN_MTU\n
\t\t\tset-name: $NETPLAN_NAME
END
)
echo $NETPLAN_CONFIG > /etc/netplan/50-cloud-init.yaml
echo 'network: {config: disabled}' > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
# safe replace of tabs with spaces
expand --tabs=4 /etc/netplan/50-cloud-init.yaml > /etc/netplan/50-cloud-init.yaml.spaces
mv /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.tabs
mv /etc/netplan/50-cloud-init.yaml.spaces /etc/netplan/50-cloud-init.yaml
echo "MTU is configured..."
echo "Configuration is: \n"
cat -n /etc/netplan/50-cloud-init.yaml
echo "\n\nRun below commands to apply the changes..."
echo "\r\rsudo netplan apply -d"
echo "\r\rsudo systemctl restart systemd-networkd.service"
echo "\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment