ec2: assign cname to elastic ip

6,572

Solution 1

CNAME resource records specify a domain as an alias of another canonical domain name. As such, it cannot point to an IP address.

A and AAAA records define the canonical name and point to IP addresses. CNAMEs must reference those.

Create an A record for allehotelsinparijs.nl that points to 79.125.111.73. Then create a CNAME record for www.allehotelsinparijs.nl that points to allehotelsinparijs.nl.

Then in your webserver on the EC2 server, create a vhost for allehotelsinparijs.nl that does a 301 redirect to www.allehotelsinparijs.nl. Details of how to do this are out of scope for this question, but there are many examples to be found here on Serverfault and elsewhere.

Solution 2

You may prefer to make the CNAME point to the AMAZON Elastic IP's DNS name.

eg. allehotelsinparijs.nl as CNAME to ec2-79-125-111-73.compute-1.amazonaws.com (may NOT be the actual amazon hostname)

The benefit from doing this is that externally your hostname will resolve to a public IP, but internal to Amazon, it will resolve to an PRIVTE IP for your instance.

(this will make calls to your site more direct and possibly cheaper when inside AWS)

Share:
6,572

Related videos on Youtube

Gbrits
Author by

Gbrits

Updated on September 18, 2022

Comments

  • Gbrits
    Gbrits over 1 year

    Couldn't find this exact same question so here it goes:

    I'm trying to setup a CNAME record to an elastic ip linked to a ec2-instance, but this fails. When deassociating the elastic-ip from the instance and linking it to the public dns of the instance it works as expected.

    Isn't it allowed to point a CNAME to a ip-address (instead of a dns-name ) ?

    btw: i'm not using an A-record, because I already us this to redirect the naked domain (e.g: example.com) to www.example.com using the free service: http://wwwizer.com/

    EDIT: more explicitly: I'd like both www.allehotelsinparijs.nl to point to 79.125.111.73 which is an amazon elastic-ip (although I think that doesn't matter for this discussion) . Moreover I want allehotelsinparijs.nl redirect to www.allehotelsinparijs.nl

    Any other way to to this? Since from an answer below it seems that indeed a cname can't link to an ip-address

    • Gbrits
      Gbrits about 12 years
      I edited my question to answer you comment
    • EEAA
      EEAA about 12 years
      I edited my answer with more details on how to accomplish what you're seeking.
  • EEAA
    EEAA about 12 years
    Thanks, Jeff...that last sentence was in my head, but apparently didn't make it out through my fingers. :)
  • Gbrits
    Gbrits about 12 years
    yep that would definitely solve it as well. I totally missed that I could refer to an elastic ip by dns name.. thanks