Recommended DNS policies·续
resource "cloudflare_zero_trust_gateway_policy" "dns_geolocation_block_policy" {
account_id = var.cloudflare_account_id
name = "All-DNS-GeoCountryIP-Blocklist"
description = "Block traffic hosted in countries categorized as high security risks"
precedence = 50
enabled = true
action = "block"
filters = ["dns"]
traffic = "any(dns.dst.geo.country[*] in {\"AF\" \"BY\" \"CD\" \"CU\" \"IR\" \"IQ\" \"KP\" \"MM\" \"RU\" \"SD\" \"SY\" \"UA\" \"ZW\"})"
}
All-DNS-DomainTopLevel-Blocklist
Block frequently misused top-level domains (TLDs) to reduce security risks, especially when there is no discernible advantage to be gained from allowing access. Similarly, restricting access to specific country-level TLDs may be necessary to comply with regulations such as OFAC ↗︎ and ITAR ↗︎.
| Selector | Operator | Value | Action |
|---|---|---|---|
| Domain | matches regex | [.](cn\|ru)$ or [.](rest\|hair\|top\|live\|cfd\|boats\|beauty\|mom\|skin\|okinawa)$ or [.](zip\|mobi)$ |
Block |
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "All-DNS-DomainTopLevel-Blocklist",
"description": "Block DNS queries of known risky TLDs",
"precedence": 60,
"enabled": true,
"action": "block",
"filters": [
"dns"
],
"traffic": "any(dns.domains[*] matches \".$ or .$ or .$\")"
}'
resource "cloudflare_zero_trust_gateway_policy" "dns_blacklist_policy" {
account_id = var.cloudflare_account_id
name = "All-DNS-DomainTopLevel-Blocklist"
description = "Block DNS queries of known risky TLDs"
precedence = 60
enabled = true
action = "block"
filters = ["dns"]
traffic = "any(dns.domains[*] matches \"[.](cn|ru)$ or [.](rest|hair|top|live|cfd|boats|beauty|mom|skin|okinawa)$ or [.](zip|mobi)$\")"
}
All-DNS-DomainPhishing-Blocklist
Block misused domains to protect your users against sophisticated phishing attacks, such as domains that specifically target your organization. For example, the following policy blocks specific keywords associated with an organization or its authentication services (such as okta, 2fa, cloudflare and sso) while still allowing access to known domains.
| Selector | Operator | Value | Logic | Action |
|---|---|---|---|---|
| Domain | not in list | Known Domains | And | Block |
| Domain | matches regex | .*okta.*\|.*cloudflare.*\|.*mfa.*\|.sso.* |
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "All-DNS-DomainPhishing-Blocklist",
"description": "Block misused domains used in phishing campaigns",
"precedence": 70,
"enabled": true,
"action": "block",
"filters": [
"dns"
],
"traffic": "any(dns.domains[] matches \".okta.|.cloudflare.|.mfa.|.sso.\") and not(any(dns.domains[*] in $<KNOWN_DOMAINS_LIST_UUID>))"
}'
resource "cloudflare_zero_trust_gateway_policy" "dns_phishing_domains_block" {
account_id = var.cloudflare_account_id
name = "All-DNS-DomainPhishing-Blocklist"
description = "Block misused domains used in phishing campaigns"
precedence = 70
enabled = true
action = "block"
filters = ["dns"]
traffic = "any(dns.domains[*] matches \".*okta.*|.*cloudflare.*|.*mfa.*|.sso.*\") and not(any(dns.domains[*] in ${"$"}${cloudflare_zero_trust_list.known_phishing_domains_list.id}))"
}
All-DNS-ResolvedIP-Blocklist
Block specific IP addresses that are malicious or pose a threat to your organization.
You can implement this policy by either creating custom blocklists or by using blocklists provided by threat intelligence partners or regional Computer Emergency and Response Teams (CERTs). Ideally, your CERTs can update the blocklist with an API automation to provide real-time threat protection.
| Selector | Operator | Value | Action |
|---|---|---|---|
| Resolved IP | in list | IP Blocklist | Block |
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "All-DNS-ResolvedIP-Blocklist",
"description": "Block specific IP addresses deemed to be a risk to the Organization",
"precedence": 80,
"enabled": true,
"action": "block",
"filters": [
"dns"
],
"traffic": "any(dns.resolved_ips[*] in $<IP_BLOCKLIST_UUID>)"
}'
resource "cloudflare_zero_trust_gateway_policy" "dns_resolvedip_blocklist_rule" {
account_id = var.cloudflare_account_id
name = "All-DNS-ResolvedIP-Blocklist"
description = "Block specific IP addresses deemed to be a risk to the Organization"
precedence = 80
enabled = true
action = "block"
filters = ["dns"]
traffic = "any(dns.resolved_ips[*] in ${"$"}${cloudflare_zero_trust_list.ip_blocklist.id}"
}
All-DNS-DomainHost-Blocklist
Block specific domains or hosts that are malicious or pose a threat to your organization. Like All-DNS-ResolvedIP-Blocklist, this blocklist can be updated manually or via API automation.
| Selector | Operator | Value | Logic | Action |
|---|---|---|---|---|
| Domain | in list | Domain Blocklist | Or | Block |
| Host | in list | Host Blocklist | Or | |
| Host | matches regex | .*example\.com |
Create a Zero Trust Gateway rulebash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "All-DNS-DomainHost-Blocklist",
"description": "Block specific domains or hosts that are malicious or pose a threat to your organization.",
"precedence": 90,
"enabled": true,
"action": "block",
"filters": [
"dns"
],
"traffic": "any(dns.domains[*] in $<DOMAIN_BLOCKLIST_UUID>) and dns.fqdn in $<HOST_BLOCKLIST_UUID> and dns.fqdn matches \".*example.com\""
}'
resource "cloudflare_zero_trust_gateway_policy" "block_dns_domain_host" {
account_id = var.cloudflare_account_id
name = "All-DNS-DomainHost-Blocklist"
description = "Block specific domains or hosts that are malicious or pose a threat to your organization."
precedence = 90
enabled = true
action = "block"
filters = ["dns"]
traffic = "any(dns.domains[*] in ${"$"}${cloudflare_zero_trust_list.domain_blocklist.id}) and dns.fqdn in ${"$"}${cloudflare_zero_trust_list.host_blocklist.id} and dns.fqdn matches \".*example\\.com\""
}
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/learning-paths/secure-internet-traffic/build-dns-policies/recommended-dns-policies/#page","headline":"Recommended DNS policies","description":"Deploy recommended DNS filtering policies.","url":"https://developers.cloudflare.com/learning-paths/secure-internet-traffic/build-dns-policies/recommended-dns-policies/","inLanguage":"en","image":"https://developers.cloudflare.com/learning-paths/secure-internet-traffic/build-dns-policies/recommended-dns-policies/og.png?v=355ab4658a9edec4","dateModified":"2026-10-12","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/"}}
description: Test Gateway DNS policy enforcement. title: Test a policy image: https://developers.cloudflare.com/learning-paths/secure-internet-traffic/build-dns-policies/test-policy/og.png?v=9da21015b23c77ae
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/learning-paths/llms.txt
Use this file to discover all available pages before exploring further.
Docs