DNAT (destination network address translation) translations let hosts on a Cloudflare One Appliance (formerly Magic WAN Connector) LAN reach a remote subnet through a different local prefix. A remote subnet is a network your Appliance reaches through Cloudflare WAN (formerly Magic WAN), such as a data center connected over an IPsec tunnel. For each translation, you map:
- A pre-NAT prefix: The prefix that hosts on the LAN send traffic to. This is a local alias for the remote subnet.
- A post-NAT prefix: The real prefix of the remote subnet, reachable through Cloudflare. It must be the same size as the pre-NAT prefix.
Use DNAT translations when:
- The remote subnet uses the same addresses as your local network. For example, a data center service and your site both use
10.1.1.0/24. Hosts on the LAN reach the remote service through a pre-NAT prefix that does not conflict. - You do not want to add routes for the remote subnet to your local network. Hosts reach the remote subnet through a pre-NAT prefix that already routes to the Appliance.
The Appliance translates addresses statically and 1:1 between the pre-NAT prefix and the post-NAT prefix, in both directions:
- For traffic from the LAN to an address in the pre-NAT prefix, the Appliance replaces the destination address with the matching address in the post-NAT prefix, and sends the traffic to Cloudflare WAN.
- For traffic from Cloudflare WAN with a source address in the post-NAT prefix, the Appliance replaces the source address with the matching address in the pre-NAT prefix, before it forwards the traffic to the LAN.
Hosts on the LAN only see the remote subnet's addresses in the pre-NAT prefix. The translation is stateless, so it works for connections started from either side.
DNAT translations change destination addresses. To change the source addresses of your LAN, which makes the LAN unique in the Cloudflare WAN overlay, use static NAT for a subnet. You can use both on the same LAN. The Appliance applies both translations to the same packet.
- Both prefixes must be IPv4 CIDR prefixes with no host bits set. For example, use
10.20.0.0/24, not10.20.0.1/24. In the dashboard, if you enter a single IP address, it becomes a/32prefix. - The pre-NAT prefix and the post-NAT prefix must be the same size.
- Pre-NAT prefixes cannot overlap the LAN's static address, its routed subnets, or other pre-NAT prefixes on the same LAN.
- Post-NAT prefixes cannot overlap other post-NAT prefixes on the same LAN. A post-NAT prefix can overlap your local subnets.
- The LAN must use a static address.
- The post-NAT prefix must be reachable through Cloudflare WAN, for example through a static route to an IPsec tunnel.
- Hosts on the LAN must send traffic for the pre-NAT prefix to the Appliance. This happens automatically when the Appliance is their default gateway.
A site and a remote data center both use 10.1.1.0/24. The data center connects to Cloudflare WAN over an IPsec tunnel. Hosts at the site need to reach a service at 10.1.1.20 in the data center.
Configure the LAN at the site with:
- A Static NAT prefix of
10.200.1.0/24for the LAN's10.1.1.0/24subnet. Without it, return traffic to the site's hosts would go to the data center instead, because10.1.1.0/24in Cloudflare WAN already routes to the data center. - A DNAT translation with a Pre-NAT prefix of
100.64.1.0/24and a Post-NAT prefix of10.1.1.0/24.
flowchart LR accTitle: DNAT translation with static NAT accDescr: A LAN host sends traffic to a pre-NAT address. The Appliance translates the destination to the post-NAT address and the source to the static NAT address, then sends the traffic through Cloudflare to the data center. a(Host 10.1.1.50) -->|dst 100.64.1.20| b(Cloudflare One Appliance) b -->|src 10.200.1.50 dst 10.1.1.20| c(Cloudflare WAN) --> d(Data center 10.1.1.20) classDef orange fill:#f48120,color: black class b,c orange
In this case:
- A host at
10.1.1.50connects to100.64.1.20. The Appliance changes the destination to10.1.1.20, and the static NAT prefix changes the source to10.200.1.50. - The data center replies from
10.1.1.20to10.200.1.50. The Appliance changes the source back to100.64.1.20, and the destination back to10.1.1.50.
- Go to the Appliances page.
- Go to Profiles.
- Find the Appliance you want to configure > select the three dots next to it > Edit.
- Go to Network configuration > LAN configuration.
- Find the LAN you want to edit > select the three dots next to it > Edit. You can also select Create to create a new LAN.
- In DNAT translations, select Add DNAT translation.
- In Pre-NAT prefix, enter the prefix that hosts on the LAN will use to reach the remote subnet. For example,
100.64.1.0/24. - In Post-NAT prefix, enter the real prefix of the remote subnet. For example,
10.1.1.0/24. - (Optional) Repeat steps 6-8 to add more translations.
- Select Save.
To remove a translation, select the delete button next to it, then select Save.
Set the remote_subnets array when you create or update a LAN. Each item has a local_alias_prefix (the pre-NAT prefix) and a remote_prefix (the post-NAT prefix).
Required API token permissions
At least one of the following token permissions is required:Magic WAN WriteMagic Transit Write
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/sites/$SITE_ID/lans/$LAN_ID" \
--request PATCH \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"remote_subnets": [
{
"local_alias_prefix": "100.64.1.0/24",
"remote_prefix": "10.1.1.0/24"
}
]
}'The array you send replaces all existing translations on the LAN. If you leave out remote_subnets in an update, the existing translations stay. To remove all translations, send an empty array ("remote_subnets": []).