Sub topic 4
Delegating your domain to Route 53 name servers
This chapter assumes you can create a public hosted zone, read an NS record, and run dig and the AWS CLI. Creating a hosted zone does not make Route 53 answer queries for your domain. Delegation is the step that does, and most "my domain doesn't work" problems after a migration are delegation problems.
What delegation means
DNS is a hierarchy. The root zone knows who runs com. The com zone knows who runs example.com. Each level hands the question down by publishing NS records (name server records) that name the servers responsible for the level below. That hand-off is called a delegation.
A resolver only reaches your hosted zone if the parent zone contains NS records pointing at the name servers Route 53 assigned to it. For example.com, the parent is the com zone, which is run by the registry. You can't edit it directly. You ask your registrar to change it, and the registrar passes the change to the registry.
Two sets of NS records are involved, and they are easy to confuse:
| Location | Who controls it | What it does |
|---|---|---|
| NS records in the parent zone (`com`) | The registry, changed through your registrar | Tells resolvers where to find your zone. This is the delegation. |
| NS record at the apex of your hosted zone | Route 53 creates it | Authoritative answer from your own zone. Should match the delegation. |
A domain works only when both sets name the same servers, and those servers are the ones actually hosting your zone.
The middle step is the delegation. If the com servers return the wrong NS records, or none, the resolver never reaches Route 53, and nothing inside your hosted zone matters.
Finding your four name servers
Each public hosted zone gets four name servers, spread across four top-level domains (.com, .net, .org and .co.uk) so that a problem with one TLD does not take the zone offline. The names look like ns-123.awsdns-45.com.
Create the zone and read its NS record, as in the previous chapter:
aws route53 create-hosted-zone \
--name example.com \
--caller-reference "$(date +%s)"
aws route53 list-resource-record-sets \
--hosted-zone-id ZONE_ID \
--query "ResourceRecordSets[?Type=='NS']"You can also read the assigned servers directly from the zone's delegation set:
aws route53 get-hosted-zone \
--id ZONE_ID \
--query "DelegationSet.NameServers" \
--output textThe output is the list of four hostnames, with no trailing dots. Copy all four. Registrars usually accept them in any order, and some accept a trailing dot while others reject it.
Delegating a domain registered elsewhere
Log in to your registrar and find the setting called "name servers" or "custom DNS". Replace the existing values with the four Route 53 names. Some registrars show only two or three input boxes by default, so look for an "add" link. Using fewer than four removes redundancy.
Before you switch, do these three things:
- Recreate every record first. Once the delegation changes, Route 53 answers for the domain. Any record that exists at the old provider but not in Route 53 starts returning NXDOMAIN (name does not exist). This includes MX and TXT records for email, which are easy to forget.
- Lower the TTL at the old provider. Resolvers that cached the old answers keep them until the TTL expires. Lowering the TTL a day or two beforehand shortens the overlap.
- Check DNSSEC. If the old provider signs the zone, a DS record exists at the registry. Remove the DS record before changing name servers. Otherwise validating resolvers reject the unsigned Route 53 answers and the domain appears to be down for those users only.
Delegating a domain registered with Route 53
When you register a domain with Route 53, the registrar part is Route 53 too. Registration normally creates a hosted zone and points the domain at it automatically. If you created a second hosted zone later, or deleted and recreated the first one, the domain still points at the old zone's name servers. Update them with the registrar API, which lives only in us-east-1:
aws route53domains update-domain-nameservers \
--region us-east-1 \
--domain-name example.com \
--nameservers \
Name=ns-123.awsdns-45.com \
Name=ns-456.awsdns-78.net \
Name=ns-789.awsdns-12.org \
Name=ns-1012.awsdns-34.co.ukThe command returns an operation ID. Check progress with aws route53domains get-operation-detail --region us-east-1 --operation-id OPERATION_ID. In the console, the same setting is under Registered domains, then Add or edit name servers.
Verifying the delegation
Do not trust the registrar's web page. Ask the DNS itself. The first check shows what the public DNS currently returns:
dig NS example.com +shortIf the output lists the four awsdns servers, the delegation is visible to your resolver. If you still see the old provider's servers, either the change has not been made at the registry or your resolver has cached the old answer.
To see what the parent zone says, bypassing most caching, query a com server directly. Names such as a.gtld-servers.net are the real com servers:
dig @a.gtld-servers.net example.com NS +norecurseThe NS records appear in the AUTHORITY section of the reply, not the ANSWER section, because the com server is giving a referral rather than an authoritative answer. This is the delegation exactly as the registry publishes it.
dig +trace walks the whole chain from the root, as the diagram shows:
dig +trace www.example.com ARead each hop. The last hop should come from one of your Route 53 servers and should contain your A record. If the trace ends at a server that returns REFUSED or an empty answer, the delegation points to a server that does not host your zone.
How long delegation takes
Registries publish NS changes within minutes to a few hours, but the NS records at the registry usually have a TTL of 48 hours (172800 seconds). A resolver that cached the old delegation can keep using it for up to that long. In practice, different users see the change at different times during the first one or two days. During that window, both the old and new providers may receive traffic, which is why step 1 above (recreate every record first) matters.
Delegating a subdomain
Delegation also works one level down. You may want a team to manage dev.example.com in its own hosted zone, possibly in another AWS account. Create a hosted zone named dev.example.com, then add an NS record in the parent zone (example.com) pointing to the child zone's four name servers:
{
"Comment": "Delegate dev.example.com to its own hosted zone",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "dev.example.com",
"Type": "NS",
"TTL": 172800,
"ResourceRecords": [
{ "Value": "ns-11.awsdns-22.com" },
{ "Value": "ns-333.awsdns-44.net" },
{ "Value": "ns-555.awsdns-66.org" },
{ "Value": "ns-777.awsdns-88.co.uk" }
]
}
}
]
}Apply it to the parent zone with aws route53 change-resource-record-sets --hosted-zone-id PARENT_ZONE_ID --change-batch file://delegate-dev.json. Replace the four values with the ones from the child zone. Do not leave records for dev.example.com in the parent zone besides the NS record. Once the delegation exists, the parent's resolvers never consult them, which makes them misleading.
Reusable delegation sets
By default, every new hosted zone gets a random set of four name servers. A reusable delegation set is a fixed set of four servers that you can assign to many zones. It has two uses:
- Vanity name servers. You create records such as
ns1.example.comthat point to the four IP addresses, and register them as glue records at the registrar. Your customers then seens1.example.cominstead of anawsdnsname. - Stable delegation. You can delete and recreate a zone, or move many domains in bulk, without touching the registrar each time.
aws route53 create-reusable-delegation-set \
--caller-reference "$(date +%s)"
aws route53 create-hosted-zone \
--name example.org \
--caller-reference "$(date +%s)" \
--delegation-set-id DELEGATION_SET_IDReusable delegation sets apply only to public hosted zones. You can also create one from an existing zone, by passing --hosted-zone-id to create-reusable-delegation-set, to keep that zone's current servers.
Common errors
- Delegation to the wrong zone. Two hosted zones named
example.comcan exist in one account. Only one matches the registrar's name servers, so records added to the other have no effect. Compare the NS record of the zone you are editing withdig NS example.com +short. - Mixing providers. Listing two Route 53 servers and two servers from the old provider produces inconsistent answers, because the zones may differ. Use one provider's servers only.
- Editing the apex NS record. Route 53 creates the NS and SOA records in the zone. Do not delete them. Changing the apex NS record does not change the delegation, because that is controlled at the registrar.
- Lame delegation. The parent lists a server that does not host the zone. Resolvers get
REFUSEDorSERVFAILfrom that server and retry others, so the failures are intermittent and hard to spot. - Typos. One wrong digit in
ns-1012.awsdns-34.co.ukleaves three working servers and a silent loss of redundancy. Compare the registrar's list withget-hosted-zoneoutput.
Exercise
You deleted the hosted zone for example.com and created a new one with the same name. The domain is registered at an outside registrar, and it now fails to resolve even though all records exist in the new zone. What is wrong, and how do you confirm it?
Show answer
The new zone has different name servers than the old one, but the registrar still lists the old servers, so the delegation points at servers that no longer host the zone. Confirm by running aws route53 get-hosted-zone --id ZONE_ID --query "DelegationSet.NameServers" for the new zone and dig @a.gtld-servers.net example.com NS +norecurse for the delegation, then compare the two lists. Fix it by entering the new zone's four name servers at the registrar.
Exercise
A team needs to manage app.example.com in a separate hosted zone. Where do you add the NS record, and which servers does it list?
Show answer
Add the NS record named app.example.com in the parent zone, example.com. It lists the four name servers of the new app.example.com hosted zone, not those of the parent.