Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am setting up a server on EC2 that will be used by people that will be freaked out when they see ec2-111-111-111-111.compute-1.amazonaws.com in the URL bar. I know this would be solved by using an A record rather than a CNAME, yet Amazon's documentation says to use a CNAME.

What happens if I use an A record? I've seen some tutorials on the web saying do it, but I also need my website to be reliable.

The website is just running using one instance, and will probably only run using one instance, so I don't think it matters to have multiple instances talk to each other.

share|improve this question
1  
That shouldn't change with a CNAME or A record. Either way the browser shows the hostname the user typed, unless you're redirecting in your app to the canonical name of the server. If you're doing that, well, stop! :) –  Bill Weiss Feb 5 '10 at 1:01
    
Better question, why is it resolving to the different URL then? I thought it was because it was a CNAME –  Canuk Feb 5 '10 at 1:13

4 Answers 4

up vote 11 down vote accepted

Simplified version: A records point to IP addresses. CNAME's point to other A records.

You could use an A record, but for this you should have a highly available IP address for your EC2 instance. Amazon calls this product "Elastic IP Addresses".

If you set up a CNAME to an A record that Amazon manages, then Amazon has control over a layer of indirection. For example, after a server failure, Amazon could use this to change the A record to a new IP address. This way Amazon could get the service to work again, and you would not have to change anything.

Generally speaking, it's a good practice to use 2 DNS entries, an A record for the specific server, and CNAME's for the services it provides such as "www.". This way, you have a clean separation between hardware and services, and that makes administration easier in many cases.

So, if you're not paying for "Elastic IP Addresses", then you should use a CNAME to the A record Amazon set up for you, i.e. a CNAME for "www.yourdomain.com" pointing to "ec2-111-111-111-111.compute-1.amazonaws.com.".

share|improve this answer
1  
Thanks for the answer. I do have an Elastic IP, however, Amazon's documentation says to not have A records point to that elastic IP, but to use a CNAME instead. For some reason, when I setup a CNAME to point to "ec2-111-111-111-111.compute-1.amazonaws.com." it still resolves to ec2-111-111-111-111.compute-1.amazonaws.com in the address bar, rather than just staying ec2.example.com. –  Canuk Feb 6 '10 at 18:39
    
@Canuk: That doesn't really make sense to me. Could it be a HTTP level error, i.e. is your web server sending a HTTP redirect to the Amazon address or something... You could try looking at the sequence via rexswain.com/httpview.html . If that doesn't help, write the real hostnames here, and we can take a look at it. –  Jesper Mortensen Feb 6 '10 at 23:41
    
turns out it was a configuration error on the server. Thanks for your help. I did leave it as a CNAME to have the benefit of having Amazon control the layer of indirection. –  Canuk Jun 29 '11 at 23:40

They'll never see ec2-111-111-111-111.compute-1.amazonaws.com with a CNAME record. If going to your CNAMEed domain redirects to the amazonaws.com URL, it's not due to it being a CNAME, it's something your app or web server is doing.

share|improve this answer

The reason to use a CNAME record is so that the site is accessible from both inside and outside ec2.

For example, take ping. If you ping c2-111-111-111-111.compute-1.amazonaws.com externally it will resolve to 111.111.111.111 but internally to a 10.0.0.0/8 address. However, if you ping 111.111.111.111 it won't be available internally.

share|improve this answer

The ec2-*.amazonaws.com host names resolve to different IP addresses depending on whether you are resolving them externally from the Internet, or internally from another EC2 instance.

This means that if you have two EC2 servers—say, a database server and a web server—your web server would see the database server at an internal 10.x.x.x IP address, while from the outside world, you’d see the web server at a regular non-private IP address. (Of course, you wouldn’t really want a database server to be visible from the outside world, but this is just a handy example.)

If you use an Elastic IP address, you have a known permanent IP address and it should be okay to use an A record to point to it. If you don’t have an Elastic IP (and why not, they’re free), it seems like you’d want to use the CNAME in case Amazon changes your IP address.

But if you have multiple servers, I’d still go with the CNAME so that you get the magic internal/external IP address resolution.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.