Point a subdomain to an EC2 instance without elastic IP
The IP address of an AWS EC2 instance is dynamically assigned when it launches. Allocating an elastic IP to the instance prevents the address from changing, but you might be in a situation in which you can’t or don’t want to use this service. In this case, it might be handy to have a name that always points to the current IP of the instance.
What we are looking for is dynamic DNS, and you only need two things: a DNS provider that supports it and a client to periodically send it the current public IP of the system. One of such clients is ddclient
, which is compatible with many dynamic DNS providers and is packaged in many Linux distributions. I’ve been using it with Google Domains for years, and it works well.
Install it and configure it on your EC2 instance. On Ubuntu and Debian, it is just a sudo apt install ddclient
away, and you’ll be prompted with an easy setup process. You’ll need to configure a name on your DNS provider and get the necessary credentials to input in the wizard.
And, simple as that, you have a subdomain that always points to your instance. Obviously, after launching the EC2 instance you’ll need to wait for DNS propagation. In my experience it takes a few minutes.
Oh, and of course, you can use ddclient
not only on AWS EC2, but on any Linux system with a dynamic public IP address.