Amazon AWS Transit Gateway·续2

Secondary anycast IP customers

The sessions for the second anycast IP use 169.254.240.53 and 169.254.240.54 for tunnel 03, and 169.254.240.57 and 169.254.240.58 for tunnel 04.

Do not create a Cloudflare WAN static route for 192.168.0.0/16. Cloudflare learns the VPC prefix from AWS over BGP.

Understand route exchange

The two route directions use different sources:

Direction Route source Control point
AWS to Cloudflare Routes in the Transit Gateway route table associated with each VPN attachment Dedicated route table and attachment propagation
Cloudflare to AWS Eligible routes from the Unified Routing dataplane plus tunnel-specific additional advertised prefixes Cloudflare route inventory and Additional advertised prefix list

AWS advertises the propagated VPC prefix over every established BGP session. Cloudflare can therefore retain equivalent paths and withdraw only the paths affected by a failed session. AWS learns RFC 1918 prefixes from Cloudflare WAN by default, along with any publicly routable prefixes explicitly enabled for the account. AWS can install equal-cost paths when their BGP attributes are equivalent.

Configure AWS Transit Gateway routing

The example propagates and exports the complete 192.168.0.0/16 VPC CIDR. It also propagates all prefixes learned through the VPN attachments into the dedicated Transit Gateway route table.

Associate the attachments

  1. Go to Transit gateways > Transit gateway route tables.
  2. Select <AWS_TGW_ROUTE_TABLE_ID>.
  3. Open Associations.
  4. Confirm the workload VPC attachment and every configured VPN attachment are associated with this route table.
  5. If an attachment is not associated, select Create association, select the attachment, and create the association.
  6. Confirm no unrelated attachment is associated with this route table.

An attachment can be associated with only one Transit Gateway route table. Moving an existing workload attachment can change its forwarding behavior; ensure the dedicated table contains every route the workload requires before changing the association.

Enable VPC route propagation

  1. Open Propagations for <AWS_TGW_ROUTE_TABLE_ID>.
  2. Select Create propagation.
  3. Select the workload VPC attachment and create the propagation.
  4. Confirm 192.168.0.0/16 appears as a propagated route.

AWS advertises the propagated VPC CIDR to Cloudflare through every established BGP session.

Enable VPN route propagation

  1. Open Propagations for <AWS_TGW_ROUTE_TABLE_ID>.
  2. Select Create propagation.
  3. Select the VPN attachment and create the propagation.

Secondary anycast IP customers

Repeat these steps for the second VPN attachment.

The propagated routes are the prefixes that AWS learns from Cloudflare over BGP. When the same prefix arrives with equivalent BGP attributes over multiple tunnels, the Transit Gateway can install equal-cost paths and use ECMP.

Configure workload subnet routes

For each VPC route table associated with a workload subnet:

  1. Go to Virtual private cloud > Route tables.
  2. Select the workload subnet route table.
  3. Select Routes > Edit routes.
  4. For each approved destination prefix that should traverse Cloudflare WAN, add a route with <AWS_TGW_ID> as the target.
  5. Leave any existing 0.0.0.0/0 route unchanged.
  6. Save the changes.

This produces the same split-egress design as the Terraform reference deployment: approved prefixes use the Transit Gateway, and the existing default route continues to carry Internet traffic through the Internet Gateway or NAT gateway. AWS longest-prefix matching selects the more-specific routes over the default route. Add only prefixes from the approved inventory that Cloudflare advertises; do not add a route that overlaps the VPC CIDR.

Do not point the default route at the Transit Gateway by default

A VPC route table holds one 0.0.0.0/0 route. Targeting it to <AWS_TGW_ID> replaces any existing Internet Gateway or NAT gateway route rather than adding a second path. If Cloudflare does not advertise an active default route over BGP, the Transit Gateway has no matching route and drops Internet-bound traffic from the subnet.

Change the default route only if you intend to send Internet traffic through Cloudflare Gateway, Cloudflare advertises 0.0.0.0/0, and that route appears as active in <AWS_TGW_ROUTE_TABLE_ID>. Record the original target first so you can restore it. Refer to Prefix control.

Review security controls

Confirm that the following controls permit the intended traffic:

  • Workload security groups
  • Subnet network access control lists
  • Host firewalls
  • Cloudflare WAN network firewall policies

AWS manages UDP 500, UDP 4500, and ESP connectivity for the Site-to-Site VPN tunnels. These protocols do not require rules in workload security groups.

BGP design considerations

This section covers only the BGP behavior specific to combining AWS Transit Gateway and Cloudflare WAN.

BGP timers and convergence

AWS sets the BGP hold time for each tunnel, and it cannot be changed. Cloudflare advertises 240 seconds and uses the lower value, so the AWS value applies. Cloudflare requires a hold time of at least 30 seconds. Terraform reports the AWS value as aws_bgp_holdtime in the cloudflare_tunnel_mapping output.

After a session goes down, Cloudflare propagates the route withdrawal in no more than a few minutes. In Edge Resiliency Mode, a Cloudflare data center keeps forwarding on its last known routes while tunnel health checks pass, so a BGP failure on a healthy tunnel may not withdraw the path immediately.

For more information, refer to BGP route distribution and convergence, BGP timers and settings, and Edge Resiliency Mode.

AS path loop prevention

Cloudflare preserves the original AS path between Cloudflare WAN sites, and AWS Transit Gateway has no allowas-in option. AWS silently rejects routes from any other Cloudflare WAN site that uses the Transit Gateway ASN. Give each site a unique ASN, and do not use the AWS defaults: 64512 for Transit Gateways and virtual private gateways, and 65000 for customer gateways.

Prefix control

Cloudflare advertises every eligible route from the Unified Routing dataplane, plus any entries in Additional advertised prefix list. Leaving that list empty does not limit what Cloudflare advertises. AWS accepts up to 1,000 routes from each VPN connection and advertises up to 5,000; neither quota is adjustable.

Advertising 0.0.0.0/0 to AWS sends Internet traffic through Cloudflare Gateway only if the workload route table also sends 0.0.0.0/0 to the Transit Gateway. The Terraform reference deployment does not use this design.

Block unwanted prefixes

To stop AWS from using a prefix, remove it from the Cloudflare advertisement (a static route under Networking > Routes, or an Additional advertised prefix list entry), or add a blackhole static route for the exact CIDR in <AWS_TGW_ROUTE_TABLE_ID>. A Transit Gateway static route takes precedence over a VPN-propagated route for the same CIDR, but not over a more-specific route. Routes that Cloudflare learns over BGP from other sites can only be withdrawn at the originating site or blocked in AWS. Remove any 0.0.0.0/0 blackhole route before adopting Cloudflare Gateway egress.

For more information, refer to Route evaluation order ↗︎ in the AWS documentation.

MSS and MTU

For Cloudflare WAN guidance, refer to Maximum transmission unit and maximum segment size.

IPsec encapsulation reduces the usable packet size. Cloudflare recommends a maximum TCP MSS clamp of 1360 bytes for IPsec tunnels. This value is below the 1382-byte MSS that AWS lists for AES-CBC with SHA-256 and NAT-T, so it is compatible with the cipher suite in this guide. AWS Site-to-Site VPN does not provide a per-VPN MSS-clamping control, so apply the clamp on a device or workload in the traffic path when necessary.

AWS Site-to-Site VPN does not support Path MTU Discovery. Validate large TCP flows with controlled packet-size and Don't Fragment (DF) tests. Where supported, fragment packets before encryption or apply MSS clamping rather than relying on Path MTU Discovery.

Verification

Verify AWS tunnel and BGP status

For each VPN connection:

  1. In the AWS VPC console, go to Site-to-Site VPN connections.
  2. Select the VPN connection.
  3. Open Tunnel details.
  4. Confirm both tunnels show UP.
  5. Confirm the accepted route count matches the expected Cloudflare WAN prefix inventory.

An UP tunnel confirms IKE and IPsec state, not the BGP finite-state-machine state. Confirm each session is Established in the Cloudflare BGP status view. A positive accepted route count confirms route exchange, but an established session can legitimately have zero accepted routes.

You can also verify the configured tunnels with the AWS CLI:

aws ec2 describe-vpn-connections --vpn-connection-ids <AWS_VPN_CONNECTION_01_ID> --query 'VpnConnections[].{VpnId:VpnConnectionId,Tunnels:VgwTelemetry[].{OutsideIP:OutsideIpAddress,Status:Status,ImportedRoutes:AcceptedRouteCount,Message:StatusMessage}}' --output table --no-cli-pager

Secondary anycast IP customers

Add <AWS_VPN_CONNECTION_02_ID> after <AWS_VPN_CONNECTION_01_ID> in the --vpn-connection-ids argument.

Expected results:

  • Every configured tunnel reports UP
  • AcceptedRouteCount matches the expected Cloudflare WAN prefixes and is greater than zero when routes are being advertised

The command reports tunnel telemetry and accepted route counts; it does not expose an explicit BGP session state. Use the Cloudflare BGP status view to verify that every configured session is currently established.

Verify the Transit Gateway routes

  1. Go to Transit gateways > Transit gateway route tables.
  2. Select <AWS_TGW_ROUTE_TABLE_ID> and open Routes.
  3. Confirm 192.168.0.0/16 is an active propagated route to the workload VPC attachment.
  4. Confirm the expected RFC 1918 prefixes and any explicitly enabled public prefixes appear as propagated routes through the VPN attachments.
  5. Confirm equivalent Cloudflare WAN routes have multiple equal paths when ECMP is expected.

Enumerate the exact active Transit Gateway routes and compare every CIDR and attachment with the approved prefix inventory:

aws ec2 search-transit-gateway-routes --transit-gateway-route-table-id <AWS_TGW_ROUTE_TABLE_ID> --filters Name=state,Values=active --max-results 1000 --query '{AdditionalRoutesAvailable:AdditionalRoutesAvailable,Routes:Routes[].{CIDR:DestinationCidrBlock,Type:Type,State:State,Attachments:TransitGatewayAttachments[].TransitGatewayAttachmentId}}' --output json --no-cli-pager

If AdditionalRoutesAvailable is true, the result is incomplete. Run narrower searches for each approved prefix and investigate any route not covered by the approved inventory.

Verify Cloudflare tunnel and route status

  1. In the Cloudflare dashboard, go to Networking > Insights > Network health > IPsec/GRE tunnels and interconnects.
  2. Confirm every configured tunnel is healthy.
  3. Inspect the BGP status for each tunnel and confirm every configured session is Established.
  4. Go to Networking > Routes.
  5. Confirm 192.168.0.0/16 is learned through the AWS BGP sessions.
  6. Inspect the available route paths and confirm the expected tunnels contribute paths.
  7. Confirm the complete AWS VPC prefix is present and no unrelated AWS prefix is advertised.

Test end-to-end connectivity

  1. Start a packet capture or flow-log query where available.
  2. From a permitted AWS workload in 192.168.125.0/24, ping or connect to a host in a prefix learned from Cloudflare WAN.
  3. Test the reverse direction from a Cloudflare WAN-connected network to the AWS workload.
  4. Confirm the application flow is not translated unexpectedly.
  5. During a maintenance window, disable one tunnel and confirm its BGP path is withdrawn while traffic continues over the other tunnel. Allow up to the negotiated BGP hold time for each side to declare the session down, plus up to a few minutes for Cloudflare to propagate the withdrawal. Refer to BGP timers and convergence.

Secondary anycast IP customers

Also test the loss of both tunnels in one VPN connection and confirm traffic continues through the second Cloudflare anycast IP. Allow the same convergence time.

Also confirm that every approved destination prefix (vpn_routed_prefixes in Terraform) uses the Transit Gateway and that an unmatched IPv4 destination still uses the existing Internet Gateway or NAT gateway default route. AWS longest-prefix matching gives the configured VPN routes precedence over 0.0.0.0/0. Testing direct Internet egress requires a workload with a public IPv4 address or a NAT gateway path; the Terraform proof of concept does not create a workload or NAT service.

Troubleshooting

All tunnels are down

  • Confirm each AWS customer gateway IP matches its configured Cloudflare anycast IP
  • Confirm Startup action is Start; Cloudflare only responds to IKE and never initiates it
  • Verify IKEv2, AES-256-CBC, SHA-256, and DH group 20 are the enabled proposals
  • Confirm each pre-shared key matches the corresponding AWS public IPv4 address and Cloudflare WAN tunnel
  • Review Cloudflare tunnel health events

One tunnel is down

  • Confirm the Cloudflare Customer endpoint contains the AWS Public IPv4 address generated for that specific VPN tunnel
  • Verify the inside /30, AWS public IPv4 address, and pre-shared key were not copied from another tunnel
  • Confirm every inside CIDR is unique and within 169.254.240.0/20
  • Confirm replay protection is enabled in Cloudflare and the AWS replay window is 2048
  • Confirm DPD timeout action is Restart

IPsec is up but BGP is down

  • Confirm the AWS customer gateway BGP ASN matches the CF Account ASN
  • Confirm Customer device ASN is 65020 on the corresponding Cloudflare WAN tunnel
  • Confirm BGP is enabled on every Cloudflare WAN tunnel
  • Confirm the Cloudflare interface address matches the second usable address in the AWS /30
  • Confirm no BGP MD5 key is configured in Cloudflare
  • Confirm AWS initiates TCP port 179 toward the Cloudflare interface address

Interpret the reported BGP state as follows:

State Meaning Primary checks
Established The session is exchanging routes Validate received and advertised prefix inventories
Active The peer is retrying the connection Check the peer address, ASN, and TCP port 179 reachability
Connect The TCP connection is in progress Check tunnel reachability and the Cloudflare interface address
Idle The session is not attempting to connect Confirm BGP is enabled and AWS is configured to initiate

BGP is up but routes are missing

  • Confirm every configured VPN attachment has propagation enabled in the intended Transit Gateway route table
  • Confirm the workload VPC attachment is associated with and propagated into that table
  • Confirm 192.168.0.0/16 exists as a propagated Transit Gateway route to the VPC attachment
  • Check whether BGP loop prevention rejects a route containing ASN 65020
  • Confirm the expected Cloudflare WAN routes are eligible in the Unified Routing dataplane
  • Check for route filters or a more-specific route that changes the forwarding result

Routes exist but traffic does not pass

  • Check the workload subnet route table, Transit Gateway route table, and Cloudflare WAN route table in both directions
  • Confirm security groups, network access control lists, host firewalls, and Cloudflare WAN network firewall policies allow the traffic
  • Check for overlapping or more-specific routes
  • Review VPC Flow Logs and Transit Gateway Flow Logs, if enabled
  • Confirm source and destination prefixes are not translated unexpectedly