Skip to content

Instantly share code, notes, and snippets.

@hatamiarash7
Last active February 2, 2020 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hatamiarash7/b589990c8fa619e1051e762511843f1d to your computer and use it in GitHub Desktop.
Save hatamiarash7/b589990c8fa619e1051e762511843f1d to your computer and use it in GitHub Desktop.
DNS switching script for Ubuntu server

Just set your configuration path. Examples :

  • /etc/netplan/50-cloud-init.yaml
  • /etc/resolv.conf
#!/bin/sh
file=/etc/netplan/50-cloud-init.yaml
begzar_1=185.55.226.2
begzar_2=185.55.225.25
shecan_1=178.22.122.100
shecan_2=185.51.200.2
complete() {
echo 'Apply cahnges'
netplan apply
echo 'Done'
}
begzar() {
sed -i -e "s/${shecan_1}/${begzar_1}/g" $file
sed -i -e "s/${shecan_2}/${begzar_2}/g" $file
complete
}
shecan() {
sed -i -e "s/${begzar_1}/${shecan_1}/g" $file
sed -i -e "s/${begzar_2}/${shecan_2}/g" $file
complete
}
if [ "$1" = "begzar" ]; then
begzar
elif [ "$1" = "shecan" ]; then
shecan
else
echo 'Please select DNS provider'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment