Dynamic DNS with EC2 and ZoneEdit

There seems to be a lot of questions on how to set up dyndns with EC2. It is fairly easy to do but I haven't seen anyone put everything together to do it yet so I figured I would write a little example using ZoneEdit. I picked ZoneEdit because it lets you sign up and host 5 domains for free.

First you need to sign up for a free ZoneEdit account and add your domain. I'll assume you can do this. Don't forget to change your domain to point to the ZoneEdit DNS servers.

To find out more about how the following script works read: ZoneEdit's dynamic DNS information.

I think it is nice to assign an instance its public hostname when it starts so I'm going to use the instance metadata facility to pull the hostname information.

Stick the following script in your local startup script (make sure you replace the username and password with your own ZoneEdit username and password):

wget -q -O /tmp/user-data.out http://169.254.169.254/1.0/user-data
HN=`cat /tmp/user-data.out`
rm -f /tmp/user-data.out
wget -q -O - --http-user=<username> --http-passwd=<password> "http://dynamic.zoneedit.com/auth/dynamic.html?host=$HN" > /dev/null 2> /dev/null
hostname $HN

Then start your instance like this:

ec2-run-instances ami-2bb65342 -k gsg-keypair -d "test03.example.com"

Sometimes you may have to give ZoneEdit a few minutes to get your domain updated but soon after boot the node will be accessible by the name you have given it.

Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *