Most people run a home server behind a router. If you have a dynamic IP, this could be very annoying. The server don’t know about the public IP (of the router), the router sometime don’t update the dinamic DNS. The OpenDNS settings are not valid anymore if your IP chages.
To avoid all these issues, this night I wrote a very cool script that updates DynDNS and OpenDNS at the same time.
DynDNS allows me to have a domain like my-server.dyndns.org with a dinamic IP. OpenDNS instead after a free registration and after that I added its DNS IP to my DHCP router configuration, it offers a safe browsing to my network users protecting them from several internet threats like phishing, adult sites ecc..
My server runs this script every hours via cron.
#! /bin/bash
user=MYUSER
password=MYPASSWORD
hostname=MYDNS.MYDNS.ORG
#wildcard allowed values are NOCHG, Y, N
wildcard=NOCHG
mx=NOCHG
# Y=Yes, use it as my primary mail relay. N=No, use it as backup MX record.
backmx=NOCHG
#current IP
currentIP=$( curl -s http://checkip.dyndns.org/ | grep -o “[[:digit:].]\+” )
#check
if [ "$currentIP" != "$(cat lastIP)" ]; then
echo IP changed to $currentIP
echo “$currentIP” > lastIP
#update OpenDNS
/usr/bin/curl -m 60 -u $user:$password ‘https://updates.opendns.com/account/ddns.php?’
#update DynDNS
curl -v -k -u $user:$password “https://members.dyndns.org/nic/update?hostname=$hostname&myip=$currentIP&wildcard=$wildcard&mx=$mx&backmx=$backmx”
else
echo IP not changed. It is still $currentIP
fi
