Dynamic DNS With Your Own Domain Name And Webfaction

I have been moving more of my websites hosting over to my Webfaction account. It has been a good experience overall and the service there is much more powerful than what I get with my GoDaddy hosting account.

Yesterday I found in the support forums a nice little script that allows me to use one of my domain names (or subdomain) and re-direct the DNS settings to my local computer. This way I can remotely connect to my home computer with SSH/HTTP/FTP etc. using a url that I will remember.

This is going to be useful as I am writing some Python Django web applications.

Here’s the script:

import urllib2
import xmlrpclib
import os
currentip = urllib2.urlopen('http://www.whatismyip.org').read()
if not os.path.isfile('lastip'):
    f = open('lastip', 'w')
with open('lastip', 'r') as f:
    lastip = f.read()
if lastip != currentip:
    server = xmlrpclib.ServerProxy('https://api.webfaction.com/')
    session_id, account = server.login('USERNAME', 'PASSWORD')
    server.delete_dns_override(session_id, 'YOURDOMAIN.com')
    server.create_dns_override(session_id, 'YOURDOMAIN.com', currentip, '', '', '', '')
    with open('lastip', 'w') as f:
    print('IP updated to %s' % currentip)
    print('IP not updated')

Once this is run, I can update my router settings to forward the appropriate services to my computer and give the DNS servers enough time to propagate the new entry.

I can now connect to my Home computer using my own domain name. Pretty cool.