Add custom policies
Last updated May 6, 2026 By default, you can create a maximum of 200 policies. We recommend you create lists of IP addresses to reference within policies to streamline policy management.
Add a policy
- In the Cloudflare One ↗︎ dashboard, go to Firewall policies > Custom policies.
- Select Add a policy.
- Fill out the information for your new policy. All existing policies apply to IPv4. You can use a managed IP list ↗︎ when populating the Value.
- When you are done, select Add new policy.
Create a disabled policy
When you add a new policy, the policy is Enabled by default.
To create a Disabled policy, follow the steps in Add a policy above and toggle Enabled to off. When a policy is in the disabled state, the policy will not perform the action until is set to Enabled.
To disable an existing policy, from the Custom policies tab, set the Enabled toggle to off.
Update a policy
- In the Cloudflare One ↗︎ dashboard, go to Firewall policies > Custom policies.
- Locate the policy you want to edit and select the three dots > Edit.
- Update the policy with your changes and select Save.
Delete an existing policy
- Locate the policy you want to delete in the list.
- From the end of the row, select Delete.
- Select Delete again to confirm the deletion.
API
Below, you can find examples of how to use the API to perform certain actions.
Warning
The examples on this page all use the https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets endpoint. This endpoint is intended to create policies from scratch and might overwrite existing policies.
If you have a ruleset already deployed, consider using the https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets/{ruleset_id}/rules endpoint instead.
Refer to Add a rule to a ruleset and Create an account ruleset for more information.
Skip action
The example below blocks all TCP ports, but allows one port (8080) by using the skip action.
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"name": "Example ruleset",
"kind": "root",
"phase": "magic_transit",
"description": "Example ruleset description",
"rules": [
{
"action": "skip",
"action_parameters": { "ruleset": "current" },
"expression": "tcp.dstport in { 8080 } ",
"description": "Allow port 8080"
},
{
"action": "block",
"expression": "tcp.dstport in { 1..65535 }",
"description": "Block all TCP ports"
}
]
}'
Block a country
The example below blocks all packets with a source or destination IP address coming from Brazil by using its 2-letter country code in ISO 3166-1 Alpha 2 ↗︎ format.
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"name": "Example ruleset",
"kind": "root",
"phase": "magic_transit",
"description": "Example ruleset description",
"rules": [
{
"action": "block",
"expression": "ip.src.country == \"BR\"",
"description": "Block traffic from Brazil"
}
]
}'
Use an IP list
Cloudflare Network Firewall supports using lists in expressions for the ip.src and ip.dst fields. The supported lists are:
$cf.anonymizer- Anonymizer proxies$cf.botnetcc- Botnet command and control channel$cf.malware- Sources of malware$<IP_LIST_NAME>- The name of an account-level IP list
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets \
--header "Authorization: Bearer <API_TOKEN>" \
--header "Content-Type: application/json" \
--data '{
"name": "Example ruleset",
"kind": "root",
"phase": "magic_transit",
"description": "Example ruleset description",
"rules": [
{
"action": "block",
"expression": "ip.src in $cf.anonymizer",
"description": "Block traffic from anonymizer proxies"
}
]
}'
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/cloudflare-network-firewall/how-to/add-policies/#page","headline":"Add custom policies","description":"Add custom policies to the Network Firewall.","url":"https://developers.cloudflare.com/cloudflare-network-firewall/how-to/add-policies/","inLanguage":"en","image":"https://developers.cloudflare.com/cloudflare-network-firewall/how-to/add-policies/og.png?v=4cd2de2463efb02a","dateModified":"2026-05-06","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/"},"keywords":["Geolocation"]}
description: Create rate limiting policies for network traffic. title: Create Rate Limiting policies (beta) image: https://developers.cloudflare.com/cloudflare-network-firewall/how-to/create-rate-limiting-policies/og.png?v=81ca8f16b33b1549
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/cloudflare-network-firewall/llms.txt
Use this file to discover all available pages before exploring further.
Docs