Amazon AWS Transit Gateway·续1

Choose tunnel names that do not appear in the output. For each tunnel, choose an inside /30 CIDR within 169.254.240.0/20 that does not contain any listed interface address. The reference values in this guide (169.254.240.44/30 through 169.254.240.56/30) are examples; replace them if any are already in use, for example by another deployment of this configuration.

Configure the AWS Transit Gateway

Verify the Transit Gateway options

  1. Log in to the AWS Management Console and open VPC.
  2. Go to Transit gateways > Transit gateways.
  3. Select the Transit Gateway used by the workload VPC.
  4. Confirm the following settings:
Transit Gateway option Value
Amazon side ASN 65020
VPN ECMP support Enabled
DNS support Enabled

This guide uses 65020 as an example private ASN. Choose an ASN that no other Cloudflare WAN-connected site uses, and avoid the AWS default of 64512. For more information, refer to AS path loop prevention.

AWS allows changing the Amazon-side ASN only when the Transit Gateway has no VPN, Direct Connect gateway, Connect, VPN Concentrator, or Client VPN attachments. To change it, run the following command:

aws ec2 modify-transit-gateway --transit-gateway-id <AWS_TGW_ID> --options AmazonSideAsn=65020

If the Transit Gateway already has one of those attachments, keep its current ASN, substitute that ASN throughout this guide, and configure the same value as Customer device ASN in Cloudflare. Confirm that no other Cloudflare WAN-connected site uses that ASN.

Verify the workload VPC attachment

  1. Go to Transit gateways > Transit gateway attachments.
  2. Confirm that the workload VPC has an available VPC attachment to the Transit Gateway.
  3. Confirm that attachment subnets exist in at least two Availability Zones.

Create a dedicated Transit Gateway route table

The route table associated with an AWS VPN attachment determines which routes AWS advertises through that Site-to-Site VPN connection. Use a dedicated route table so unrelated VPC, Site-to-Site VPN, and Direct Connect routes are not exported to Cloudflare WAN.

  1. Go to Transit gateways > Transit gateway route tables.
  2. Select Create transit gateway route table.
  3. For Transit gateway ID, select <AWS_TGW_ID>.
  4. Add a descriptive Name tag, such as cloudflare-wan-routing.
  5. Select Create transit gateway route table.
  6. Record its ID as <AWS_TGW_ROUTE_TABLE_ID>.

Prevent unintended route advertisement

Do not enable propagation from unrelated attachments into this route table. If you use an existing dedicated table, audit every active route and propagation before attaching the VPNs.

Create the AWS customer gateway

  1. Go to Virtual private network (VPN) > Customer gateways.
  2. Select Create customer gateway.
  3. Configure the following values:
AWS field Value
Name tag cloudflare-wan-anycast-01
BGP ASN CF Account ASN ( 13335 by default)
IP address 162.159.135.1
Certificate ARN Leave blank
Device cloudflare-wan-anycast-01
4. Select Create customer gateway.
5. Record the generated customer gateway ID as <AWS_CUSTOMER_GATEWAY_01_ID>.

Secondary anycast IP customers

Repeat the preceding process with name and device cloudflare-wan-anycast-02, the same CF Account ASN, and IP address 172.64.135.1. Record the generated ID as <AWS_CUSTOMER_GATEWAY_02_ID>.

Use a unique device name

If a customer gateway with the same type, IP address, and BGP ASN already exists in the Region, AWS returns the existing customer gateway instead of creating a new one unless the Device value differs. Enter a device name that no other customer gateway in the Region uses, and confirm that the recorded customer gateway ID is new.

Use tags for readability

Record each generated customer gateway ID as the authoritative resource identifier. You can also apply descriptive AWS tags, including a Name tag, to make customer gateways easier to identify in the AWS console and operational tooling.

Create the AWS Site-to-Site VPN connection

  1. Go to Virtual private network (VPN) > Site-to-Site VPN connections.
  2. Select Create VPN connection.
  3. Configure the following values:
AWS field Value
Name tag cloudflare-wan-bgp-01
Target gateway type Transit gateway
Transit gateway <AWS_TGW_ID>
Customer gateway Existing
Customer gateway ID <AWS_CUSTOMER_GATEWAY_01_ID>
Routing options Dynamic (requires BGP)
Local IPv4 network CIDR 0.0.0.0/0
Remote IPv4 network CIDR 0.0.0.0/0
Tunnel inside IP version IPv4

The local and remote network CIDR fields are IKE traffic selectors. Route-based forwarding is controlled by the Transit Gateway route table and BGP, not by these broad selectors. 4. Select Create VPN connection. 5. Wait until the connection state is Available. 6. Record the VPN connection ID as <AWS_VPN_CONNECTION_01_ID>.

Secondary anycast IP customers

Repeat the preceding process with these values:

AWS field Value
Name tag cloudflare-wan-bgp-02
Customer gateway ID <AWS_CUSTOMER_GATEWAY_02_ID>

Use the same Transit Gateway and dynamic-routing options. Record the VPN connection ID as <AWS_VPN_CONNECTION_02_ID>.

Record the AWS resource IDs

Keep a deployment record that maps the generated AWS resources to their Cloudflare role:

Resource Recorded value
Transit Gateway <AWS_TGW_ID>
Dedicated Transit Gateway route table <AWS_TGW_ROUTE_TABLE_ID>
Workload VPC attachment <AWS_VPC_ATTACHMENT_ID>
Customer gateway for 162.159.135.1 <AWS_CUSTOMER_GATEWAY_01_ID>
VPN connection for 162.159.135.1 <AWS_VPN_CONNECTION_01_ID>

Secondary anycast IP customers

Also record the customer gateway and VPN connection IDs for 172.64.135.1 as <AWS_CUSTOMER_GATEWAY_02_ID> and <AWS_VPN_CONNECTION_02_ID>.

Tag each AWS resource with a descriptive name, environment, owner, and change-management reference according to your organization's standards.

Configure the AWS VPN tunnels

AWS assigns two public IPv4 addresses to each VPN connection. Configure both tunnels; do not leave the second tunnel at its default settings.

Configure tunnel 01

  1. Select <AWS_VPN_CONNECTION_01_ID>.
  2. Open Tunnel details and record the first Public IPv4 address as <AWS_OUTSIDE_IP_01>.
  3. Select Actions > Modify VPN tunnel options.
  4. Select <AWS_OUTSIDE_IP_01> for VPN tunnel outside IP address.
  5. Configure the following options. Remove other algorithm choices so AWS cannot negotiate an unexpected proposal.
AWS option Value
Inside IPv4 CIDR 169.254.240.44/30
Pre-shared key Enter a PSK that meets the AWS requirements and record it as <TUNNEL_01_PSK>
Phase 1 encryption algorithms AES256
Phase 2 encryption algorithms AES256
Phase 1 integrity algorithms SHA2-256
Phase 2 integrity algorithms SHA2-256
Phase 1 DH group numbers 20
Phase 2 DH group numbers 20
IKE versions ikev2
Replay window size 2048
DPD timeout action Restart
Startup action Start

Leave the Phase 1 lifetime at 28800 seconds and Phase 2 lifetime at 3600 seconds, then select Save changes.

AWS supports the Start startup action only with IKEv2. Cloudflare only responds to IKE and never initiates it, so AWS must initiate each tunnel.

Configure tunnel 02

Repeat the preceding process for the second public IPv4 address and tunnel-specific values:

Tunnel VPN connection Inside IPv4 CIDR Pre-shared key
02 <AWS_VPN_CONNECTION_01_ID> 169.254.240.48/30 <TUNNEL_02_PSK>

Record the public IPv4 address as <AWS_OUTSIDE_IP_02>. Use the same IKE, IPsec, DPD, replay-window, lifetime, and startup settings on both tunnels. Configure each tunnel with a PSK that meets the pre-shared key requirements. The tunnels can share a PSK.

Secondary anycast IP customers

For the second VPN connection, configure tunnel 03 with 169.254.240.52/30 and <TUNNEL_03_PSK>, and tunnel 04 with 169.254.240.56/30 and <TUNNEL_04_PSK>. Record their public IPv4 addresses as <AWS_OUTSIDE_IP_03> and <AWS_OUTSIDE_IP_04>. Apply the same tunnel settings used for tunnels 01 and 02.

AWS connection changes restart tunnels

Modifying an AWS Site-to-Site VPN connection triggers a tunnel restart and will most likely result in a brief loss of connectivity. Changes typically take approximately three to five minutes to complete. Make changes to an existing production connection during an approved maintenance window.

Create the Cloudflare WAN IPsec tunnels

AWS assigns a public IPv4 address to each VPN tunnel and automatically uses that address as the IKE ID. AWS does not allow the IKE ID to be changed. Cloudflare WAN refers to this AWS address as the Customer endpoint. Although Customer endpoint is generally optional in a Cloudflare WAN IPsec tunnel configuration, it is required for this integration so that it matches the IKE ID presented by AWS.

Create the AWS VPN connection first to obtain its two public IPv4 addresses. Because each AWS VPN connection contains two tunnels, the baseline requires two corresponding Cloudflare WAN IPsec tunnels.

For general Cloudflare WAN tunnel configuration guidance and field definitions, refer to Configure tunnel endpoints.

AWS assigns the Customer endpoint values

Use the AWS Public IPv4 address generated for the corresponding VPN tunnel as the Customer endpoint. If you create a Cloudflare tunnel before adding the generated AWS address, the tunnel will remain down until you update and save its Customer endpoint.

  1. In the Cloudflare dashboard, go to the Connectors page.
  2. From the IPsec/GRE tunnels tab, select Create a tunnel.
  3. On the Add tunnels page, select IPsec tunnel.
  4. Create two tunnels using the following values:
Attribute AWS_TUN_01 AWS_TUN_02
IPv4 interface address 169.254.240.46/30 169.254.240.50/30
Customer endpoint <AWS_OUTSIDE_IP_01> <AWS_OUTSIDE_IP_02>
Cloudflare anycast IP 162.159.135.1 162.159.135.1
Pre-shared key <TUNNEL_01_PSK> <TUNNEL_02_PSK>
Tunnel health checks Enabled Enabled
Health check rate Medium Medium
Health check type Request Request
Health check direction Bidirectional Bidirectional
Health check target Default (not shown) Default (not shown)
Replay protection Enabled Enabled
Automatic return routing Disabled Disabled

Secondary anycast IP customers

Create AWS_TUN_03 and AWS_TUN_04 using the corresponding values recorded earlier and Cloudflare anycast IP 172.64.135.1.

Tunnel names and interface addresses must be unique within the Cloudflare account. If another tunnel already uses one of these names or interface addresses, choose a different name or a different inside /30 CIDR for the matching AWS tunnel.

Replace every <AWS_OUTSIDE_IP_XX> placeholder with the address shown for the matching AWS tunnel. Match tunnels by VPN connection and inside IPv4 CIDR rather than by comparing or sorting the generated public IP addresses.

Select Use my own pre-shared key for each tunnel and enter the PSK configured on the matching AWS tunnel. AWS uses IP-address IKE identities for this integration; do not use the Cloudflare-generated FQDN identity workflow. Cloudflare matches an IP-address IKE identity to a tunnel by its Customer endpoint, so each Cloudflare tunnel must use a unique Customer endpoint value.

Automatic return routing

Automatic return routing is disabled because this design exchanges routes with BGP and supports traffic initiated from other Cloudflare WAN sites toward AWS.

For more information, refer to Automatic return routing (ARR).

Verify tunnel-to-VPN pairing

Before saving each tunnel, verify these tunnel-specific values as a set:

  • AWS VPN connection ID
  • AWS Public IPv4 address used as the Cloudflare Customer endpoint
  • Inside /30 CIDR and Cloudflare interface address
  • Cloudflare anycast IP used by the AWS customer gateway
  • Matching pre-shared key

Match tunnels by their AWS details

Do not infer tunnel order from the AWS public IPv4 addresses. Match each Cloudflare tunnel to the Public IPv4 address and Inside IPv4 CIDR shown under the AWS VPN connection's Tunnel details.

Verify health check settings

Cloudflare health checks test reachability independently of IKE, IPsec, and BGP state. Configure every tunnel with exactly these values:

Health check field Value
Rate Medium
Type Request
Direction Bidirectional
Target Default

The dashboard shows Health check target only when Health check direction is Unidirectional. With Bidirectional selected, the field is hidden and the default target applies, so no action is required. Do not set a custom target through the API or Terraform.

The default target is the other usable address in the tunnel's /30, which is the AWS inside address. For example, for the Cloudflare interface address 169.254.240.46/30, Cloudflare sends health checks to 169.254.240.45. A healthy IPsec security association does not by itself prove that the health check or BGP session is working.

For more information, refer to Tunnel health checks.

Configure BGP in Cloudflare WAN

BGP over IPsec requires Unified Routing. AWS initiates each BGP session; Cloudflare does not initiate BGP peering.

Record the CF Account ASN

  1. Go to Networking > Routes.
  2. Select WAN configuration.
  3. Record the CF Account ASN.

The CF Account ASN defaults to 13335 and can be changed to a private ASN from 64512 through 65534. It applies to every BGP session in the Cloudflare account and must differ from the AWS Transit Gateway ASN. This guide uses 13335 as the reference value. If your account uses a different CF Account ASN, use that value wherever this guide shows 13335, including the BGP ASN of each AWS customer gateway.

For more information, refer to Configure routes.

Enable BGP on each tunnel

For AWS_TUN_01 and AWS_TUN_02:

  1. In the Cloudflare dashboard, go to the Connectors page.
  2. In IPsec/GRE tunnels, locate the tunnel.
  3. Select the three-dot menu next to the tunnel, then select Configure BGP.
  4. For Customer device ASN, enter 65020.
  5. Leave MD5 key blank. AWS Site-to-Site VPN does not provide a matching BGP MD5 configuration option.
  6. Leave Additional advertised prefix list blank unless AWS must receive an additional route that is not already eligible in the Unified Routing dataplane.
  7. Select Save.

Secondary anycast IP customers

Repeat these steps for AWS_TUN_03 and AWS_TUN_04.

Leaving Additional advertised prefix list blank does not restrict advertisements to zero routes. Cloudflare still advertises eligible routes from the Unified Routing dataplane. Inventory those routes before enabling BGP, and block any prefix that AWS must not use as described in Block unwanted prefixes. In the split-egress design used throughout this guide, AWS must not learn 0.0.0.0/0; advertise it only for the optional Cloudflare Gateway egress design described in Prefix control.

Cloudflare peers with the AWS inside IP through the tunnel. AWS peers with the corresponding Cloudflare interface address. The resulting sessions are:

Tunnel AWS BGP address Cloudflare BGP address
AWS_TUN_01 169.254.240.45 169.254.240.46
AWS_TUN_02 169.254.240.49 169.254.240.50