Network Firewall Ruleset Ingress Policies and Origin Restriction
How Cloudflare Network Firewall rulesets work: minimal vs extended ingress policies, stateless egress, limits, and locking down origin traffic.
This page summarizes Cloudflare Network Firewall documentation (also called Magic Firewall for Magic Transit customers) on building ingress packet-filtering policies, choosing between minimal and extended rulesets, and reducing attack surface together with origin restrictions.
Cloudflare Network Firewall default behavior: what passes before you add rules
Section titled “Cloudflare Network Firewall default behavior: what passes before you add rules”By default, Cloudflare Network Firewall permits all ingress traffic that has already passed through Cloudflare’s core DDoS mitigations. That default is permissive on purpose, but it leaves a wide inbound surface unless you add your own rules.
By default, Cloudflare Network Firewall (formerly Magic Firewall) permits all ingress traffic that has passed through Cloudflare’s core DDoS mitigations. To proactively mitigate attacks and minimize your attack surface and leakage of attack traffic into your environment, we recommend implementing your Cloudflare Network Firewall rules using the following guidelines.
— Cloudflare, Best practices
Magic Transit customers receive Network Firewall automatically. With no custom rules configured, traffic is still forwarded after mitigations:
Without any rules configured, Cloudflare Network Firewall will pass on all traffic after mitigations are applied to your tunnels.
— Cloudflare, Enable Cloudflare Network Firewall
Cloudflare recommends a ruleset tailored to your environment rather than relying on that implicit allow-all after DDoS scrubbing.
Positive vs negative security model: which ruleset approach to use
Section titled “Positive vs negative security model: which ruleset approach to use”Network Firewall policy can follow either a positive security model (allow only required traffic, deny the rest) or a negative security model (block known bad traffic, allow everything else). The same distinction appears in Cloudflare’s surge-readiness material:
Positive Security policy: Allow specific requests and deny everything else.
Negative Security policy: Block specific requests and allow everything else.
— Cloudflare, Control incoming requests
Ruleset logic states the two configuration options explicitly:
Enforce a positive security model and only permit required traffic and block everything else.
Begin with a minimal ruleset to block specific traffic and, by default, everything else is permitted.
| Approach | Typical ruleset | Best when |
|---|---|---|
| Negative (block known bad) | Minimal ruleset | First-time setup, or you cannot export perimeter rules yet |
| Positive (allow required only) | Extended ruleset | You can categorize systems on Magic Transit prefixes and define required flows |
Cloudflare calls the extended ruleset best practice for shrinking attack surface when you can adopt positive security:
The Extended ruleset is the best practice for reducing your attack surface by adopting a positive security model.
— Cloudflare, Enable Cloudflare Network Firewall
If you already run on-premises or edge firewall rules, Cloudflare’s guidance is to replicate those rules in Network Firewall when possible; otherwise contact your Implementation Manager to translate them. New deployments should start with the minimal ruleset, then move toward extended rules as maturity allows (packet-filtering best practices).
Minimal ruleset: block common DDoS reflection vectors on ingress
Section titled “Minimal ruleset: block common DDoS reflection vectors on ingress”The minimal ruleset is a suggested starting point—not exhaustive—that blocks widely abused source ports and protocols while allowing ESP, TCP, UDP, GRE, and ICMP unless your rules say otherwise.
The suggested minimal ruleset blocks some known common vectors for DDoS attacks and permits all other ESP, TCP, UDP, GRE and ICMP traffic.
— Cloudflare, Minimal ruleset
Recommended block rules (reference or managed rules)
Section titled “Recommended block rules (reference or managed rules)”Cloudflare documents three reference rules (also available as managed rules):
- UDP source ports used in attacks or invalid on Magic Transit ingress (
1900,11211,389,111,19,1194,3702,10001,20800,161,162,137,27005,520,0, and similar). - TCP source ports
21,0, and3306(SYN/ACK reflection and invalid source port0). - Protocols: block HOPOPT and anything outside
esp,tcp,udp,gre,icmp—adjusted for what your network actually needs.
Before enabling, confirm VPN, NTP, databases, and other legitimate services are not caught by these blocks (packet-filtering minimal ruleset).
Other ingress traffic to review manually
Section titled “Other ingress traffic to review manually”The same pages list additional types to restrict case by case: SFTP, TFTP, SSH, Telnet, RDP, SNMP, NTP (reflection risk—prefer internal DNS or DoH), MS-SQL, and geolocation-based blocks where relevant. For prefixes with only servers, consider blocking ingress whose TCP source ports are 80 or 443 from the Internet; for mixed endpoint prefixes, keep a disabled emergency rule you can enable during reflection attacks.
Extended ruleset: IP lists and per-role ingress rules
Section titled “Extended ruleset: IP lists and per-role ingress rules”The extended ruleset builds on minimal guidance by assigning IP lists per role on your Magic Transit prefixes, then permitting only legitimate flows and using a catch-all block.
The extended ruleset builds on the Minimal ruleset by creating targeted rules for different types of systems on your network. Before creating these rules, you must create IP lists for each category.
— Cloudflare, Extended ruleset
Typical categories:
- Endpoints (user devices)
- Internal routers / firewall interfaces
- Web servers
- Non-web servers
For each category, permit what legitimate use requires and block the rest.
Endpoints (user devices): ephemeral ports and catch-all block
Section titled “Endpoints (user devices): ephemeral ports and catch-all block”Endpoints behave as clients, not servers: return traffic lands on high ephemeral destination ports; they should not receive unsolicited inbound TCP SYNs.
Example pattern from Cloudflare:
- Allow TCP to
$endpointswithtcp.dstportin{32768..60999}and block inbound SYN-only (not (tcp.flags.syn and not tcp.flags.ack)). - Allow UDP to the same ephemeral range.
- Allow limited ICMP types (0, 3, 11) if pings/traceroutes matter.
- Rule 10: block all other traffic to
$endpoints.
Web servers: HTTP/S from the Internet or only from Cloudflare IPs
Section titled “Web servers: HTTP/S from the Internet or only from Cloudflare IPs”Web servers need both server ports (e.g. 80/443) and client return paths (DNS/NTP UDP replies may be required).
If you are not behind Cloudflare Layer 7 proxying, an example allows inbound HTTP/S from the Internet with appropriate TCP flags, optional DNS/NTP UDP replies, then a catch-all block on $web_servers.
If you are proxied, restrict HTTP/S sources to Cloudflare IP addresses instead of the open Internet—this replaces the generic Internet-facing HTTP rule. Cloudflare warns that IP ranges change; use maintained lists rather than stale hardcoded ranges (extended ruleset — Cloudflare proxied traffic).
Internal routers and non-web servers
Section titled “Internal routers and non-web servers”For internal routers, permit limited ICMP (and GRE/ESP if tunnels need it), then block everything else to those IPs. For non-web servers, restrict by expected sources and valid destination ports; block SYN to closed ports.
Add policies and root ruleset: limits and IP lists
Section titled “Add policies and root ruleset: limits and IP lists”Policies live in a root ruleset—the top-level container for firewall policies. New Magic Transit accounts may not have one yet; you can verify in the dashboard or via the Account rulesets API (Add policies).
A root ruleset is the top-level container that holds all your firewall policies.
— Cloudflare, Add policies
Operational limits:
- Default maximum 200 policies; contact your account team for a higher limit.
- Cloudflare recommends IP address lists referenced in policies rather than repeating addresses in every rule.
Match expressions use the packet-filtering syntax (for example destination checks like net.dst.ip in {10.0.0.0/8} in Gateway policy expressions).
Ruleset evaluation order: why rule placement breaks policies
Section titled “Ruleset evaluation order: why rule placement breaks policies”Traffic is evaluated top to bottom; the first enabled match wins; disabled rules are skipped.
Traffic is matched in order of the configured rules. As soon as traffic is matched by an enabled rule, it is no longer validated against the later rules, and traffic will pass through disabled rules.
— Cloudflare, Ruleset logic
A broad Allow early (for example all TCP in rule 4) makes a later Block for a specific IP unreachable. Design catch-all blocks last, specific permits before them, and use disabled rules to preview impact in analytics before enabling (Post prefix advertisement monitoring and fine tuning).
Magic Transit egress: stateless firewall and the default-drop trap
Section titled “Magic Transit egress: stateless firewall and the default-drop trap”Minimal and extended guidance focus on ingress. Egress needs extra rules because Network Firewall is not stateful:
Cloudflare Network Firewall does not track connection state (it is not “stateful”). A stateful firewall automatically allows return traffic for active connections — for example, if you send a request outbound, the response is allowed back in. Because Network Firewall is not stateful, each packet — whether ingress or egress — is evaluated independently against your rules. This means ingress block rules can inadvertently block egress traffic.
— Cloudflare, Magic Transit egress
Rules apply to both ingress and egress on Magic Transit. If you use a default-drop catch-all on ingress, add before it an allow for traffic sourced from your Magic Transit prefix to any destination, for example ip.src in {<YOUR_MAGIC_TRANSIT_PREFIX>} with Action Allow (Magic Transit egress).
Layer 3 firewall vs origin lockdown: complementary controls
Section titled “Layer 3 firewall vs origin lockdown: complementary controls”Network Firewall filters traffic on your advertised prefixes. Origin bypass is a separate problem: if someone learns your origin IP, they can skip WAF and cache.
Generally, your origin server should only accept requests coming from your web application.
— Cloudflare, How to prevent DDoS attacks
Cloudflare’s layered origin guidance includes proxied DNS, auditing DNS-only records, rotating origins, Authenticated Origin Pulls, tunnels, Magic Transit, and allowlisting Cloudflare IPs at the origin (Protect your origin server). At the host firewall, blocking non-Cloudflare sources on http/https is a common pattern (Cloudflare IP addresses — Block other IP addresses).
Reducing malicious L7 traffic via WAF custom rules, rate limiting, bot protection, and DDoS tuning also lowers what reaches the origin (Customize Cloudflare security). Network Firewall rulesets and origin allowlisting address different layers; both matter during attacks (Change Access Control List).
Common mistakes when configuring Network Firewall rules
Section titled “Common mistakes when configuring Network Firewall rules”- Placing a wide Allow above specific Block rules, so blocks never run (Ruleset logic).
- Adding endpoint or web-server permits below a catch-all block rule.
- Treating the firewall as stateful and omitting explicit egress allow when using default-drop ingress (Magic Transit egress).
- Enabling minimal UDP/TCP blocks without checking required services (VPN, NTP, DB ports).
- Hardcoding Cloudflare CIDRs in rules without a process to refresh them (Cloudflare IP addresses).
- Relying on Network Firewall alone while origin still accepts direct Internet traffic (Prevent external connections).
How to check this on your site
Section titled “How to check this on your site”- Confirm a customized Network Firewall ruleset exists and review best practices against your prefix layout (minimal vs extended).
- Create or verify IP lists for each extended-ruleset role (Add policies).
- Run new rules in disabled mode, then use Network Analytics (
verdict = dropand rule ID) to confirm intended matches before enabling (Post prefix advertisement monitoring and fine tuning). - After any default-drop ingress rule, confirm an egress allow for your Magic Transit source prefix (Magic Transit egress).
- 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.