13

Seems the Public DNS, e.g. ec2-x-x-x-x.compute-1.amazonaws.com will be changed when you stop or terminated the instance.

So this mean they have the same life span as the ec2 public IP address, so why should I use this public DNS? They are not easy to remember, and rather meaningless..

5
  • 1
    In certain cases, where you can setup only CNAME records., the public DNS comes into play. May 15, 2012 at 17:18
  • @CS3, you can do it by using A record to the instance. Since both the public IP and DNS have the same lifespan.
    – Ryan
    May 15, 2012 at 17:38
  • 'A' Records can be mapped to IP addresses. But if the same machine exposes different services with the same address, CNAMEs can help convey meaningful domain names. ( Eg: ftp.domain.tld, www.domain.tld ). May 15, 2012 at 18:02
  • There is only one difference between the public DNS and public IP. See my answer below. May 15, 2012 at 19:06
  • I have exactly the same question 3 years on . My conclusion... the public DNS is pretty useless. If they had assigned a unique but permanently fixed public DNS (e.g. a guid), I would be able to stop/start my instance, knowing that my SSH and SFTP connections I have already setup will still work. It seems this simple thing is impossible without buying an elastic IP address.. which is a huge waste for an instance which is only started occasionally.
    – Greg Woods
    Dec 21, 2018 at 9:52

4 Answers 4

29

The public DNS name (whether elastic IP address or not) is exactly the same as using the public IP address (elastic IP or not) with the one following important difference:

If you query the public DNS name from outside of EC2, it resolves to the public IP address. If you query the public DNS name from inside of EC2, it resolves to the private IP address.

You can use this trick with or without Elastic IP addresses. I recommend using Elastic IP addresses as it keeps the public DNS name the same even after stop/start or moving your service to another EC2 instance. Because of this, you can always use the public DNS name of the Elastic IP address and it will resolve to the internal IP address of the current instance to which the Elastic IP is associated.

You can extend this by using a CNAME DNS entry where you map your preferred hostname to the external DNS name of the Elastic IP.

Here's an article I wrote about using this feature to save money and speed up network performance with internal EC2 communication without having to keep track of the current internal IP address for each instance on all your other instances: http://alestic.com/2009/06/ec2-elastic-ip-internal

Other than this one difference, I agree that you might as well use the public IP address instead of the public DNS name because:

  1. You save time by not doing a DNS lookup

  2. You avoid any security risks that occasionally arise in the DNS protocol.

so I suppose, in reality, right there are two more differences...

0
7

You'd use the EC2 public address to do things like SSHing into that server, or for interconnecting EC2 instances, or any number of other things.

If you need a consistent address (say to point users at), you'd provision an Elastic Load Balancer or an Elastic IP to sit in front of your instance(s).

Also, within EC2, public DNS resolves to the instance's internal IP, but outside EC2 it resolves to the external IP. This can be useful at times, as communicating between EC2 nodes using the private IP saves you money.

4
  • 1
    Doesnt answer the question asked. Whatever you said, could be done using IP addresses also. May 15, 2012 at 17:20
  • 2
    @Yoga If you don't need it, don't use it. What, exactly, are you going for here?
    – ceejayoz
    May 15, 2012 at 17:40
  • 2
    ceejayoz did answer the question in the third paragraph (DNS resolution inside and outside of EC2). I've expanded on this in my answer which only focuses on this difference. May 15, 2012 at 19:08
  • @EricHammond In fairness, I was editing that in when Yoga posted.
    – ceejayoz
    May 15, 2012 at 19:14
5

Well they only change when you stop the instance. If your instance is going to be long lived you can just point a CNAME to it and it will work. They're not completely useless, they are just transient.

2

You can use Elastic IP's

Here is an article on them

http://aws.amazon.com/articles/1346

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .