Sub topic 16
When VPC address ranges overlap
This chapter assumes you know CIDR notation, subnets, route tables, security groups, and how to read the AWS CLI. It also assumes you have seen the Transit Gateway and PrivateLink chapters before it. Here you will see why overlapping address ranges break network-level routing, why PrivateLink does not have that problem, and what to do when you cannot renumber.
Why overlap is a problem
Two VPCs overlap when their CIDR blocks share any addresses. For example, 10.0.0.0/16 and 10.0.5.0/24 overlap, because the second range sits inside the first. Two VPCs that both use 10.0.0.0/16 overlap completely.
Overlap is common. Teams often pick the console default or the first range from a wiki. Acquisitions and partner networks bring in ranges that were chosen independently.
Transit Gateway and VPC peering both route packets by destination IP address. A route table maps a destination CIDR to a target. If two VPCs own the same CIDR, the router cannot tell which VPC a packet for 10.0.1.20 belongs to.
AWS enforces this in several places:
- VPC peering refuses to create a connection between VPCs with overlapping CIDR blocks.
- Transit Gateway lets you attach VPCs with overlapping ranges, but it does not propagate a route from an attachment whose CIDR matches a route already in the table. Static routes win over propagated routes. Among propagated routes, one attachment's route does not replace another's with the same CIDR, so traffic reaches only one of them or neither.
- Inside a VPC, the local route is always the most specific match for the VPC's own range. A route to the transit gateway for an overlapping CIDR cannot take over traffic for addresses that belong to your own VPC.
The last point causes confusing failures. Suppose VPC A is 10.0.0.0/16 and VPC B is also 10.0.0.0/16. A host in A that connects to 10.0.1.20 reaches only its own VPC, because the local route wins. No transit gateway route can change that.
Check for overlap before you attach
Check ranges before you build anything. This Python script uses only the standard library. It lists every pair of overlapping CIDRs in a list.
from ipaddress import ip_network
from itertools import combinations
vpcs = {
"prod": "10.0.0.0/16",
"staging": "10.0.0.0/16",
"shared": "10.1.0.0/16",
"partner": "10.0.5.0/24",
}
for (name_a, cidr_a), (name_b, cidr_b) in combinations(vpcs.items(), 2):
if ip_network(cidr_a).overlaps(ip_network(cidr_b)):
print(f"OVERLAP: {name_a} {cidr_a} <-> {name_b} {cidr_b}")Running it prints:
OVERLAP: prod 10.0.0.0/16 <-> staging 10.0.0.0/16
OVERLAP: prod 10.0.0.0/16 <-> partner 10.0.5.0/24
OVERLAP: staging 10.0.0.0/16 <-> partner 10.0.5.0/24To list the real ranges of your VPCs, including secondary CIDR blocks, use the CLI:
aws ec2 describe-vpcs \
--query "Vpcs[].{Id:VpcId,Primary:CidrBlock,All:CidrBlockAssociationSet[].CidrBlock}"Remember secondary CIDR blocks. A VPC can have several, and any of them can collide with another network.
Option 1: renumber
Renumbering means moving workloads into a VPC with a non-overlapping range. It is the cleanest fix, and it is also the most work. You cannot change a VPC's primary CIDR block. You can add a secondary block and migrate subnets into it, or you can build a new VPC and move resources over.
Choose renumbering when:
- The overlapping VPCs hold few resources, or the workloads are stateless.
- You expect to connect the VPCs to many others over time.
- You need full network-level connectivity, such as arbitrary ports and bidirectional connections.
Plan address space centrally. A simple approach is to allocate each account or environment a block from a larger private range. Amazon VPC IP Address Manager (IPAM) tracks allocations and can stop teams from creating VPCs that collide with existing ones.
Option 2: expose services with PrivateLink
PrivateLink works because it never joins the two networks. The consumer VPC gets an interface endpoint, which is a set of elastic network interfaces (ENIs) with private IP addresses from the consumer's own subnets. Consumers connect to those local addresses. AWS carries the traffic to the provider's Network Load Balancer over its own backbone.
The provider and consumer never exchange routes, so their ranges can be identical. The consumer sees only addresses from its own range. The provider's targets see traffic coming from the NLB's addresses, not from the consumer.
PrivateLink has limits you must accept:
- One direction. Connections start at the consumer and go to the provider. The provider cannot open connections back to consumer hosts.
- Service-level only. You expose a specific service behind an NLB, such as a database proxy or an internal API. Consumers cannot reach anything else in the provider VPC.
- TCP, and UDP in some cases. The service must fit what an NLB can front.
- Source identity. The provider sees NLB-side addresses by default. To see the consumer's address, enable Proxy Protocol v2 on the NLB target group and make the application read it.
The commands to publish and consume the service are the same as in the earlier PrivateLink chapters. They work with overlapping ranges, because the endpoint's ENIs live in the consumer's own subnets. For reference:
aws ec2 create-vpc-endpoint-service-configuration \
--network-load-balancer-arns arn:aws:elasticloadbalancing:us-east-1:111122223333:loadbalancer/net/my-svc/0123456789abcdef \
--acceptance-required
aws ec2 create-vpc-endpoint \
--vpc-endpoint-type Interface \
--vpc-id vpc-0aaa1111bbb22222c \
--service-name com.amazonaws.vpce.us-east-1.vpce-svc-0123456789abcdef0 \
--subnet-ids subnet-0aaa1111 subnet-0bbb2222 \
--security-group-ids sg-0123456789abcdef0Option 3: keep overlap with a routable intermediate range
Sometimes you must use network-level connectivity and cannot renumber, for example when a legacy partner needs a full network path. The common design uses a separate, non-overlapping range in the middle:
- Create a small intermediary VPC with a unique CIDR, or use a routable secondary range.
- Place NAT in front of the overlapping network. Source NAT makes the overlapping side appear to come from addresses in the unique range.
- Attach the intermediary VPC to the transit gateway and route to it.
This design works but adds cost and operational weight. NAT hides the original source addresses, so logs and security rules lose detail. Every flow depends on the NAT devices, so you must size them and make them highly available. Address-based troubleshooting becomes harder, because an address seen on one side differs from the address seen on the other.
Treat this as a bridge while you migrate, not as a permanent design, unless there is no alternative.
Choosing an approach
| Situation | Best fit | Main cost |
|---|---|---|
| Few workloads, you control both sides | Renumber | Migration effort |
| One service consumed by many VPCs | PrivateLink | One-directional, per-service setup |
| Third party with unmovable ranges, API access only | PrivateLink | Provider runs an NLB |
| Full network access needed, cannot renumber | NAT through an intermediary VPC | Complexity, lost source visibility |
Common errors
- Assuming Transit Gateway will sort it out. It attaches the VPCs without complaint, and then traffic silently goes to one side or nowhere.
- Forgetting secondary CIDRs. A check on primary ranges alone passes, and then a secondary block collides.
- Trying to override local routing. A route for an overlapping CIDR does not redirect traffic for addresses inside your own VPC.
- Expecting two-way traffic over PrivateLink. Only the consumer can start connections. If the provider needs to call back, create a second endpoint service in the opposite direction.
- Overlap with on-premises ranges. Overlap with a VPN or Direct Connect network causes the same problems. Check those ranges too.
Exercise
Two VPCs both use 10.0.0.0/16. A team attaches both to a transit gateway and adds a route for 10.0.0.0/16 in each VPC's route table pointing at the transit gateway. A host in VPC A tries to reach 10.0.3.9, which lives in VPC B. Why does the connection fail, and what is one approach that lets VPC A use a service running in VPC B without renumbering?
Show answer
The address 10.0.3.9 falls inside VPC A's own range, so the local route in VPC A's route table is the most specific match and the packet never leaves VPC A. The route to the transit gateway cannot override it. Without renumbering, VPC B can publish the service behind a Network Load Balancer as a PrivateLink endpoint service, and VPC A creates an interface endpoint. Traffic then goes to an address in VPC A's own subnets, which AWS carries to the service in VPC B.
Exercise
A provider exposes an API with PrivateLink to a consumer whose VPC has the same CIDR. The provider's application must also push notifications to hosts in the consumer VPC. Does the existing endpoint service support this? What can the provider do?
Show answer
No. PrivateLink connections start only at the consumer. The provider cannot open connections to consumer hosts. The consumer can poll the API, or the consumer can publish its own endpoint service for the notifications, and the provider creates an interface endpoint to it. The provider can also use an asynchronous channel such as a queue that both sides can reach.