David Baldaro's home on the Internet
david@baldaro.me.uk

Automatical updating OpenDNS using DNS-O-Matic from a script

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/bash 
USER=”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" ]; then   
  OLDIP=`cat /home/david/.dnsomatic.txt`   
  if [ "$OLDIP" = "$IP" ]; then     
    echo “$OLDIP is currently up-to-date”     
    exit 0   
  else     
    echo $IP > /home/david/.dnsomatic.txt     
    RETURN=$(curl -s https://${USER}:${PASS}@updates.dnsomatic.com/nic/update?)     
    echo “Return message from DNS-O-Matic : ” $RETURN   
  fi 
fi  
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.

3 Comments to “Automatical updating OpenDNS using DNS-O-Matic from a script”

  1. Nice article, but it won’t appear to work with my router ip address, any ideas?

  2. 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.

Leave a Reply

Disclaimer

The opinions expressed in this website are those of the author, and do not reflect in any way those of the his employer of which any association for which he is associated with.
QR Code Business Card