Files
Misc-Scripts/update-dns.sh
2024-03-12 10:14:52 -05:00

65 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
if [ -d /opt/idssys/defaults ]; then
source /opt/idssys/defaults/colors.inc
source /opt/idssys/defaults/default.inc
else
source /dev/stdin <<< "$(curl -sL http://go.scity.us/colorsinc)"
source /dev/stdin <<< "$(curl -sL http://go.scity.us/defaultinc)"
fi
if [ -f /etc/netplan/eth0.yaml ]; then
cat /etc/netplan/eth0.yaml
netfile=/etc/netplan/eth0.yaml
elif [ -f /etc/netplan/network.yaml ]; then
cat /etc/netplan/network.yaml
netfile=/etc/netplan/network.yaml
elif [ -f /etc/network/interfaces ]; then
cat /etc/network/interfaces
netfile=/etc/network/interfaces
else
echo -e "No network configs found\n"
exit 1
fi
echo
read -n 1 -p "Do you wish to continue changing the DNS? (Y/n) " choice
case "$choice" in
[Nn])
echo -e "${Green}The DNS servers have NOT been updated${Color_Off}"
exit 0
;;
* ) if [ -f /etc/netplan/eth0.yaml ] || [ -f /etc/netplan/network.yaml ]; then
if [ "${1}" = "offsite" ]; then
sed -i 's/10.10.10.10,10.10.10.11/10.2.1.5,10.2.1.6,10.10.10.5/g' ${netfile}
sed -i 's/10.2.1.2,10.10.10.5/10.2.1.5,10.2.1.6,10.10.10.5/g' ${netfile}
sed -i 's/127.0.0.1,10.10.10.10/10.2.1.5,10.2.1.6,10.10.10.5/g' ${netfile}
else
sed -i 's/10.10.10.10,10.10.10.11,10.2.1.2/10.10.10.5,10.2.1.2/g' ${netfile}
sed -i 's/10.10.10.10,10.10.10.11/10.10.10.5,10.2.1.2/g' ${netfile}
fi
/usr/sbin/netplan apply
cat ${netfile}
else
if [ "${1}" = "offsite" ]; then
sed -i 's/10.10.10.10 10.10.10.11/10.10.10.10 10.10.10.11 10.2.1.2/g' ${netfile}
else
sed -i 's/10.10.10.10 10.10.10.11 10.2.1.2/10.10.10.5 10.2.1.2/g' ${netfile}
sed -i 's/10.10.10.10 10.10.10.11/10.10.10.5 10.2.1.2/g' ${netfile}
fi
/usr/sbin/service networking restart
cat ${netfile}
fi
echo -e "${Green}The DNS servers have been updated${Color_Off}"
;;
esac
echo
exit 0