Sub topic 9
Private hosted zones for VPC-internal names
This chapter assumes you know what a public hosted zone is, can read a Route 53 change batch, and understand VPC basics such as DNS resolution inside a VPC. A private hosted zone lets you give internal resources friendly names that resolve only from inside your VPCs.
What a private hosted zone does
A private hosted zone (PHZ) is a container for DNS records that Route 53 answers only for queries coming from VPCs you have associated with it. Clients outside those VPCs get no answer from it. The records inside use the same types, TTLs and routing policies as in a public zone.
Typical uses are names such as db.internal.example.com that point at a private IP address, or a name that returns a different answer inside your network than on the internet.
Prerequisites on the VPC
Two VPC settings must be enabled, or the private zone will not resolve:
enableDnsSupportlets the VPC use the Amazon-provided resolver (the Route 53 Resolver at the VPC base address plus two).enableDnsHostnamesis required for private hosted zones to work with the VPC.
Check them before you debug anything else.
Creating a private hosted zone
You create the zone and associate one VPC in the same call. The --vpc option is what makes the zone private.
aws route53 create-hosted-zone \
--name internal.example.com \
--caller-reference "$(date +%s)" \
--vpc VPCRegion=us-east-1,VPCId=vpc-0123456789abcdef0Add records with a change batch, exactly as you would in a public zone:
{
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "db.internal.example.com",
"Type": "A",
"TTL": 300,
"ResourceRecords": [{ "Value": "10.0.1.25" }]
}
}
]
}Save this as db-record.json, then apply it:
aws route53 change-resource-record-sets \
--hosted-zone-id ZONE_ID \
--change-batch file://db-record.jsonAssociating more VPCs
One zone can serve many VPCs, including VPCs in other Regions. Associate an extra VPC with this command:
aws route53 associate-vpc-with-hosted-zone \
--hosted-zone-id ZONE_ID \
--vpc VPCRegion=us-west-2,VPCId=vpc-0fedcba9876543210If the VPC belongs to a different AWS account, the zone owner must first authorize the association with create-vpc-association-authorization. The VPC owner then runs the associate command. The owner can delete the authorization afterward.
Split-horizon DNS
If a private and a public hosted zone have the same name, Route 53 uses the private zone for queries from the associated VPC. This is split-horizon DNS. Inside the VPC, app.example.com can resolve to a private address. Outside, it resolves to the public address.
There is a catch. If the private zone lacks a record that exists in the public zone, the VPC resolver returns NXDOMAIN. It does not fall back to the public zone. Copy every name you still need inside the VPC into the private zone.
Common errors
| Symptom | Likely cause |
|---|---|
| Name does not resolve in the VPC | `enableDnsSupport` or `enableDnsHostnames` is off, or the VPC is not associated |
| NXDOMAIN for a public name inside the VPC | Split-horizon zone is missing that record |
| Name resolves on the internet but you expected it hidden | Record was created in the public zone, not the private one |
| Cross-account association fails | The authorization was not created first |
Test from an instance inside the VPC with dig db.internal.example.com. The same query from your laptop should fail.
For on-premises networks to resolve these names, you need Resolver endpoints, covered in a later chapter.
Exercise
An instance in a VPC associated with a private zone example.com queries www.example.com. The record exists only in your public zone of the same name. What does the instance receive, and how do you fix it?
Show answer
It receives NXDOMAIN, because the private zone answers for the whole name and Route 53 does not fall back to the public zone. Fix it by creating a www.example.com record in the private hosted zone.
Exercise
Which two VPC attributes must be enabled for a private hosted zone to resolve, and which command adds a second VPC to an existing zone?
Show answer
enableDnsSupport and enableDnsHostnames. Use aws route53 associate-vpc-with-hosted-zone with the zone ID and the --vpc option.