NAT on DRG - Part 1 - Overlapping CIDRs between two local VCNs

Introduction

Two networks that use the same IP range cannot talk to each other with plain routing. A router that receives a packet for 10.0.1.25 has no way to tell whether that address lives in the network on its left or the network on its right. In Oracle Cloud Infrastructure (OCI) this happens more often than you would like: two teams both picked 10.0.0.0/16 for their Virtual Cloud Network (VCN), a company was acquired, or an application was cloned together with its addressing.

Until now the usual answers were to re-address one of the networks or to place a firewall or NAT appliance between them. NAT on DRG removes the need for both. The Dynamic Routing Gateway (DRG) can now translate IPv4 addresses itself, as traffic passes through one of its attachments. The translation is:

There is one concept that decides whether your configuration works or not, so it is worth stating early:

[!NOTE] A NAT rule describes traffic entering the DRG through the attachment that holds the policy. Always write the rule from the point of view of the network behind that attachment.

In this first part we use the simplest topology possible: two VCNs in the same region, attached to the same DRG, both with the subnet 10.0.1.0/24. Each VCN gets its own NAT policy that presents it to the other side under a unique “shadow” CIDR:

VCN Real subnet CIDR Shadow CIDR seen by the other VCN
uc1-vcn-a 10.0.1.0/24 192.168.10.0/24
uc1-vcn-b 10.0.1.0/24 192.168.20.0/24

An instance in VCN A therefore reaches the instance in VCN B on 192.168.20.x, and an instance in VCN B reaches VCN A on 192.168.10.x. Neither side ever sees the other side’s real 10.0.1.x address.

image

Other Use Cases

This tutorial is part of a series of five. Every part solves a different overlap scenario with the same building blocks.

Diagram

Overlapping subnet CIDRs resolved with stateless 1:1 NAT on DRG
(Two VCNs with the same CIDR communicate privately by translating one side to a unique private CIDR as traffic traverses the DRG.)

image

The diagram shows every object you configure in this tutorial:

Prerequisites

[!NOTE] The names, CIDRs and IP addresses in this tutorial come from the lab in the screenshots. You can use your own, as long as the shadow CIDRs do not overlap with anything else in your network and have the same prefix length as the CIDR they replace.

Steps

Step 01: Review the two VCNs with overlapping CIDRs

We start with the problem itself: two VCNs that were created with exactly the same address space. Nothing in OCI prevents you from doing this, and as long as the VCNs stay isolated it causes no harm. It only becomes a problem at the moment you want to connect them.

image

image

image

Step 02: Review the subnets

The overlap continues one level down. Both VCNs have a single public subnet, and both subnets use 10.0.1.0/24. This /24 is the range that the NAT rules translate later, so remember it.

image

image

Step 03: Review the internet gateways

The internet gateways have nothing to do with NAT on DRG. They are only here so that you can reach the test instances over SSH on their public IP addresses.

image

image

Step 04: Configure the security lists

The test in this tutorial is a ping between the two instances, so the security lists must allow ICMP. Keep in mind which source address the instances will see. Because of the translation, a ping from VCN A arrives in VCN B with a source address in 192.168.10.0/24, not 10.0.1.0/24. The rule that allows ICMP from 192.168.0.0/16 is therefore the one that matters.

The lab allows ICMP from all three private ranges. That is broader than this tutorial needs. The minimum is one ICMP rule per VCN, with the shadow CIDR of the other VCN as source: 192.168.20.0/24 in uc1-vcn-a and 192.168.10.0/24 in uc1-vcn-b.

image

image

Step 05: Create the DRG and attach both VCNs

The DRG is the router between the two VCNs and the place where the translation happens. Both VCNs are attached to the same DRG, each with its own VCN attachment. The attachments are important in this tutorial, because the route tables and the NAT policies are all bound to an attachment, not to the DRG as a whole.

image

[!NOTE] We come back to this Attachments tab in Step 09. At that point every attachment also shows its own DRG route table and its DRG NAT policy.

Step 06: Create a DRG route table for each attachment

A DRG route table decides where a packet goes after it has entered the DRG through an attachment. By default all VCN attachments share one autogenerated route table that is filled with the CIDRs of the attached VCNs. With two VCNs that advertise the same 10.0.1.0/24, that table can hold only one active route for this CIDR. The DRG picks one of the two attachments and marks the other route as a conflict. Whichever one wins, every packet for 10.0.1.0/24 goes to the same attachment, no matter which side it came from, so only one direction can ever work. This tutorial needs the opposite: the same destination has to lead to a different attachment depending on where the packet entered the DRG. Each attachment therefore gets its own DRG route table with a single static route that points to the other attachment.

The destination in these routes is the real CIDR 10.0.1.0/24, not a shadow CIDR. This is because of the order in which the DRG works:

  1. The packet enters the DRG through an attachment.
  2. The NAT policy on that attachment translates the packet.
  3. The DRG looks up the translated destination in the DRG route table of that attachment.

A packet from VCN A to 192.168.20.158 has already been translated to destination 10.0.1.158 by the time the route lookup happens.

image

image

Step 07: Configure the VCN route tables

The instances must know that the shadow CIDR of the other VCN is reachable through the DRG. An instance in VCN A talks to VCN B on 192.168.20.0/24, so that is the destination you route to the DRG in VCN A. The real CIDR 10.0.1.0/24 is never routed to the DRG, because for the instance that range is its own local subnet.

image

image

Step 08: Create the DRG NAT policies and rules

This is the step the whole tutorial is about. We create one DRG NAT policy per VCN, and each policy gets one rule. Every rule does two translations at once:

Remember that a rule describes traffic entering the DRG through the attachment that holds the policy. The policy for VCN A is therefore written from the point of view of VCN A:

  Original Translated Meaning
Source 10.0.1.0/24 192.168.10.0/24 VCN A presents itself as 192.168.10.0/24.
Destination 192.168.20.0/24 10.0.1.0/24 The shadow CIDR of VCN B is replaced with the real CIDR of VCN B.

The policy for VCN B is the mirror image:

  Original Translated Meaning
Source 10.0.1.0/24 192.168.20.0/24 VCN B presents itself as 192.168.20.0/24.
Destination 192.168.10.0/24 10.0.1.0/24 The shadow CIDR of VCN A is replaced with the real CIDR of VCN A.

image

image

image

[!NOTE] The original and the translated CIDR of a pair must have the same prefix length. Rules are evaluated in order of priority, the lowest number first, and only the first matching rule is applied. A policy with rules still translates nothing until it is associated with an attachment, which is the next step.

Step 09: Associate the NAT policies with the VCN attachments

A policy becomes active for traffic when it is associated with a DRG attachment. Each attachment can have one NAT policy. We associate uc1-policy-a with the attachment of VCN A and uc1-policy-b with the attachment of VCN B.

image

image

You can verify the complete configuration from the DRG side as well.

image

image

image

Step 10: Test the connectivity

Everything is in place, so it is time to send a packet. The last octet of an address is preserved by the 1:1 translation, which tells you which address to ping:

Instance Real IP address Address to use from the other VCN
uc1-inst-a 10.0.1.81 192.168.10.81
uc1-inst-b 10.0.1.158 192.168.20.158

This is what happens to a ping from uc1-inst-a to uc1-inst-b:

Where Source Destination What happens
Leaves uc1-inst-a 10.0.1.81 192.168.20.158 The route table uc1-rt-a sends 192.168.20.0/24 to the DRG.
Enters the DRG on uc1-att-a 192.168.10.81 10.0.1.158 The rule in uc1-policy-a translates source and destination.
Route lookup in uc1-drgrt-att-a 192.168.10.81 10.0.1.158 10.0.1.0/24 points to uc1-att-b.
Arrives at uc1-inst-b 192.168.10.81 10.0.1.158 The instance sees a ping from the shadow address of uc1-inst-a.

The reply follows the same steps in the other direction. It leaves uc1-inst-b as 10.0.1.158 to 192.168.10.81, is translated by the rule in uc1-policy-b when it enters the DRG on uc1-att-b, and arrives at uc1-inst-a as 192.168.20.158 to 10.0.1.81.

image

image

[!NOTE] NAT on DRG does not translate DNS. If your applications find each other by name, the DNS records that the other side uses must point to the shadow addresses, not to the real ones.

Conclusion

Two VCNs with exactly the same subnet CIDR now communicate privately through a single DRG, without re-addressing either of them and without a firewall or NAT appliance in the path. Each VCN is presented to the other one under a unique shadow CIDR, and the translation is done by the DRG itself.

The configuration comes down to three things that always belong together. A DRG NAT policy with a rule written from the point of view of the network behind the attachment. A DRG route table per attachment that routes on the address after translation. And a VCN route table that sends the shadow CIDR of the other side to the DRG. If one of the three is missing, the translation may still happen but the packet has nowhere to go.

The same three building blocks return in the rest of the series. In NAT on DRG - Part 2 - Overlapping CIDRs between multiple remote VCNs the two VCNs move to different regions and the translation happens on a remote peering connection.

Acknowledgments

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.