Skip to content

Magic Transit overview: L3 BGP-routed DDoS protection for your IP space

Magic Transit advertises your /24 or /48 from Cloudflare's anycast network, scrubs traffic, and tunnels clean packets back to your origin over GRE or direct CNI. When this fits and when a reverse proxy is enough.

Magic Transit is the right shape when you own IP space, your services aren’t all HTTP, and a reverse proxy can’t do what you need. Instead of pointing DNS at Cloudflare’s anycast addresses, you advertise your own /24 (IPv4) or /48 (IPv6) into Cloudflare’s BGP, traffic gets scrubbed at the edge, and clean packets ride back to your origin over GRE tunnels or a direct interconnect. This article covers when that model fits — for network teams evaluating whether to lift an entire network behind Cloudflare versus running the existing reverse-proxy zones.

How to verify

Before signing anything, confirm you actually own the IP space and have authority to advertise it. The ARIN/RIPE WHOIS, your LOA template, and a working BGP session to Cloudflare’s onboarding are the gates.

# Confirm WHOIS ownership and the AS-SET / route objects
whois 203.0.113.0/24
whois -h whois.radb.net '!gAS65000'

# Once Magic Transit is live, verify your prefix is being announced
# from Cloudflare's anycast network (check from outside your own AS)
curl -sS "https://api.bgp.tools/prefix/203.0.113.0/24/upstreams" | jq

# Confirm tunnel state from your edge router (Linux GRE example)
ip -s tunnel show gre1
ip route show table 200 | grep 203.0.113

# Check Magic Transit health endpoint exposed by Cloudflare for your account
curl -sS "https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/magic/cf_interconnects" \
  -H "Authorization: Bearer ${CF_API_TOKEN}" | jq '.result[]'

In the dashboard: Magic Transit → Health Checks shows tunnel state per interconnect; Magic Transit → IP Prefixes lists what Cloudflare is announcing on your behalf.

What’s happening

Magic Transit moves you from “Cloudflare is a reverse proxy for HTTP” to “Cloudflare is your transit provider for everything”. The mental shift matters because everything downstream changes.

In a reverse-proxy CDN posture, your DNS resolves to Cloudflare anycast IPs (104.x, 172.x), Cloudflare terminates the TCP/TLS connection, and your origin sees Cloudflare-source IPs hitting your public IP. Non-HTTP services either bypass Cloudflare entirely or need Spectrum to be proxied at all. Source IPs require CF-Connecting-IP header restoration. The protection extends only to whatever you’ve deliberately put in front of Cloudflare.

With Magic Transit, you advertise your own prefix into Cloudflare’s BGP. Cloudflare announces it on the public internet from their anycast edge. Traffic for 203.0.113.0/24 arrives at the nearest Cloudflare data centre. The network-layer Managed Ruleset and the always-on L3/L4 protection scrub it. Clean traffic is encapsulated and shipped back to your physical network — over GRE tunnels riding the public internet, over IPsec, or over a direct cross-connect (Cloudflare Network Interconnect, CNI) into a colo facility. Your origin sees the original client IPs, on the original ports, with no rewriting.

This unlocks two things a reverse proxy can’t: protection for non-HTTP services on their native ports (SSH, custom TCP, UDP game servers, RDP) without per-service Spectrum config, and protection for your entire IP block at once — including services you haven’t deliberately registered yet. The trade is that you now have a routing relationship with Cloudflare. Tunnels can flap, BGP sessions can de-peer, and your network team has to operate the on-ramp.

InternetClients +attack sources203.0.113.0/24Cloudflare anycast edgeL3/L4 scrubbing + Network DDoS RulesetSYN floods, UDP amp, malformed packets droppedAttack dropxClean trafficforwardBGP session: customer AS → AS13335/24 IPv4 or /48 IPv6 advertisedGRE / CNICustomer networkEdge routerOrigin servicesnative portsOutbound (asymmetric) or symmetric routing optionsAsymmetric: out via ISPreturn path bypasses CFSymmetric: out via CFall egress via tunnel
Magic Transit advertises your IP space, scrubs at the anycast edge, returns clean packets via GRE or CNI.

The procedure

The onboarding is mostly paperwork and BGP — the dashboard work is small. Plan four to six weeks for the first prefix.

  1. Inventory the IP space. What prefixes do you own, are the WHOIS / RPKI records clean, and what services live on them today? Magic Transit needs at least a /24 for IPv4 or a /48 for IPv6 because that’s the smallest prefix the global routing table will accept.

  2. Sign the LOA (Letter of Authorization). This is Cloudflare’s authorization to announce your prefix from AS13335. Cloudflare onboarding will share the template; your network team signs it on the same letterhead as your RIR records.

  3. Choose the on-ramp. Three options:

    • GRE tunnels over the public internet — fastest to set up, works from any router with GRE support. Higher latency variance, MTU considerations (1476 with GRE overhead).
    • IPsec tunnels — encrypts the leg from Cloudflare back to you. Use when GRE over public internet is a compliance non-starter.
    • Cloudflare Network Interconnect (CNI) — direct cross-connect at a colo where Cloudflare is present (Equinix, Megaport, etc.). No internet leg.
  4. Configure the BGP session. Cloudflare provides their side; you configure your edge router. Cisco IOS-XR fragment:

    router bgp 65000
     neighbor 162.159.x.x
      remote-as 13335
      description Cloudflare Magic Transit primary
      password <shared-secret>
      address-family ipv4 unicast
       route-policy CF-IN in
       route-policy CF-OUT out
      !
    !
  5. Deploy the Network-layer DDoS Managed Ruleset. Magic Transit → Configuration → DDoS Protection → Deploy. Defaults are fine to start; override per-prefix only after you see false positives in attack analytics.

  6. Test failover. Bring down one tunnel and confirm BGP withdraws from that interconnect; clean traffic should ride the surviving tunnel within seconds. Document the runbook.

  7. Decide on Magic WAN if you want SD-WAN replacement on top. Magic WAN extends Magic Transit so all your sites, VPCs, and remote users tunnel into Cloudflare’s network. Same anycast edge, broader scope — useful if you’re already replacing branch SD-WAN.

Common pitfalls

  • Advertising a prefix that overlaps an existing announcement somewhere else — global routing prefers more specifics, and you can blackhole your own traffic.
  • Forgetting RPKI — Cloudflare validates origin signatures and will not announce an unsigned prefix in regions where RPKI is enforced.
  • Setting up only one GRE tunnel — without redundancy, a single tunnel flap takes the whole prefix offline.
  • Misaligned MTU on GRE — applications work for small packets and silently fail on large POSTs; set TCP MSS clamping on your edge.
  • Conflating Magic Transit with Spectrum — Spectrum proxies named services (see cf-spectrum-non-http-tcp-udp); Magic Transit covers your whole prefix.

Stack Harbor’s network engineers handle the BGP session config, the LOA paperwork, and the tunnel runbook on the client’s edge router as part of managed operations — including the failover drill before the first real attack.