4
votes

Traditionally, the purpose of a DNS server is to translate human-friendly hostnames into IP addresses. More importantly, it allows for the updating of a service's location (IP address) on the network while retaining the same hostname.

In EC2 however, the public DNS hostname is linked to its public IP address. For example, if the IP address of an instance is 1.2.3.4, its DNS name would be ec2-1-2-3-4.compute-1.amazonaws.com.

As the DNS name is syntactically linked to its IP, it wouldn't serve as a memorable URL nor allow the IP to change independently of its DNS name.

What could be the reason AWS provides the DNS name? What purpose does the DNS name serve in the context of EC2? What can I accomplish with the public DNS hostname that I can't with the public IPv4 address?

1
Just by looking at it you already know its from AWS and its about instance. In contrast, Just by looking at an IP address, you know nothing about it. So DNS makes your source code more readable, without needing to guess what a give IP in a source code represents.Marcin

1 Answers

6
votes

One advantage to using the public hostname instead of the private IP is actually the magic translation to IP address.

If you're inside of AWS and you use the public hostname it will resolve to the private IP, whereas if you're outside of AWS it will resolve to the public IP. Some users will create a CNAME for a specific host that resolves to the public hostname of the EC2. Then when one of their applications connect to this hostname it will route to the private IP, which will avoid all public transit.

Each instance that receives a public IP address is also given an external DNS hostname; for example, ec2-203-0-113-25.compute-1.amazonaws.com. We resolve an external DNS hostname to the public IP address of the instance from outside its VPC, and to the private IPv4 address of the instance from inside its VPC

Outside of this feature it is a regular domain record that is supplied to provide a user with either IP or domain name.