Linode DDNS updater script
So my domain registrar doesn’t do DDNS (dynamic dns), but Linode have an API to update your DNS records that you have on their name servers, so you can do DDNS with your own domains really easily!
I use my Wifi router with OpenWrt on to run the update script every hour. There are a couple of updater scripts out there, a quick Google will find you some. Below is one I’ve bodged together using a couple I found
##!/bin/sh # modified by jfro from http://www.cnysupport.com/index.php/linode-dynamic-dns-ddns-update-script LINODE_API_KEY=abcde1234#your linode api key DOMAIN_ID=12345#your domain id RESOURCE_ID=67890#your resource id WAN_IP=`curl -s http://whatsmyip.yourdomain` if [ -f $HOME/.wan_ip.txt ]; then OLD_WAN_IP=`cat $HOME/.wan_ip.txt` else echo "No file, need IP" OLD_WAN_IP="" fi if [ "$WAN_IP" = "$OLD_WAN_IP" ]; then echo "IP Unchanged" else echo $WAN_IP > $HOME/.wan_ip.txt echo "Updating DNS to $WAN_IP" curl -sk https://api.linode.com/?api_key="$LINODE_API_KEY"&api_action=domain.resource.update&DomainID="$DOMAIN_ID"&ResourceID="$RESOURCE_ID"&Target="$WAN_IP" fi
I’ve put that script at /root/update-dns.sh , which seems to survive a reboot. You will also need to install curl – this can easily be done though the web interface (System -> Software, search and install curl). I then set up a cron job (again using the web interface ‘System -> Scheduled tasks’) that looks like this
0 * * * * /root/update-dns.sh
That will cause the updater script to run every hour on the hour 24 x 7 x 365.
Finding my internet IP address
Because my Wifi router isn’t directly connected to ‘the internet’ its ip address is a local ip address, so I have put this php script on my linode to get the ip address under a new domain (you could put it anywhere you want, or use any other method you wish to find your internet ip address).
<?php header("Content-type: text/plain"); printf("%s", $_SERVER["REMOTE_ADDR"]); ?>
If you find where I have put my ip address finder script feel free to use it, just don’t hammer it to death and don’t blame me if I decide to move it one day without warning!
Finding your Linode Domain ID and/or Resource ID
This is a little tricky, I’m sure you could once find it from the Linode web interface but I couldn’t find it, so I came up with a quick webpage that uses the Linode API to fetch the Domain IDs and Resource IDs for those domains.
You can find it at http://dev.chrisrogers.me.uk/linode/
To use just enter your Linode API key and click the magic button. Your Linode domain(s) should then appear and you can click the Fetch Resources button to find the resource id. Then just copy the domain id and resource id into the update script and you should be all sorted!