Network DDoS Protection, BGP Anycast, Tunnels, and Egress
How Magic Transit protects IP networks with BGP, GRE and IPsec tunnels, BYOIP or leased IPs, egress routing, and edge packet firewalling.
This page summarises Cloudflare documentation on Magic Transit: an enterprise network-layer service that fronts your public IP space with DDoS mitigation, optional traffic acceleration, and integrated packet filtering. It applies to on-premises, cloud-hosted, and hybrid networks where you need to protect entire prefixes rather than only HTTP applications behind a reverse proxy.
Magic Transit: what it is and when you need it
Section titled “Magic Transit: what it is and when you need it”Magic Transit is a network security and performance solution for Distributed Denial of Service (DDoS) protection and related controls at OSI layer 3 (IP). It is aimed at teams that own publicly routable IP prefixes (data centers, ISP edge, multi-cloud front doors) and need mitigation capacity beyond local appliances or constrained Internet links.
Magic Transit is a network security and performance solution that offers Distributed Denial of Service (DDoS) protection, traffic acceleration, and more for on-premise, cloud-hosted, and hybrid networks.
— Cloudflare, About Magic Transit
Magic Transit acts as the front door to your IP network: it accepts packets destined for your space, inspects and processes them, then delivers clean traffic to your origin over GRE, IPsec, or Cloudflare Network Interconnect (CNI). Magic Transit is not self-serve; you start by engaging Cloudflare to scope prefix count and implementation timing (Get started). Cloudflare’s China Network does not yet support Magic Transit.
| Situation | Typical fit |
|---|---|
| Volumetric L3/L4 attacks against your own IP ranges | Magic Transit (always-on or on-demand) |
| Only HTTP zones on Cloudflare proxy | Application DDoS on zones; not a substitute for full prefix protection |
Smaller networks without a customer /24 |
Cloudflare IPs (leased space) |
| B2B partners expect traffic from your public IPs | Bring Your Own IP (BYOIP) |
How BGP anycast and tunnels onboard ingress traffic
Section titled “How BGP anycast and tunnels onboard ingress traffic”Ingress Magic Transit works by announcing your protected prefixes (or Cloudflare-leased prefixes) from Cloudflare’s global network via Border Gateway Protocol (BGP) and anycast, so Internet traffic is ingested close to sources and scrubbed at the edge.
Magic Transit delivers its connectivity, security, and performance benefits by serving as the front door to your IP network. This means it accepts IP packets destined for your network, processes them, and then outputs them to your origin infrastructure. The Cloudflare network uses Border Gateway Protocol (BGP) to announce your company’s IP address space, extending your network presence globally, and anycast to ingest your traffic.
— Cloudflare, About Magic Transit
After mitigation (and optional Cloudflare Network Firewall filtering), clean traffic is handed to you through anycast GRE or IPsec tunnels over the Internet or CNI for private handoff (Magic Transit Reference Architecture). You configure tunnels in the dashboard or API (Configure tunnel endpoints).
IP prefix size, BYOIP, and Letter of Agency (LOA)
Section titled “IP prefix size, BYOIP, and Letter of Agency (LOA)”To use Magic Transit with your own space, you need a publicly routable block of at least /24—the smallest size Cloudflare can generally announce on your behalf, matching common ISP acceptance of /24 in the global table (Magic Transit Reference Architecture).
To use Magic Transit, you need to own a publicly routable IP address block with a minimum size of /24. If you do not own a /24 address block, you can use Magic Transit with a Cloudflare-owned IP address.
— Cloudflare, Cloudflare IPs
For customer-owned prefixes, BYOIP onboarding requires a Letter of Agency (LOA) so Cloudflare can provision and advertise your ranges (Bring your own IP space). Cloudflare-leased IPs do not require an LOA; leased setups typically enable Magic Transit Egress automatically, with policy-based routing (PBR) on your side for correct return paths (Cloudflare IPs).
During cutover, you normally stop advertising the same specific prefixes from your border routers (or advertise less-specific cover routes for backup failover) so Internet traffic is attracted to Cloudflare (Protect public networks with Cloudflare).
Ingress-only DSR vs Magic Transit egress (symmetric paths)
Section titled “Ingress-only DSR vs Magic Transit egress (symmetric paths)”You choose ingress only or ingress and egress.
Default (ingress only) uses Direct Server Return (DSR): client-to-server traffic flows through Cloudflare; server responses leave via your ISP default route and do not traverse Cloudflare tunnels.
By default, Magic Transit processes traffic in the ingress direction only (from the Internet to the customer network). The server return traffic back to the clients is routed by the customer’s DC edge router via its uplinks to the Internet/ISP based on the edge router’s default routing table. This server return traffic will not transit through Cloudflare via tunnels. This is referred to as Direct Server Return (DSR).
— Cloudflare, Magic Transit Reference Architecture
Egress sends both directions through Cloudflare—useful for symmetric filtering, leased-IP source addresses that must exit via Cloudflare, and some hybrid cloud designs (Egress traffic).
Egress requirements in brief:
- Source IPs must belong to your Magic Transit prefix; destinations must be public, non–RFC 1918 routable addresses.
- Use PBR (or a careful default route) so only authorised prefixes use GRE/IPsec toward Cloudflare.
- Configure tunnel failure detection so PBR fails over when upstream to Cloudflare breaks.
- For egress, prefer bidirectional tunnel health checks (Egress traffic).
Longest Prefix Match matters when you split announcements: Internet traffic to a more specific prefix at your ISP still reaches you there, while Cloudflare-originated traffic to the same hosts may use Magic Transit tunnels when a covering prefix is advertised from Cloudflare—counting toward bandwidth (Bandwidth measurement).
Cloudflare Network Firewall with Magic Transit packet rules
Section titled “Cloudflare Network Firewall with Magic Transit packet rules”Cloudflare Network Firewall (FWaaS at layers 3 and 4) ships with Magic Transit (and Cloudflare WAN). Rules use Wireshark-inspired syntax and can match IP, port, protocol, packet length, bit fields, and related attributes (Overview).
Order of enforcement: DDoS mitigations run before Network Firewall; allowing traffic in the firewall does not override DDoS blocks.
Cloudflare Network Firewall rules are performed after Cloudflare’s DDoS mitigations have been applied. The two systems are independent, and therefore, permitting traffic inside Cloudflare Network Firewall does not allow it within our DDoS mitigations.
— Cloudflare, Ruleset logic
For egress, Network Firewall is not stateful in both directions after DDoS mitigations. A default drop on ingress may block outbound unless you add an earlier rule permitting traffic from your Magic Transit prefix to any destination (Magic Transit egress best practices). Rules apply to ingress and egress paths through Cloudflare (Egress traffic).
North-south protection can be combined with Cloudflare Gateway for DNS and HTTP policy on outbound Internet flows; east-west corporate traffic is often Cloudflare WAN instead of Magic Transit alone.
Bandwidth billing, always-on vs on-demand protection
Section titled “Bandwidth billing, always-on vs on-demand protection”Clean bandwidth (egress from Cloudflare to your network after DDoS and firewall) is measured at 95th percentile from five-minute samples; attack traffic blocked at the edge is excluded (Bandwidth measurement). Subscribed bandwidth is a billing metric—Cloudflare does not throttle when you exceed contracted use; overages follow contract terms.
Always-on routes traffic through Cloudflare continuously for fastest mitigation (Magic Transit Reference Architecture). On-demand keeps peacetime on your normal transit; Network Flow analyses flow telemetry (NetFlow, IPFIX, sFlow) and can trigger prefix advertisement automatically (Magic Transit integration). ISP-scale designs are described in Protect ISP and telecommunications networks from DDoS attacks.
In analytics, Ingress is Internet toward your network via Cloudflare; Egress is your network out through Cloudflare when egress is enabled (Network Analytics dashboard).
Router requirements and pre-flight checks before go-live
Section titled “Router requirements and pre-flight checks before go-live”Tunnel endpoint routers should support GRE (or IPsec if GRE is unavailable), at least one tunnel per ISP, MSS clamping, and asymmetric flows for ingress-only DSR (Get started).
Before production advertisement, Cloudflare validates tunnels, health checks, LOA, IRR, and MSS; global config rollout takes about one day (Run pre-flight checks). On your side:
- Confirm upstream ISPs use uRPF loose, not strict, or expect packet loss after Cloudflare originates your prefix.
- Align MSS/MTU on GRE/IPsec paths (CNI often preserves 1500-byte MTU).
- Monitor BGP peering to Cloudflare yourself; Cloudflare does not alert on peer loss.
Common mistakes
Section titled “Common mistakes”- Enabling strict uRPF at the ISP while Cloudflare announces your prefix.
- Default drop Network Firewall rules without an egress permit for your Magic Transit source range.
- Assuming stateful firewall behaviour on Magic Transit egress (Magic Transit egress best practices).
- Overlapping BGP specifics: a more specific at the ISP bypasses Magic Transit for Internet-originated traffic while Cloudflare-originated traffic may still use tunnels (Bandwidth measurement).
- Treating concentrator traffic (VPN, NAT, SaaS meeting IPs) as attack floods without tuning—see Third-party services and DDoS protection.
After onboarding, validate mitigation layers and consider controlled network-layer simulation tests on your own prefixes (Verify DDoS protection); HTTP-only DDoS tests require reverse-proxy onboarding, not Magic Transit alone.
How to check this on your site
Section titled “How to check this on your site”- Confirm which prefixes are onboarded, whether you use BYOIP or Cloudflare-leased IPs, and that tunnel/CNI health checks are green in the Magic Transit dashboard (Get started).
- From an external vantage, verify BGP paths attract protected prefixes to Cloudflare and that return paths match your design (DSR vs egress PBR) (Magic Transit Reference Architecture).
- Review Network Analytics Direction filters for expected ingress/egress volumes and attack visibility.
- Audit Cloudflare Network Firewall rules for egress permits if you use default-drop posture (Magic Transit egress best practices).
- You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”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, and we will correct or clarify it.