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..

Ryan
  • 5,831
  • 24
  • 72
  • 91
  • 1
    In certain cases, where you can setup only CNAME records., the public DNS comes into play. – Shyam Sundar C S May 15 '12 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 '12 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 ). – Shyam Sundar C S May 15 '12 at 18:02
  • There is only one difference between the public DNS and public IP. See my answer below. – Eric Hammond May 15 '12 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 '18 at 09:52

4 Answers4

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...

Eric Hammond
  • 11,163
  • 1
  • 36
  • 56
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.

ceejayoz
  • 32,910
  • 7
  • 82
  • 106
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.

coredump
  • 12,713
  • 2
  • 36
  • 56
2

You can use Elastic IP's

Here is an article on them

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

ckliborn
  • 2,778
  • 4
  • 25
  • 37