Insights

Peered VPC Hostname Resolves to a Public IP? Check Peering DNS Resolution

November 29, 2026
0:00
You set up a VPC peering connection. The routes are in place and the security groups allow the peer's CIDR, yet an app in one VPC can't reach a service in the other when it connects by hostname. Run dig on the peer instance's EC2 public DNS name and you get a public IP instead of the private 10.x address you expected. That is the default AWS behavior, and a per-connection setting called DNS resolution controls it. This guide covers checking that setting from the CLI, turning it on for each side, and proving the change worked with dig from both VPCs.
Every EC2 instance with a public IPv4 address gets a public DNS hostname, something like ec2-203-0-113-25.eu-west-1.compute.amazonaws.com. Inside the instance's own VPC, the Amazon-provided resolver answers that name with the private IP. Anywhere else, it answers with the public IP. A peered VPC counts as "anywhere else" by default. The AWS documentation on how peering works says that when an instance queries the public DNS hostname of an instance in a peered VPC, AWS resolves it to the peer's public IPv4 address. Traffic then routes over the public internet instead of the peering link. That is where the confusing symptoms come from. If the source instance sits in a private subnet, the packet goes out through a NAT gateway and arrives at the peer from the NAT's Elastic IP. A security group rule that allows the peer VPC's CIDR doesn't match that source address, so the connection times out. If the source subnet has no internet route at all, the connection fails before it leaves the VPC. In both cases the peering connection looks healthy in the console, which is why people often suspect routing or security groups first. The fix is the AllowDnsResolutionFromRemoteVpc option on the peering connection. The option is set separately on the requester side and on the accepter side. The flag on one side decides how that side's hostnames resolve when queried from the other VPC. The requester flag lets the accepter VPC resolve requester hostnames to private IPs, and the accepter flag does the reverse. If you only enable one side, name resolution works in one direction only. That half-working state is confusing to debug.
Four things decide which IP a peer hostname resolves to:
  • the peering connection status
  • the DNS resolution flag on each side
  • the DNS attributes on each VPC
  • which resolver the instance actually uses
All four can be checked with read-only commands.
BASH
# Peering status and the DNS resolution flag for both sides (read-only)
aws ec2 describe-vpc-peering-connections \
  --vpc-peering-connection-ids pcx-0123456789abcdef0 \
  --query 'VpcPeeringConnections[0].{Status:Status.Code,Requester:RequesterVpcInfo.[VpcId,PeeringOptions.AllowDnsResolutionFromRemoteVpc],Accepter:AccepterVpcInfo.[VpcId,PeeringOptions.AllowDnsResolutionFromRemoteVpc]}'

# DNS attributes on each VPC (run for both VPC IDs)
aws ec2 describe-vpc-attribute --vpc-id vpc-0aaaa1111bbbb2222 --attribute enableDnsSupport
aws ec2 describe-vpc-attribute --vpc-id vpc-0aaaa1111bbbb2222 --attribute enableDnsHostnames

# On the instance: which resolver is it really using?
resolvectl status 2>/dev/null || cat /etc/resolv.conf
In the first command's output, the status should be active. The peering options only matter, and may only appear in the output, once the connection is active. Each side's flag shows as true or false. The AWS re:Post article on troubleshooting peering DNS resolution notes that DNS hostnames and DNS resolution must also be enabled on the individual VPCs. The second pair of commands checks that. Both attributes should report "Value": true on both VPCs. If either is off, the peering flag alone won't produce private answers. You can turn the attributes on in the console under the VPC's "Edit VPC settings" page or with aws ec2 modify-vpc-attribute. Check the exact argument format for your CLI version before scripting it. The third check is the one people skip most often. The private answer only comes from the Amazon-provided resolver, which lives at the VPC's base CIDR plus two (for example, 10.0.0.2 in a 10.0.0.0/16 VPC). If /etc/resolv.conf or the systemd-resolved configuration points at a public resolver such as 1.1.1.1, or at a company DNS server that forwards to the internet, the instance gets the public IP no matter what the peering flags say. A DHCP options set with custom domain name servers is a common cause.
If either flag shows false, enable it. This change does not interrupt existing traffic. It only changes what the resolver returns, and you can reverse it by running the same command with =false. In practice, though, it changes where traffic flows. Connections that currently go out over the internet will move to the peering link, where the peer's security groups and network ACLs for private CIDRs apply. Confirm those rules allow the traffic before you flip the flags in production.
BASH
# Requester side: lets the accepter VPC resolve requester hostnames to private IPs
# (run with credentials for the account that owns the requester VPC)
aws ec2 modify-vpc-peering-connection-options \
  --vpc-peering-connection-id pcx-0123456789abcdef0 \
  --requester-peering-connection-options AllowDnsResolutionFromRemoteVpc=true

# Accepter side: lets the requester VPC resolve accepter hostnames to private IPs
# (run with credentials for the account that owns the accepter VPC)
aws ec2 modify-vpc-peering-connection-options \
  --vpc-peering-connection-id pcx-0123456789abcdef0 \
  --accepter-peering-connection-options AllowDnsResolutionFromRemoteVpc=true
If both VPCs are in the same account, you can run both commands with the same credentials. In cross-account peering, each account typically controls only its own side. A call that tries to set the other side's options fails. Coordinate with the other account's owner instead of trying to work around the error. For inter-region peering, run each call against the region that matches your setup and check the AWS documentation if the call returns an error about the connection not being found. The same applies if you manage peering through Terraform or CloudFormation: set the requester and accepter options in the resource definition rather than with ad hoc CLI calls. Otherwise the next apply may revert your change. Run the first describe-vpc-peering-connections command again afterwards. Both flags should now read true.
The flags reading true is necessary but not proof. Test resolution from an instance in each VPC, because each direction depends on a different flag. The hostnames below are illustrative. Replace them with the real public DNS names of instances in the peer VPC, which you can find in the instance details or with aws ec2 describe-instances --query 'Reservations[].Instances[].PublicDnsName'.
BASH
# From an instance in VPC A: resolve a VPC B instance through the default resolver
dig +noall +answer ec2-203-0-113-25.eu-west-1.compute.amazonaws.com

# Ask the Amazon-provided resolver directly, bypassing resolv.conf
dig +noall +answer @169.254.169.253 ec2-203-0-113-25.eu-west-1.compute.amazonaws.com

# Control test: a public resolver should still return the public IP
dig +noall +answer @1.1.1.1 ec2-203-0-113-25.eu-west-1.compute.amazonaws.com
The three queries tell you different things:
  • Direct query to the Amazon resolver (second command). It should return the peer's private IP, such as an address in 10.1.0.0/16. If it still returns the public IP, the peering flag for the peer's side or that VPC's DNS attributes are the problem.
  • Default resolver (first command). If the direct query returns the private IP but this one returns the public IP, the instance is using a different resolver. Go back to the resolver check in the audit section.
  • Public resolver (third command). This should keep returning the public IP. It confirms you are querying the right name, and it shows that the private answer exists only inside AWS.
Then repeat the test from an instance in VPC B against a VPC A hostname. If one direction works and the other doesn't, one of the two flags is still off. If the direct query is correct but the application still connects to the public IP, look at caching. The dig answer section shows a TTL. Local caches such as systemd-resolved may hold the old answer until that TTL expires, and on systemd-resolved hosts you can clear the cache with resolvectl flush-caches. Some application runtimes and connection pools cache DNS results themselves and only re-resolve on restart. Finish with a real connection test, such as nc -vz <hostname> <port> or a curl to the service. A working peering path shows up in VPC flow logs as traffic between the two private CIDRs instead of traffic through the NAT gateway.
The option applies only to AWS-generated public DNS hostnames of EC2 instances. Custom names are a separate case. The Stack Overflow thread on peered hostnames resolving to public IPs raises this: if you use a Route 53 private hosted zone such as db.internal.example, the peering flag has no effect on it. The private hosted zone has to be associated with the peer VPC for those names to resolve there. The option also doesn't make peering transitive. If VPC A peers with a hub and the hub peers with VPC C, enabling DNS resolution on both connections still doesn't let A reach C through the hub. Native peering never forwards traffic onward. The details are in this explanation of non-transitive peering. If you also run peered networks on Google Cloud, the model is different. Google's VPC Network Peering documentation says peering does not automatically share internal DNS names such as *.c.<project>.internal. Google recommends using internal IP addresses across peered networks. You won't find an equivalent of the AWS flag there, so don't go looking for one. From the support desk, the useful habit is to ask what name the application connects to before touching routes or security groups. If the name is an EC2 public DNS hostname and dig @169.254.169.253 returns a public IP, routing is not the problem. To sum up: when a peered hostname resolves to a public IP, check both peering flags, both VPCs' DNS attributes, and the instance's resolver, in that order. Enable the flag on each side that needs to be resolvable. Then confirm with dig from each VPC before declaring it fixed. Each direction depends on a different flag, so a test from only one VPC proves only half of the change.

Join My Newsletter & Get Updates!

Get notified whenever a new technical guide, server infrastructure breakdown, or personal reflection goes live, plus a curated weekly digest.