I’ve just changed my domain dns service to FreeDNS and with the help of a little bash script, it will update from my Synology NAS which means I don’t have to have my box up all the time. This is great! I’ve setup cron to run it every 6 hour. For more information about cron you can check wikipedia.
#minute hour mday month wday who command
0 */6 * * * root /usr/bin/dnsactual.sh
Now that we have a cron working to run the script every 6 hours, let’s write the script. I’ve modified a bash script from FreeDNS that updates the dynamic ip if need be. Here is the code.
##############################################################################
# application name: dnsactual
# other files: dnsactual.conf (keeps the last updated ip)
# dnsactual.log (register date & time of the actualization)
# Author: Ernest Danton
# Date: 01/29/2007
# Modified by Benoit Beauchamp on 8/8/2010
##############################################################################
if test -f /etc/freedns/dnsactual.conf
then
CacheIP=$(cat /etc/freedns/dnsactual.conf)
fi
#echo $CacheIP
/opt/bin/wget http://freedns.afraid.org/dynamic/check.php -o /dev/null -O /tmp/ip
CurreIP=$(cat /tmp/ip | grep Detected | cut -d : -f 2 | cut -d '<' -f 1 | tr -d " ")
#echo $CurreIP
if [ "$CurreIP" = "$CacheIP" ]
then
# Both IP are equal
echo "Update not required..."
else
# The IP has change
echo "Updating http://free.afraid.org with " $CurreIP
wget http://freedns.afraid.org/dynamic/update.php?CHANGEMETOTHEPROPERKEY -o /dev/null -O /dev/stdout
echo `date` "Updating log with IP " $CurreIP >> dnsactual.log
fi
rm -f /etc/freedns/dnsactual.conf
echo $CurreIP > /etc/freedns/dnsactual.conf
You’ll have to change it according to your setting but the first thing that you will need to do in order to have it run properly is to make sure you have wget install. You can locate wget with the following command
> find / -name "wget"
/usr/syno/bin/wget
/opt/bin/wget
I used the opt/bin/wget in the script. You will also need to change the CHANGEME to your key that you can find on FreeDNS website located at http://freedns.afraid.org/dynamic/ under the Direct URL link.
So now that we have cron and a script installed. I can now connect to my subdomain of my choice from anywhere. It’s good to be able to call home without too much fuss. Easy isn’t it?