Using DDclient for dynamic DNS on Amazon EC2

When using Amazon EC2, IP addresses of your instances are assigned dynamically when launched. If you are bring up and down instances frequently, it can be helpful to use a dynamic DNS service so you can use a consistent hostname for your instance, event if it's IP address changes.

DDclient is a command line tool which works with a variety of dynamic DNS providers and is available pre-packaged on many Linux distributions (e.g. apt-get install ddclient on Ubuntu 14.04). DDclient can use various methods to look up the IP to use. In this case, I want DDclient to use the EC instance's external IP address. One method is to look up the IP from a specified web page, usually used with a site like whatismyip.com or checkip.org.

On an EC2 instance, we have another option: Instance Metadata. You can fetch all kinds of useful metadata about an EC2 instance using a REST API served from http://169.254.169.254/latest/meta-data/. To retreive the public IP address (IPv4) of a running EC2 instance, fetch http://169.254.169.254/latest/meta-data/public-ipv4 from that instance. To use this with DDclient, include the following line in your DDclient config file:

use=web, web=http://169.254.169.254/latest/meta-data/public-ipv4
Contents © 2010-2017 Michael Rabbitt - Powered by Nikola