Configure routes·续
Set up BGP peering
You need to configure two ASNs:
- The Cloudflare account-scoped ASN named CF Account ASN.
- One ASN for each on-ramp you want to configure with BGP.
If you have already set up your Cloudflare account ASN, skip steps two and three below.
Set up BGP for an interconnect
Note
BGP over CNI is in closed beta and is not currently available to new customers. If you are interested in BGP peering over CNI, contact your account team.
- Go to the Routes page. Go to Routes ↗
- Select WAN configuration.
- In CF Account ASN, enter Cloudflare's ASN, and select Update.
- Go to Interconnects. Go to Interconnects ↗
- Locate the CNI interconnect with Dataplane v2 to configure with BGP > select the three dots next to it > Configure BGP.
- In Customer device ASN, enter the ASN for your network.
Note Multiple tunnels or interconnects with the same ASN will not exchange routes if standard BGP loop prevention is enabled. Consider using a different ASN per session, or enabling duplicate ASNs (like Cisco's allowas-in feature) to exchange routes between networks.
7. In MD5 key, you can optionally enter the key for your network. Note that this is meant to prevent accidental misconfigurations and is not a security mechanism.
8. (Optional) In Additional Advertised prefix list, input any additional prefixes you want to advertise alongside your existing routes. Leave this blank if you do not want to advertise extra routes. Typical prefixes to configure here include:
- A route to 0.0.0.0/0, the default route — to attract all Internet-bound traffic if using Cloudflare WAN with Gateway.
- A route to 100.96.0.0/12, the portion of CGNAT space used by default with Cloudflare One Clients.
- A route to 100.64.0.0/12, the portion of CGNAT space used by default for Cloudflare Source IPs.
9. Select Save.
Set up BGP for IPsec/GRE tunnels
- Go to the Routes page. Go to Routes ↗
- Select WAN configuration.
- In CF Account ASN, enter Cloudflare's ASN, and select Update.
- Go to Connectors. Go to Connectors ↗
- In IPsec/GRE tunnels, locate the tunnel you want to configure with BGP > select the three dots next to it > Configure BGP.
- In Customer device ASN, enter the ASN for your network.
Note Multiple tunnels or interconnects with the same ASN will not exchange routes if standard BGP loop prevention is enabled. Consider using a different ASN per session, or enabling duplicate ASNs (like Cisco's allowas-in feature) to exchange routes between networks.
7. In MD5 key, you can optionally enter the key for your network. Note that this is meant to prevent accidental misconfigurations and is not a security mechanism.
8. (Optional) In Additional Advertised prefix list, input any additional prefixes you want to advertise alongside your existing routes. Leave this blank if you do not want to advertise extra routes. Typical prefixes to configure here include:
- A route to 0.0.0.0/0, the default route — to attract all Internet-bound traffic if using Cloudflare WAN with Gateway.
- A route to 100.96.0.0/12, the portion of CGNAT space used by default with Cloudflare One Clients.
- A route to 100.64.0.0/12, the portion of CGNAT space used by default for Cloudflare Source IPs.
9. Select Save.
Important remarks for GRE/IPsec tunnels
If you are configuring BGP peering for a tunnel (GRE or IPsec) you must be aware of the following:
- Your Customer Premises Equipment (CPE) must initiate the BGP peering session. Cloudflare will not initiate.
- Your BGP speaker must peer with the tunnel's IPv4 interface address. Your CPE may use any IPv4 address for its side of the peering connection; it does not need to use the other address from the
/31or/30interface subnet.
Caution
If the tunnel is to an Azure VPN gateway, the tunnel interface address must not be in the link-local range. Azure will not initiate BGP sessions to peers using link-local addresses. Use an RFC 1918 address for your tunnel interface address instead.
- Hold time must be 30 seconds or greater. Cloudflare recommends at least 90 seconds. Cloudflare advertises a hold time of 240 seconds, so if you set a value greater than 240 seconds, the negotiated hold time will be 240 seconds.
- Connect retry time should be low (for example, five or 10 seconds).
- Your CPE may advertise up to 5,000 prefixes on one BGP session.
- MD5 authentication is optional. You can use a maximum of 80 characters. Supported characters include a-zA-Z0-9'!@#$%^&*()+[]{}<>/.,;:_-~`= \\|
Caution
MD5 authentication is not a valid security mechanism. The MD5 key is not treated as a secret value. This is only supported for preventing misconfiguration, not for defending against malicious attacks.
When MD5 is enabled, you cannot use Telnet to test BGP connectivity (Telnet does not support TCP MD5 authentication).
Filter BGP routes
BGP filter profiles control routes exchanged over your peering session with Cloudflare. They apply to BGP over GRE or IPsec tunnels.
Each account-scoped profile requires a unique name, one match action, and up to 1,000 Classless Inter-Domain Routing (CIDR) targets.
Match actions have the following behavior:
| Match action | Behavior |
|---|---|
allow |
Accept matching routes and reject everything else. |
deny |
Reject matching routes and accept everything else. |
Each CIDR target has a matching mode that determines whether the prefix and its subnets match:
| Matching mode | Syntax | Matches |
|---|---|---|
| Exact prefix | 10.0.0.0/8 |
Only 10.0.0.0/8. |
| Prefix and more-specific routes | 10.0.0.0/8+ |
10.0.0.0/8 and every more-specific subnet. |
| Exact length | 10.0.0.0/8{16} |
Every /16 subnet within 10.0.0.0/8. |
| Length range | 10.0.0.0/8{16,24} |
Every /16 through /24 subnet within the prefix. |
Each tunnel supports one import filter and one export filter.
Import filters apply to routes Cloudflare receives from the peer. Rejected routes do not enter the Magic routing table. Rejected routes remain in the local routing information base (RIB-in). Making the filter more permissive adds them to the Magic routing table without a route refresh.
Export filters apply to routes selected for peer advertisement. Prefixes in the tunnel's extra_prefixes field bypass export filters.
Create profiles
- Go to the Routes page. Go to Routes ↗
- From the BGP filter profiles tab, select Create filter profile.
- Enter a descriptive Name for your filter profile and optionally add a Description.
- Choose Allow or Deny as the Action to take when a route matches a target.
- Add a Target by entering a CIDR prefix in CIDR prefix. Choose which Match mode this target should use.
- If you want to add more targets, choose Add target.
- Select Create.
You need your account ID and API token to use the API.
The following request creates an allow profile for corporate subnets:
Create BGP Filter Profilebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/bgp/filter_profiles" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Allowed on-premises imports",
"description": "Corporate subnets accepted from the customer router",
"match_action": "allow",
"targets": [
"10.0.0.0/8+",
"192.168.0.0/16",
"2001:db8::/32+"
]
}'
Profile targets have these requirements:
- Targets must use valid CIDR network addresses without whitespace. Cloudflare rejects duplicate or equivalent targets.
- Profiles support IPv4 and IPv6 targets, but not IPv4-mapped IPv6 targets.
Assign profiles
- Go to the Connectors page and choose IPsec/GRE tunnels. Go to Connectors ↗
- Choose Create a tunnel to make a new tunnel or choose Configure BGP from the three-dot menu next to an existing tunnel.
- Select a profile from Import filter profile. To remove it, select X next to the selected profile.
- Repeat for Export filter profile.
- Choose Add tunnels or Save.
The following request assigns import and export profiles to a GRE tunnel. Set each field to a profile ID from your account.
<details>
<summary>
Required API token permissions
</summary>
At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:
- <code>Magic WAN Write</code>
- <code>Magic Transit Write</code>
</details>
Update GRE Tunnelbash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/gre_tunnels/$GRE_TUNNEL_ID" \
--request PUT \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"bgp": {
"import_filter_id": "a1b2c3d4e5f647890a1b2c3d4e5f6789",
"export_filter_id": "b2c3d4e5f6a78901b2c3d4e5f6a78901"
}
}'
To remove an assigned profile, set its corresponding field to null.
Profile assignments have these behaviors and limits:
- Changing a profile or a tunnel's profile assignments does not reset BGP sessions.
- You cannot delete an in-use profile. Detach the profile from all tunnels first.
- Cloudflare enforces the 5,000-route RIB-in limit before import filtering. Rejected routes still count toward this limit.
Next steps
Now that you have configured your tunnels and routes, the next step is to create a site. Sites represent the local network of a data center, office, or other physical location, and combine all on-ramps available there. Sites also allow you to check, at a glance, the state of your on-ramps and set up health alert settings so that Cloudflare notifies you when there are issues with the site's on-ramps.
Refer to Set up a site for more information.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/cloudflare-wan/configuration/how-to/configure-routes/#page","headline":"Configure routes","description":"Cloudflare WAN uses a static configuration to route your traffic through anycast tunnels from Cloudflare's global network to your locations. You can also use BGP peering to exchange routes dynamically. Learn how to configure routing.","url":"https://developers.cloudflare.com/cloudflare-wan/configuration/how-to/configure-routes/","inLanguage":"en","image":"https://developers.cloudflare.com/cloudflare-wan/configuration/how-to/configure-routes/og.png?v=03c6dce35e8aa24d","dateModified":"2026-10-15","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Learn how to configure IPsec or GRE tunnels for Cloudflare WAN. title: Configure tunnel endpoints image: https://developers.cloudflare.com/cloudflare-wan/configuration/how-to/configure-tunnel-endpoints/og.png?v=d3c061b9d5f16e47
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/cloudflare-wan/llms.txt
Use this file to discover all available pages before exploring further.
Docs