Files
Misc-Scripts/update-dns.sh
2025-08-17 19:12:52 -05:00

68 lines
1.7 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
netfile=/etc/netplan/eth0.yaml
elif [ -f /etc/netplan/network.yaml ]; then
netfile=/etc/netplan/network.yaml
elif [ -f /etc/network/interfaces ]; then
netfile=/etc/network/interfaces
else
echo -e "No network configs found\n"
exit 1
fi
# cat ${netfile}
# echo
chmod 0600 ${netfile}
read -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.2.1.2,10.10.10.5/10.2.1.6,10.2.1.5/g' ${netfile}
sed -i 's/127.0.0.1,10.10.10.5/127.0.0.1,10.2.1.6/g' ${netfile}
else
sed -i 's/10.10.10.5,10.2.1.2/10.10.10.10,10.10.10.11/g' ${netfile}
sed -i 's/10.10.10.11,10.10.10.10/10.10.10.10,10.10.10.11/g' ${netfile}
# sed -i 's/127.0.0.1,10.10.10.10,10.2.1.2/127.0.0.1,10.10.10.10/g' ${netfile}
# sed -i 's/127.0.0.1,10.10.10.11,10.2.1.2/127.0.0.1,10.10.10.11/g' ${netfile}
fi
/usr/sbin/netplan apply
else
if [ "${1}" = "offsite" ]; then
sed -i 's/10.2.1.2 10.10.10.5/10.2.1.6 10.2.1.5/g' ${netfile}
else
sed -i 's/10.10.10.5 10.2.1.2/10.10.10.11 10.10.10.10/g' ${netfile}
sed -i 's/10.10.10.11 10.10.10.10/10.10.10.10 10.10.10.11/g' ${netfile}
fi
/usr/sbin/service networking restart
fi
cat ${netfile}
echo -e "${Green}The DNS servers have been updated${Color_Off}"
;;
esac
echo
exit 0