Updating dynamic DNS on Amazon EC2
published Oct 10, 2007
There are two steps to updating your dynamic DNS.
- Get your IP address
- Tell your dynamic DNS provider the IP address
On EC2, things are a little different from your standard hosting setup. Here’s how you get dynamic DNS working on EC2.
Getting your IP address
See this Amazon article about getting data about your instance for more information about instance data.
To make a long story short, to find out the public IP address of your EC2 instance, you make a http get request to
Note that this has to be done from your EC2 instance.
Try it out from the command line. Log-in to your EC2 instance and type
From Ruby, it’s just as simple. Cut and paste this into a script, or just run it in
Updating your DNS with your dynamic DNS provider
The following instructions assume that you want to use ez-ipupdate to update your DNS. If you don’t want to, or if ez-ipupdate doesn’t support your dynamic DNS provider, it should be relatively simple to get it working anyways.
If you’re running Ubuntu, then install it using
sudo aptitude install ez-ipupdate or
sudo apt-get install ez-ipupdate. On a RedHat installation
sudo yum install ez-ipupdate.
You can also install from source, of course.
When you install it using
apt-get, it will ask you for some configuration info. This won’t work on EC2, so ignore the configuration and use the script below instead.
Installing the Ruby script
Here’s the script:
If you’re running an ec2-on-rails instance, place the script in
Otherwise, place it somewhere in your path and create a shell script to call it in
Make sure that both update_dynamic_dns.rb and the init script are executable.
The config file
Create a file called
/etc/ez-ipupdate/dynamic_dns.yml. It should look something like this
To update multiple hosts, put them all on the host entry, separated by commas.
Testing and debugging
Test out the script:
- run it:
- Wait a couple of minutes.
- ping your domain name from a local machine and make sure that it points at the right IP address.
Hopefully that works for you. Let me know if you have any problems, comments or suggestions.