Recently I have started using OpenDNS for my DNS needs, as well as their security tools for providing some simple protection for my home network.
However, that also hit my with a problem that I still operate my home network based off a dynamic IP service from my ADSL provider. My Netgear router comes with a handy tool which can update a DynDNS (http://www.dyndns.com/) however I was struggling with a solution to keep my OpenDNS records updated with my current IP.
This wouldn’t have of been a problem had I been using a PC or MAC (as OpenDNS have tools for that) – however all my clients are Linux, so I was stuck. I did find a part solution in that DNS-O-Matic (https://www.dnsomatic.com/) provides a free service for updating other DNS records, and provides a simple API. So a small script was hacked together to check and update the DNS-O-Matic records.
#!/bin/bashUSER=”Username”PASS=”Password”IP=$(curl -s http://myip.dnsomatic.com/ | egrep -m1 -o ‘[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}’)if [ -r "/home/david/.dnsomatic.txt" ]; thenOLDIP=`cat /home/david/.dnsomatic.txt`if [ "$OLDIP" = "$IP" ]; thenecho “$OLDIP is currently up-to-date”exit 0elseecho $IP > /home/david/.dnsomatic.txtRETURN=$(curl -s https://${USER}:${PASS}@updates.dnsomatic.com/nic/update?)echo “Return message from DNS-O-Matic : ” $RETURNfifi
After that a small entry into the crontab to schedule the script to run several times a day – and again I am a happy man.
Nice article, but it won’t appear to work with my router ip address, any ideas?
when trying out your script, i get:
egrep: ‘[0-9]1.[0-9]1.[0-9]1.[0-9]3’: No such file or directory
can you help?
tnx alf
Hmm, not used this script for a while – as my router now has an option to automatically update with my IP. Will try and test it out again for you though.