Sub topic 12
Route 53 Resolver endpoints for hybrid DNS
This chapter assumes you have read the earlier chapters on private hosted zones and on how recursive resolvers and authoritative servers work. You should also know VPC basics: subnets, security groups, and a VPN or Direct Connect link to an on-premises network. Hybrid DNS is the practice of letting your VPC and your on-premises network resolve each other's private names.
The problem: two private DNS worlds
A private hosted zone answers queries only from VPCs associated with it. Your on-premises DNS servers know nothing about it. In the other direction, an EC2 instance asks the VPC's built-in resolver for db.corp.example.com. That resolver has no idea your data center hosts that name, so it tries the public internet and fails.
Route 53 Resolver endpoints solve both directions without running your own DNS servers on EC2.
What Route 53 Resolver is
Every VPC has a built-in recursive resolver, called Route 53 Resolver. It answers at the VPC's base address plus two (for a 10.0.0.0/16 VPC, that is 10.0.0.2) and at the link-local address 169.254.169.253. It resolves:
- names in private hosted zones associated with the VPC
- Amazon-provided names such as
ip-10-0-1-5.ec2.internal - public names, by recursing to the internet
This built-in resolver is reachable only from inside the VPC. Resolver endpoints extend it across the VPC boundary.
Inbound and outbound endpoints
A Resolver endpoint is a set of elastic network interfaces (ENIs) in your VPC that carry DNS traffic. Each endpoint has a direction.
| Endpoint | Direction of queries | Typical use |
|---|---|---|
| Inbound | On-premises (or another network) to the VPC | On-premises servers resolve private hosted zone names and VPC-internal names |
| Outbound | VPC to on-premises (or another network) | EC2 instances resolve names hosted by your corporate DNS servers |
An inbound endpoint gives you IP addresses inside your VPC that on-premises DNS servers can send queries to. An outbound endpoint is the source of queries that Resolver forwards out of the VPC. It does nothing until you create forwarding rules.
Endpoint requirements
When you create an endpoint, you choose:
- The VPC the endpoint lives in.
- At least two IP addresses, each in a different subnet. Use different Availability Zones so the endpoint survives a zone failure. You can pick specific IPs or let Route 53 assign them. Pick them deliberately for inbound endpoints, because your on-premises servers will be configured with these addresses.
- A security group that applies to the endpoint's ENIs.
Security group rules are a common source of failures:
- An inbound endpoint needs an inbound rule allowing UDP and TCP port 53 from your on-premises DNS server addresses.
- An outbound endpoint needs an outbound rule allowing UDP and TCP port 53 to your on-premises DNS servers. Security groups allow all outbound traffic by default, but many teams tighten that.
- Allow TCP as well as UDP. DNS falls back to TCP for large responses.
Routing and network ACLs must also permit the traffic. Outbound queries leave through the VPC route tables, so there must be a route to the on-premises network, for example through a virtual private gateway or transit gateway.
Each endpoint ENI handles a limited query rate (the documented figure is about 10,000 queries per second per ENI, though it varies with the query and response mix). Check the current quotas for your account. Spreading across more ENIs raises capacity.
Creating an inbound endpoint
The following command creates an inbound endpoint with two addresses. Replace the subnet and security group IDs with your own.
aws route53resolver create-resolver-endpoint \
--creator-request-id "inbound-$(date +%s)" \
--name onprem-to-vpc \
--direction INBOUND \
--security-group-ids sg-0123456789abcdef0 \
--ip-addresses SubnetId=subnet-0aaa1111bbb22222c,Ip=10.0.1.10 \
SubnetId=subnet-0ddd3333eee44444f,Ip=10.0.2.10The creator-request-id is an idempotency token. Reusing the same value in a retry does not create a duplicate. The endpoint takes a few minutes to reach the OPERATIONAL status. Check with:
aws route53resolver list-resolver-endpoints \
--query "ResolverEndpoints[].{Id:Id,Name:Name,Status:Status,Direction:Direction}"Next, configure your on-premises DNS server with a conditional forwarder that sends queries for the private zone to both endpoint addresses. In BIND, that looks like this:
zone "internal.example.com" {
type forward;
forward only;
forwarders { 10.0.1.10; 10.0.2.10; };
};Windows DNS, Infoblox, and other products have an equivalent conditional forwarder setting. Always list both addresses.
The inbound endpoint resolves whatever the VPC's resolver can resolve. That includes private hosted zones associated with the endpoint's VPC. It also includes names defined by forwarding rules associated with that VPC.
Creating an outbound endpoint and a forwarding rule
First create the outbound endpoint. It has the same shape as the inbound one, with a different direction:
aws route53resolver create-resolver-endpoint \
--creator-request-id "outbound-$(date +%s)" \
--name vpc-to-onprem \
--direction OUTBOUND \
--security-group-ids sg-0123456789abcdef1 \
--ip-addresses SubnetId=subnet-0aaa1111bbb22222c \
SubnetId=subnet-0ddd3333eee44444fThen create a rule that says which domain to forward and where to. Use the endpoint ID returned by the previous command:
aws route53resolver create-resolver-rule \
--creator-request-id "rule-$(date +%s)" \
--name corp-forward \
--rule-type FORWARD \
--domain-name corp.example.com \
--resolver-endpoint-id rslvr-out-0123456789abcdef0 \
--target-ips Ip=10.20.0.2,Port=53 Ip=10.20.0.3,Port=53A rule has no effect until you associate it with a VPC:
aws route53resolver associate-resolver-rule \
--resolver-rule-id rslvr-rr-0123456789abcdef0 \
--vpc-id vpc-0123456789abcdef0After association, any instance in that VPC that queries anything.corp.example.com gets the query forwarded from the outbound endpoint to 10.20.0.2 or 10.20.0.3.
Rule types and which rule wins
| Rule type | What it does |
|---|---|
| Forward | Sends queries for a domain and its subdomains to the target IPs you list |
| System | Tells Resolver to resolve a domain itself instead of forwarding it |
| Recursive (auto-defined) | The default behavior for everything else: resolve normally, including public DNS |
If more than one rule could match a query, Resolver picks the most specific domain name. Suppose you have a forward rule for corp.example.com and a system rule for cloud.corp.example.com. A query for app.cloud.corp.example.com is resolved by Resolver locally, because the system rule is the more specific match. This is the standard way to carve out a cloud-hosted subdomain from a larger on-premises domain.
Be careful when a private hosted zone and a forwarding rule overlap on the same name. Behavior depends on which is more specific, and mixed setups confuse people. Avoid overlap where you can. If you cannot, test with dig from an instance and read the current AWS documentation on rule and zone precedence.
Sharing rules across VPCs and accounts
You do not need an outbound endpoint in every VPC. A rule can be associated with many VPCs, and the outbound endpoint can sit in one central VPC.
- Within an account, associate the same rule with each VPC that needs it.
- Across accounts, share the rule using AWS Resource Access Manager (RAM). The receiving account then associates the shared rule with its VPCs.
A common design puts the endpoints in a shared-services VPC, shares the rules through RAM, and routes traffic to on-premises through a transit gateway. This keeps the endpoint count, and therefore the hourly cost, low.
Cost and capacity considerations
You pay an hourly charge for each ENI in an endpoint, plus a charge per million queries that pass through. Two ENIs per endpoint is the minimum, so an idle endpoint pair costs money every hour. Do not create endpoints per VPC out of habit.
Monitor endpoints with CloudWatch metrics, and consider enabling Resolver query logging. Query logs record which instances asked for which names and what answers came back. They are very useful when debugging, and you can send them to CloudWatch Logs, S3, or Kinesis Data Firehose.
Common errors and how to find them
- Timeouts from on-premises to the inbound endpoint. Check the endpoint's security group (UDP and TCP 53 from the on-premises ranges), the on-premises firewall, and the return route. Test with
dig @10.0.1.10 host.internal.example.com +time=3from an on-premises host. - EC2 instances cannot resolve on-premises names. Confirm the rule is associated with the instance's VPC, the rule's domain name matches, and the outbound endpoint's security group and routes reach the target IPs. A rule created but not associated is a frequent mistake.
- Private hosted zone names do not resolve. The VPC must have DNS resolution and DNS hostnames enabled, and the zone must be associated with the VPC.
- Query loops. Never forward a domain from AWS to an on-premises server that forwards the same domain back to your inbound endpoint. The query bounces between the two until it times out. Keep each domain authoritative in exactly one place.
- Only one endpoint address configured on-premises. If that Availability Zone has a problem, name resolution for the domain stops. List both addresses.
- Wrong network. Instances that use a custom DNS server through a DHCP options set bypass the VPC resolver, so your rules never apply. Point such instances back at the VPC resolver, or make the custom server forward to it.
You can test the AWS-side path from any instance in the VPC:
dig app.corp.example.com +short
dig @169.254.169.253 app.corp.example.com +shortBoth queries should return the same answer from the on-premises name server. If the first works and a direct query to the on-premises server from the instance also works, the problem is on the rule side.
Choosing a design
- You only need on-premises hosts to resolve AWS private names: an inbound endpoint is enough.
- You only need AWS workloads to resolve on-premises names: an outbound endpoint plus forward rules is enough.
- You need both: create both endpoints and keep domain ownership clear, with one authoritative side per domain.
- You have many VPCs or accounts: centralize endpoints and share rules with RAM.
Exercise
Your on-premises servers need to resolve hostnames in the private hosted zone internal.example.com, and your EC2 instances need to resolve hostnames under corp.example.com, which your corporate DNS servers host. Which Resolver endpoints do you create, what configuration does each need, and which extra step is easy to forget?
Show answer
Create an inbound endpoint for the first need and an outbound endpoint for the second. The inbound endpoint needs at least two IP addresses in different subnets (preferably different Availability Zones) and a security group allowing UDP and TCP port 53 from the on-premises DNS servers. Then configure the on-premises DNS servers with a conditional forwarder for internal.example.com pointing at both inbound endpoint IPs. The outbound endpoint needs a security group that allows UDP and TCP 53 to the corporate DNS servers, and a forwarding rule for corp.example.com with those servers as target IPs. The easy-to-forget step is associating the forwarding rule with each VPC whose instances need it. A rule that is not associated has no effect.