Traffic steering (3)·续1
Scoping routes to specific regions
If you have multiple connectivity paths to a network segment and want to apply different route prioritization based on where traffic arrives at the Cloudflare network, you can scope routes to specific Cloudflare data center regions. This is useful if you run your own anycast network and want your end-user traffic to arrive at your network location closest to the user.
When you scope a route to a Cloudflare data center region, it only shows up in the Magic Transit Virtual Network routing table in that region, along with all global routes that do not have any region scope. Route prioritization and ECMP logic apply across both region-scoped and global routes.
Note
Scoping routes to specific regions is not supported with BGP peering, and is only available to statically configured routes at this time.
When using region-scoped routes, ensure that all prefixes have routes covering all regions. Otherwise, traffic may arrive at a Cloudflare region that is not covered by any route, in which case Cloudflare drops the traffic.
The following table exemplifies how to use geographic scoping for routes:
| Prefix | NextHop | Priority | Region code |
|---|---|---|---|
10.10.10.100/24 |
TUNNEL_1_IAD |
100 |
AFR |
10.10.10.100/24 |
TUNNEL_2_IAD |
100 |
EEUR |
10.10.10.100/24 |
TUNNEL_3_ATL |
100 |
ENAM |
10.10.10.100/24 |
TUNNEL_4_ATL |
100 |
ME |
10.10.10.100/24 |
TUNNEL_5_ATL |
100 |
WNAM |
10.10.10.100/24 |
TUNNEL_4_ATL |
100 |
ENAM |
When there are multiple routes to the same prefix with equal priority, and those routes are assigned to different geographic regions (like WNAM and ENAM), traffic entering the network in a specific region — for example, WNAM — egresses through the route associated with that same region.
Anycast routing
Cloudflare uses anycast to route traffic. Anycast is a network addressing and routing method that routes incoming requests to different locations. Traffic can arrive at a different geographic location than expected. Not all requests go to the closest data center because Internet routing and peering relationships are complex, and Cloudflare optimizes for performance and reliability.
Region codes and associated regions
Cloudflare has nine geographic regions:
| Region code | Region |
|---|---|
AFR |
Africa |
APAC |
Asia Pacific |
EEUR |
Eastern Europe |
ENAM |
Eastern North America |
ME |
Middle East |
OC |
Oceania |
SAM |
South America |
WEUR |
Western Europe |
WNAM |
Western North America |
Configure scoping for your traffic in the Region code section when adding or editing a static route. Refer to Create a static route and Edit a static route for more information.
Magic Transit prefix mapping
Map route prefixes smaller than /24
You must provide your prefixes and the tunnels that should be mapped to for Cloudflare to route your traffic from our global network to your data centers through anycast tunnels. Use the following table as reference.
| Prefix | NextHop |
|---|---|
103.21.244.0/29 |
TUNNEL_1_IAD |
103.21.244.8/29 |
TUNNEL_2_ATL |
The minimum advertising prefix is /24, but because Cloudflare uses anycast tunnels as an outer wrapper for your traffic, Cloudflare can route prefixes within that /24 to different tunnel endpoints. For example, you can send x.x.x.0/29 to Data Center 1 and x.x.x.8/29 to Data Center 2. This is helpful when you operate in an environment with constrained IP resources.
Map route prefixes bigger than onboarded prefixes
If you have multiple onboarded /24 subnets that belong to a larger contiguous block, you can configure a summary static route for the corresponding supernet (like a /23 or a /22) instead of adding each /24 individually. This eliminates the need to configure each /24 route, as all traffic will be routed through the same GRE tunnels.
For example, if you have two tunnels:
192.0.2.0/24192.0.3.0/24
You can summarize these into a single 192.0.2.0/23.
Refer to Add tunnels to learn more about configuring GRE tunnels.
Note
These address blocks are a part of
and are reserved for use as examples in documentation.
Equal-cost multi-path routing
Equal-cost multi-path routing uses hashes calculated from packet ↗︎ data to determine the route chosen. The hash always uses the source and destination IP addresses. For TCP and UDP packets, the hash includes the source and destination ports as well. The ECMP algorithm divides the hash for each packet by the number of equal-cost next hops. The modulus (remainder) determines the route the packet takes.
Using ECMP has a number of consequences:
- Routing to equal-cost paths is probabilistic.
- Packets in the same session with the same source and destination have the same hash. The packets also use the same next hop.
- Routing changes in the number of equal-cost next hops can cause traffic to use different tunnels. For example, dynamic reprioritization triggered by health check events can cause traffic to use different tunnels.
As a result, ECMP provides load balancing across tunnels with the same prefix and priority.
Note
Packets in the same flow use the same tunnel unless the tunnel priority changes. Packets for different flows can use different tunnels depending on which tunnel the flow's 4-tuple — source and destination IP and source and destination port — hash to.
Examples
This diagram illustrates how ECMP distributes traffic equally across two paths with the same prefix and priority.
Normal traffic flow
flowchart LR
accTitle: Tunnels diagram
accDescr: This example has three tunnel routes, with traffic equally distributed across two paths.
subgraph Cloudflare
direction LR
B[Cloudflare <br> data center]
C[Cloudflare <br> data center]
D[Cloudflare <br> data center]
end
Z("Load balancing for some <br> priority tunnels uses ECMP <br> (hashing on src IP, dst IP, <br> scr port, dst port)") --- Cloudflare
A((User)) --> Cloudflare --- E[Anycast IP]
E[Anycast IP] --> F[/"GRE Tunnel 1 / <br> priority 1 / <br> ~50% of flows"/] --> I{{Customer <br> data center/ <br> network 1}}
E[Anycast IP] --> G[/"GRE Tunnel 2 / <br> priority 1 / <br> ~50% of flows"/] --> J{{Customer <br> data center/ <br> network 2}}
E[Anycast IP] --> H[/GRE Tunnel 3 / <br> priority 2 / <br> 0% of flows/] --o K{{Customer <br> data center/ <br> network 3}}
Failover traffic flow: Scenario 1
Customer router failure
When Magic Transit health checks determine that Tunnel 2 is unhealthy, Magic Transit dynamically de-prioritizes that route, leaving Tunnel 1 as the sole top-priority route. As a result, Magic Transit steers traffic away from Tunnel 2, and all traffic flows to Tunnel 1.
flowchart LR
accTitle: Tunnels diagram
accDescr: This example has Tunnel 2 unhealthy, and all traffic prioritized to Tunnel 1.
subgraph Cloudflare
direction LR
B[Cloudflare <br> data center]
C[Cloudflare <br> data center]
D[Cloudflare <br> data center]
end
Z(Tunnel health is <br> determined by <br> health checks that <br> run from all Cloudflare <br> data centers) --- Cloudflare
A((User)) --> Cloudflare --- E[Anycast IP]
E[Anycast IP] --> F[/"Tunnel 1 / <br> priority 1 / <br> ~100% of flows"/]:::green --> I{{Customer <br> data center/ <br> network 1}}
E[Anycast IP] --> G[/Tunnel 2 / <br> priority 3 / <br> unhealthy / 0% of flows/]:::red --x J{{Customer <br> data center/ <br> network 2}}
E[Anycast IP] --> H[/Tunnel 3 / <br> priority 2 / <br> 0% of flows/] --o K{{Customer <br> data center/ <br> network 3}}
classDef red fill:#EE4B2B,color: black
classDef green fill:#00FF00,color: black
Failover traffic flow: Scenario 2
Intermediary Internet Service Provider (ISP) failure
When Magic Transit determines that Tunnel 1 is unhealthy as well, that route is also de-prioritized, leaving Tunnel 3 with the top priority route. In that case, all traffic flows to Tunnel 3.
flowchart LR
accTitle: Tunnels diagram
accDescr: This example has Tunnel 1 and 2 unhealthy, and all traffic prioritized to Tunnel 3.
subgraph Cloudflare
direction LR
B[Cloudflare <br> data center]
C[Cloudflare <br> data center]
D[Cloudflare <br> data center]
end
Z(Lower-priority tunnels <br> are used when <br> higher-priority tunnels <br> are unhealthy) --- Cloudflare
A((User)) --> Cloudflare --- E[Anycast IP]
E[Anycast IP] -- Intermediary <br> network issue --> F[/Tunnel 1 / <br> priority 3 / <br> unhealthy / 0% of flows/]:::red --x I{{Customer <br> data center/ <br> network 1}}
E[Anycast IP] -- Intermediary <br> network issue --> G[/Tunnel 2 / <br> priority 3 / <br> unhealthy / 0% of flows/]:::red --x J{{Customer <br> data center/ <br> network 2}}
E[Anycast IP] --> H[/Tunnel 3 / <br> priority 2 / <br> 100% of flows/]:::green --> K{{Customer <br> data center/ <br> network 3}}
classDef red fill:#EE4B2B,color: black
classDef green fill:#00FF00,color: black
When Magic Transit determines that Tunnels 1 and 2 are healthy again, it re-prioritizes those routes, and traffic flow returns to normal.
ECMP and bandwidth utilization
Because ECMP is probabilistic, the algorithm routes roughly the same number of flows through each tunnel. However, it does not consider the amount of traffic already sent through a tunnel when deciding where to route the next packet.
For example, consider a scenario with many very low-bandwidth TCP connections and one very high-bandwidth TCP connection. Packets for the high-bandwidth connection have the same hash and thus use the same tunnel. As a result, that tunnel utilizes greater bandwidth than the others.
Note
Magic Transit supports a weight field that you can apply to a route so that a specified percentage of traffic uses a certain tunnel rather than other equal-cost tunnels. Refer to Route prioritization for more information.
For example, in a scenario where you want to route 70% of your traffic through ISP A and 30% through ISP B, you can use the weight field to help achieve that.
Because ECMP balances flows probabilistically, the use of weights is only approximate.
For more on Magic Transit tunnel weights, contact your Cloudflare customer service manager.
BGP information
Using BGP peering with your Cloudflare One or Magic Transit network routing table allows you to automate the process of adding or removing networks and subnets. BGP does not replace tunnel health checks. Refer to Tunnel health checks.
With this functionality, you can:
- Establish an eBGP session between your devices and the Magic Transit service when connected through CNI, GRE or IPsec tunnels.
- Secure the session by MD5 authentication to prevent misconfigurations.
- Exchange routes dynamically between your devices and your Magic Transit network routing table.
Release status
The following table outlines the current availability and recommended use cases for BGP across different connectivity methods.
| Feature | Release stage | Recommended use | Prerequisites |
|---|---|---|---|
| BGP over Anycast IPsec/GRE | Generally available | Production workloads | Available to all Unified Routing accounts; no enablement required |
| BGP over CNI | Closed beta | Not available to new customers — contact your account team | Cloudflare Network Interconnect (CNI) v2 |
