| [ Web Proxy ] |
| Viewing: https://developers.cloudflare.com/waf/tools/zone-lockdown/ | [Back] [Original] |
Zone Lockdown specifies a list of one or more IP addresses, CIDR ranges, or networks that are the only IPs allowed to access a domain, subdomain, or URL. You can configure multiple destinations, including IPv4/IPv6 addresses, in a single zone lockdown rule.
All IP addresses not specified in the zone lockdown rule will not have access to the specified resources. Requests from those IP addresses will receive an Access Denied response.
Note
Cloudflare recommends that you use custom rules instead of zone lockdown rules to block requests from IP addresses not present in an allowlist of IPs and CIDR ranges.
For examples of using custom rules for this purpose, refer to the following use cases:
Cloudflare Zone Lockdown is available on paid plans. The Zone lockdown rules option appears only if you have configured at least one zone lockdown rule.
The number of available zone lockdown rules depends on your Cloudflare plan.
| Free | Pro | Business | Enterprise | |
|---|---|---|---|---|
| Availability | No | Yes | Yes | Yes |
| Number of rules | 0 | 3 | 10 | 200 |
Note
The Zone lockdown rules option appears only if you have configured at least one zone lockdown rule.
If you have access to Zone Lockdown rules
In the Cloudflare dashboard, go to the Security rules page.
Go to Security rules ↗Select Create rule > Zone lockdown rules.
If this option is not available, refer to the instructions below.
Enter a descriptive name for the rule in Name.
For URLs, enter the domains, subdomains, or URLs you wish to protect from unauthorized IPs. You can use wildcards such as *. Enter one item per line.
For IP Range, enter one or more allowed IPv4/IPv6 addresses or CIDR ranges, one per line. Only these IP addresses and ranges will be able to access the resources you entered in URLs.
(Optional) If you are creating a zone lockdown rule that overlaps with an existing rule, expand Advanced Options and enter a priority for the rule in Priority. The lower the number, the higher the priority. Higher priority rules take precedence.
Select Save and Deploy lockdown rule.
If you do not have access to Zone Lockdown rules
Create a custom rule to perform zone lockdown:
In the Cloudflare dashboard, go to the Security rules page.
Go to Security rules ↗Select Templates, and then select the template Allow only specified IP addresses.
Fill in the required fields and select Deploy.
Issue a POST request for the Create a Zone Lockdown rule operation similar to the following:
Required API token permissions
At least one of the following token permissions is required:Firewall Services Writecurl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/firewall/lockdowns" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"description": "Block all traffic to staging and wiki unless it comes from HQ or branch offices",
"urls": [
"staging.example.com/*",
"example.com/wiki/*"
],
"configurations": [
{
"target": "ip_range",
"value": "192.0.2.0/24"
},
{
"target": "ip_range",
"value": "2001:DB8::/64"
},
{
"target": "ip",
"value": "203.0.133.1"
}
]
}'The following example rule will only allow visitors connecting from a companys headquarters or branch offices to access the staging environment and the wiki:
Name:
Block all traffic to staging and wiki unless it comes from HQ or branch offices
URLs:
staging.example.com/*
example.com/wiki/*
IP Range:
192.0.2.0/24
2001:DB8::/64
203.0.133.1
This example would not protect an internal wiki located on a different directory path such as example.com/internal/wiki.
Note
A custom rule with an equivalent behavior would have the following configuration:
Description:
Block all traffic to staging and wiki unless it comes from HQ or branch offices
Expression:
((http.host eq "staging.example.com") or (http.host eq "example.com" and http.request.uri.path wildcard "/wiki/*")) and not ip.src in {192.0.2.0/24 2001:DB8::/64 203.0.133.1}Action: Block
A visitor from an unauthorized IP will get the following error when there is a match for a zone lockdown rule:
[Example of Error 1106 (access denied) received by a user accessing the zone from an unauthorized IP address]
| Web Proxy Viewer | New URL | Original Page |