Today I want to talk about how we can use our company-specific domain names for the hostnames that are assigned to our EC2 instances inside our VPCs, rather than the default region-specific domain name that AWS uses by default when assigning hostnames to the EC2 instances.
Scenario
Imagine that you have an existing corporate network on-premise that you now want to extend to AWS. You create a VPC in the region closest to your user base. You then connect your corporate network with your AWS VPC using VPN / Direct Connect. All your connected devices on your corporate network use a specific domain name, say the name of the company is ‘XYZ enterprise’ and so the company domain could be something like ‘xyz.com’. A connected computer that belongs to an employee named Andrew could have a hostname like ‘andrew-pc.xyz.com’.
Now, you want to reuse this same domain name for the EC2 instances that you are going to provision inside the AWS VPC. But, by default AWS VPCs use region-specific domain names for assigning the hostnames for the EC2 instances that are provisioned inside that VPC. How can you change this behaviour to assign the EC2 instance hostname using your own companies domain name? Continue reading to figure it out!
Default AWS VPC Domain Names
By default when we launch EC2 instances inside the default VPC or custom VPCs in our AWS accounts, they get assigned public DNS hostnames (if the ‘enableDnsHostname’ setting is turned on inside the VPC) and also private DNS hostnames which specifically are based on the default DHCP option sets that are assigned to the VPCs.
The public DNS name resolves to the public IP address of the EC2 instances when it is used from outside the VPC and the private DNS hostname resolves to the private IP address of the EC2 instance when used from inside the VPC. Inside the VPCs we need to turn on ‘enableDnsSupport’ and ‘enableDnsHostname’ settings for the domain names to get assigned to EC2 instances. By default, the EC2 instances are assigned private and public hostnames using the following pattern:
Internal: