Linode Dynamic DNS

This script uses Linode API Python bindings to update a DNS entry. I use it to keep a DNS entry like home.domain.com updated with my home connection IP address, allowing me easy remote access.

Download

Source code from linode-dyndns.py is distributed in public domain. Feel free to use and modify as needed. Please, share you modifications, it can be useful to others.

Latest version can be found at official mercurial repositories:

hg clone http://src.ultrav.com.br/linode-dyndns/

Pre-requisites

This script uses linode-python module and needs a Linode API key. You can create your API key in profile at Linode panel. You also need IDs from objects you want to change. The following code lists all domains and entries registered in your Linode account:

from linode import api
linode = api.Api('YOURAPIKEY')
for domain in linode.domain_list():
    print domain['DOMAINID'], domain['DOMAIN']
    for record in linode.domain_resource_list(domainid=domain['DOMAINID']):
        print record['TYPE'], record['NAME'], record['TARGET']

You also needs an URI from a web service that prints your IP in plain text. By default script uses a web service hosted on my servers, you can change it to another or host your own with following PHP script:

<?php printf("%s", $_SERVER['REMOTE_ADDR']); ?>

Usage

Create an AAAA entry in your domain. Use list script above to show IDs from your resources. Edit variables in begining of script and run it:

vinicius@ultrav:/usr/local/bin$ ./linode-dyndns.py
2013-07-07 22:48:23 INFO: Registered IP address is 1.2.3.4, setting to 123.192.131.65
2013-07-07 22:48:25 INFO: IP address successfully updated!

Copy script to /usr/local/bin/ and create a crontab entry to run it every 6 hours:

0 */6 * * *  /usr/local/bin/linode-dyndns.py &2>> /tmp/linode-dyndns.log