How does one point a domain to a load balancer that doesn't have a stable IP?

34,422

Solution 1

You can use an Alias record like described in http://aws.amazon.com/route53/faqs/:

Additionally, Route 53 offers ‘Alias’ records (a Route 53-specific virtual record). Alias records are used to map resource record sets in your hosted zone to Elastic Load Balancing instances. Alias records work like a CNAME record in that you can map one DNS name (mydomain.com) to another ‘target’ DNS name (elb1234.elb.amazonaws.com). They differ from a CNAME record in that they are not visible to resolvers. Resolvers only see the A record and the resulting IP address of the target record.

Next you can cname the domain like domain.com to www.domain.com using a CNAME(after you've pointed it using the Alias record), like:

www.domain.com CNAME TO domain.com

Also please note that in order to do this you'll need to move your zone to route53 so to do the Alias record. Most of the DNS providers unfortunately don't offer the ability to make such records for the domain name.

Solution 2

From the AWS info page on Elastic Load Balancing:

Traffic to the DNS name provided by the Elastic Load Balancer is automatically distributed across your load balanced, healthy Amazon EC2 instances.

So in essence, Amazon provides you with a DNS name to map your records to. This would be using a CNAME record as opposed to an A record. The DNS name of the load balancer should not change therefore you never have to deal with IPs which as you point out might change.

EDIT:

AWS has always supported direct CNAME links to subdomains and wildcard subdomains for a root domain with simply CNAME records. So essentially it looks something like:

www.mydomain.com -> my-aws-01-elb.aws.amazon.com

Then for your root level domain you have two options, either setup DNS forwarding with your DNS host provider so that mydomain.com -> www.mydomain.com or utilize Amazon's Route 53 service to host your entire DNS zone and let them manage and setup the required records to get root-level domain support.

If you don't need root domain level support and using a subdomain such as sub.mydomain.com or www.mydomain.com then you can use simple CNAME records for everything.

Share:
34,422
Elver Loho
Author by

Elver Loho

Updated on September 18, 2022

Comments

  • Elver Loho
    Elver Loho over 1 year

    I'm trying to point mydomain.eu to an AWS load balancer, which, by its nature, does not have a stable IP, so I think I'm supposed to point the A record to a subdomain at Amazon, but as far as I can tell the A record can only be an IP address, so I'm terribly confused at the moment.

    What would the zone file look like for mydomain.eu where the A record and the www subdomain both point to, let's say, loadbalancer.mydomain.aws.com?

    • Admin
      Admin over 11 years
      Can you clarify if you are using Route 53 as your DNS provider or your own external provider?
  • Logic Wreck
    Logic Wreck over 11 years
    If you are to use the zone name record, like you have zone abc.com, then a CNAME won't work and you will have to use and Alias record as stated in my answer in order to point abc.com to the ELB.
  • Logic Wreck
    Logic Wreck over 11 years
    If you have a domainname that you need to point to the ELB, and it's similar to the zonename name, then you need to use an Alias record in order to point this domain to the ELB rather then a CNAME as a CNAME won't work in this case.
  • Logic Wreck
    Logic Wreck over 11 years
    Actually he says the next: where the A record and the www subdomain both point to, let's say, loadbalancer.mydomain.aws.com - please check thus my update. if he'll want to point the domain itself he'll have to use the Alias record as stated. Also please note that most DNS providers don't allow CNAMEs for the domain name, only A records are allowed.
  • Logic Wreck
    Logic Wreck over 11 years
    Well for instance godaddy doesn't and from what I've seen in my practice as a sysadmin a lot of people host their DNS zones there.
  • Steve Townsend
    Steve Townsend over 11 years
    godaddy is hardly a gold standard…
  • Logic Wreck
    Logic Wreck over 11 years
    I agree, godaddy is not a very good choice, but still many people do host their DNS,sites etc. there
  • Elver Loho
    Elver Loho over 11 years
    This is the approach I ended up going with and it works perfectly. Thanks! :)
  • Osama Jilani
    Osama Jilani almost 11 years
    What do you mean by "cname the domain like domain.com to www.domain.com using a CNAME". Is this domain management or Route 53?
  • Ramesh Chand
    Ramesh Chand over 6 years
    in my case i have pointed cname and the domain example.com not working however example.com working fine please suggest me how i can make working example.com.
  • Randy L
    Randy L over 5 years
    ALIAS is some made-up stuff, annoying
  • user2902302
    user2902302 over 4 years
    Note: Route53 is the default choice in the AWS context, but some other DNS providers also offer ALIAS records as a feature now.