Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

BGP IP Prefix Advertisement, Virtual Network Peering, and Withdrawal

How Cloudflare Magic Transit and Cloudflare WAN control edge prefix ads, tunnel BGP peering, AS prepends, and safe BYOIP withdrawal.

This page summarizes Cloudflare documentation on two related problems operators confuse: announcing your IP prefixes to the Internet through Cloudflare’s anycast edge (Bring Your Own IP, or BYOIP), and exchanging routes over BGP with the Magic Transit or Cloudflare WAN virtual network routing table through GRE, IPsec, or Network Interconnect (CNI). Edge advertisement steers public traffic; virtual-network BGP steers traffic inside your Cloudflare overlay. They use different sessions, ASNs, and control planes.

Edge prefix advertisement: what “Advertised” and “Withdrawn” mean

Section titled “Edge prefix advertisement: what “Advertised” and “Withdrawn” mean”

Dynamic advertisement lets you choose when Cloudflare announces your onboarded IP prefixes to the global Internet. While a prefix is Advertised, Cloudflare originates BGP for those addresses so traffic can reach Magic Transit protection. While Withdrawn, Cloudflare stops announcing; traffic follows whatever other BGP paths exist.

Dynamic advertisement allows you to control when Cloudflare announces your IP prefixes via BGP. When a prefix is advertised, Cloudflare announces it to the Internet so that traffic destined for those IPs can be routed to Cloudflare. When a prefix is withdrawn, Cloudflare stops announcing it — traffic will then follow whatever other BGP routes exist for that prefix.

— Cloudflare, Dynamic advertisement

You can toggle status in the dashboard or API. Enabling advertisement typically takes two to seven minutes; disabling or withdrawing takes about 15 minutes. For BYOIP onboarding, Cloudflare creates the BGP prefix withdrawn until bindings are ready; you advertise only after configuration is complete.

You cannot advertise until Cloudflare finishes pre-flight checks (tunnel health, LOA, IRR, MSS, and related validation). If a prefix is grayed out as Withdrawn and locked, contact your account team to complete pre-flight and unlock prefixes, as described in Advertise prefixes.

After checks complete:

Once pre-flight checks are completed, Cloudflare unlocks your prefixes for you to advertise via the dashboard, API or BGP at a time of your choosing.

— Cloudflare, Advertise prefixes

If you use Cloudflare-leased IPs, you do not advertise your own prefixes. Magic Transit on-demand cannot be used with Cloudflare leased IPs.

For anycast edge announcements you choose whether Cloudflare uses your ASN or AS13335:

If you supply your own ASN, Cloudflare prepends the main Cloudflare ASN (AS13335) to the BGP AS_PATH. For example, if your ASN is AS64496, anyone directly peering with Cloudflare sees the path as 13335 64496.

— Cloudflare, Advertise prefixes

The CF Account ASN used on GRE/IPsec/CNI tunnel peering is separate: it is not exposed in edge anycast AS_PATH for Magic Transit customers, per Configure routes (Magic Transit).

A BGP prefix object is what Cloudflare anycasts. By default one BGP prefix matches the onboarded IP prefix length—a /20 onboarded block is announced as /20 unless you configure additional BGP prefix objects for more-specific announcements, as explained in Advertise prefixes.

BGP prefix advertisement control: one method per prefix

Section titled “BGP prefix advertisement control: one method per prefix”

Cloudflare offers several ways to set edge Advertised vs Withdrawn state. Pick one control method per prefix; mixing control planes causes conflicting states.

Control method How it works Typical use
Dashboard / Addressing API Manual on_demand.advertised or status dropdown Operations runbooks, on-demand DDoS
BGP to Route Reflectors eBGP sessions to Cloudflare route reflectors Large-scale or automated edge control
Network Flow Threshold-based auto-advertise Attack-driven Magic Transit on-demand
Magic Transit virtual routing table auto_advertise_withdraw tied to learned tunnel routes Unified Routing with GRE/IPsec/CNI v2

You should only use one control method per prefix at any given time. Mixing multiple control planes can lead to conflicting advertisement states, causing unpredictable routing behavior.

— Cloudflare, Advertise prefixes

Network Flow auto-advertisement works only with API/dashboard control, not with BGP-controlled edge advertisement. After auto-advertisement triggers, you must manually withdraw when the attack ends.

On the Routes page, edit the IP prefix and set Advertised or Withdrawn (Advertise prefixes). Any BGP prefix can be updated with a PATCH to the Addressing API, for example:

curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/addressing/prefixes/$PREFIX_ID/bgp/prefixes/$BGP_PREFIX_ID" \
--request PATCH \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{"on_demand":{"advertised":true}}'

Dynamic advertisement best practices recommend enabling Cloudflare advertisement before withdrawing from your data center, verifying with a looking glass on AS13335, then removing the origin advertisement—and waiting at least 15 minutes between status changes (otherwise API error 1004 rate limit).

Auto advertise/withdraw from tunnel routes

Section titled “Auto advertise/withdraw from tunnel routes”

With CNI Dataplane v2, GRE, or IPsec and Unified Routing, set auto_advertise_withdraw on the BGP prefix so edge anycast tracks exact matches in the Magic Transit Virtual Network routing table (Advertise prefixes). Subnet or supernet routes that do not exactly match the configured BGP prefix do not keep the edge announcement alive.

Virtual Network BGP peering: tunnels, CNI, and the CF Account ASN

Section titled “Virtual Network BGP peering: tunnels, CNI, and the CF Account ASN”

BGP peering with the Magic Transit or Cloudflare WAN virtual network routing table is not the same as edge anycast control. It exchanges reachability for your overlay: routes learned from your router populate the virtual table and are advertised back to your peers with the CF Account ASN prepended for loop prevention (Traffic steering (Magic Transit)).

BGP peering is available on:

BGP peering exchanges routes dynamically between your devices and your Cloudflare virtual network routing table. You no longer need to update static routes manually as your network changes.

— Cloudflare, BGP over IPsec and GRE tunnels generally available

The account-wide CF Account ASN defaults to 13335 and can be set to a private ASN 64512–65534. It must differ from each tunnel’s customer device ASN and applies to all BGP sessions in the account (Configure routes). When integrating with AWS Transit Gateway, the CF Account ASN must also differ from the AWS Transit Gateway ASN.

For Cloudflare WAN, customer AS_PATH is transitive between on-ramps; two sites using the same ASN will reject each other’s routes unless you use unique ASNs per site or CPE features such as allowas-in (Configure routes).

Your customer premises equipment (CPE) must initiate BGP; Cloudflare does not. Peer to the tunnel’s IPv4 interface address; hold time must be ≥30 seconds (Cloudflare advertises 240 seconds and negotiates the lower value). Up to 5,000 prefixes per session. Optional MD5 is for misconfiguration prevention only, not security (Configure routes). Azure VPN gateways cannot use link-local tunnel interface addresses for BGP.

Global convergence of routes learned at the ingress PoP typically completes within about 20 seconds (Traffic steering). BGP does not replace tunnel health checks.

IPsec/GRE tunnels support account-scoped BGP filter profiles: one import and one export filter per tunnel, up to 1,000 CIDR targets, allow (default deny) or deny (default permit) actions, with exact, more-specific, and length-range match syntax (Configure routes, BGP route filtering changelog). Profile changes apply without resetting the BGP session; rejected imports still count toward the 5,000-route RIB-in limit.

AS prepending and graceful BYOIP withdrawal

Section titled “AS prepending and graceful BYOIP withdrawal”

Deprioritize Cloudflare before changing providers

Section titled “Deprioritize Cloudflare before changing providers”

AS prepending lengthens the edge AS_PATH through Cloudflare so alternate providers with shorter paths attract traffic during migration. Configure asn_prepend_count from 0 to 3 via the Addressing API, or BGP communities 13335:50101–13335:50103 (Advertise prefixes, Graceful withdrawal of BYOIP prefixes).

AS prepending helps you gracefully transition traffic between network providers. By adding prepends to Cloudflare’s advertisement, you make the route through Cloudflare less preferred for some Internet network providers.

— Cloudflare, Advertise prefixes

Prepending is best-effort: peers choose paths by their own policies. Cloudflare’s internal network still prefers delivering Magic Transit traffic via configured tunnels until you withdraw the edge prefix—CDN traffic to a Magic Transit origin can keep using the overlay even if the Internet prefers a more-specific direct route (Advertise prefixes).

A sudden edge withdrawal risks stuck routes in the global DFZ when upstreams miss the withdraw and keep forwarding to an inactive next hop (Safely withdraw a BYOIP prefix). Use the same prefix length on Cloudflare and at your ISP:

  1. Announce the same-length prefix from your origin to your ISPs so a competing path exists globally.

  2. Wait five to ten minutes (or longer) for BGP convergence and traffic drain.

  3. Withdraw the prefix from Cloudflare using your chosen control method (dashboard, API, or BGP).

  4. Allow extra time for ISP table refresh; withdrawals often take longer than advertisements (Troubleshoot routing and BGP).

Optional AS prepends before withdrawal shift traffic gradually, as in Safely withdraw a BYOIP prefix and Troubleshoot routing and BGP.

Before routing changes, apply correct MSS clamps. GRE over CNI Dataplane v1 with Magic Transit typically needs 1476 bytes; Dataplane v2 or v1 with 1500-byte MTU handoff may not (Advertise prefixes). Skipping MSS clamping can cause silent packet loss.

Common mistakes:

  • Using two edge control methods on one prefix (for example Network Flow plus BGP route reflectors).
  • Expecting Network Flow to withdraw after an attack without a manual step (Network Flow FAQ).
  • Withdrawing edge routes without first advertising the same prefix elsewhere (BGP path hunting).
  • Configuring virtual-network BGP but forgetting that anycast withdrawal is still separate for Magic Transit (Traffic steering (Magic Transit)).
  • Peering with only one of three route reflectors when using BGP edge control—withdrawals must clear all sessions (Advertise prefixes).
  • Relying on a single CNI path without Internet tunnel backup during maintenance (Disruptive Maintenance).

For architecture context (CNI, DSR vs egress, packet flow), see Magic Transit Reference Architecture and Network Interconnect.

  1. In the Cloudflare dashboard Routes / IP Prefixes view, confirm BYOIP prefix status matches intent (Advertised or Withdrawn) per Dynamic advertisement best practices.
  2. After changes, wait at least the documented interval (2–7 minutes to advertise, ~15 minutes to withdraw) before toggling again or declaring failure.
  3. Use external BGP visibility guidance from Troubleshoot routing and BGP (Magic Transit)—confirm propagation timing and, if you use RPKI, that ROA records match your Cloudflare ASN setup.
  4. For tunnel BGP, verify learned routes in the dashboard or API and confirm sessions meet CPE-initiated peering and timer requirements in Configure routes.
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.