---
title: Common DNS policies · Cloudflare Zero Trust docs
description: The following policies are commonly used to secure DNS traffic.
lastUpdated: 2025-04-11T17:37:50.000Z
source_url:
  html: https://patricia-pcx17119-l7-overrides.preview.developers.cloudflare.com/cloudflare-one/policies/gateway/dns-policies/common-policies/index.md
  md: https://patricia-pcx17119-l7-overrides.preview.developers.cloudflare.com/cloudflare-one/policies/gateway/dns-policies/common-policies/
---

The following policies are commonly used to secure DNS traffic.

Refer to the [DNS policies page](https://developers.cloudflare.com/cloudflare-one/policies/gateway/dns-policies/) for a comprehensive list of other selectors, operators, and actions.

## Allow corporate domains

This policy allows users to access official corporate domains. By deploying the policy with high [order of precedence](https://developers.cloudflare.com/cloudflare-one/policies/gateway/order-of-enforcement/#order-of-precedence), you ensure that employees can access trusted domains even if they fall under a blocked category like *Newly seen domains* or *Login pages*.

* Dashboard

  | Selector | Operator | Value | Action | Precedence |
  | - | - | - | - | - |
  | Domain | in list | *Allowed domains* | Allow | 1 |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data '{
    "name": "Allow corporate domains",
    "description": "Allow any internal corporate domains added to a list",
    "precedence": 0,
    "enabled": true,
    "action": "allow",
    "filters": [
      "dns"
    ],
    "traffic": "any(dns.domains[*] in $<LIST_UUID>)",
    "identity": ""
  }'
  ```

  To get the UUIDs of your lists, use the [List Zero Trust lists](https://developers.cloudflare.com/api/resources/zero_trust/subresources/gateway/subresources/lists/methods/list/) endpoint.

## Block security threats

Block [security categories](https://developers.cloudflare.com/cloudflare-one/policies/gateway/domain-categories/#security-categories) such as Command & Control, Botnet and Malware based on Cloudflare's threat intelligence.

* Dashboard

  | Selector | Operator | Value | Action |
  | - | - | - | - |
  | Security Categories | in | *All security risks* | Block |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data '{
    "name": "All-DNS-SecurityCategories-Blocklist",
    "description": "Block security categories based on Cloudflare's threat intelligence",
    "precedence": 20,
    "enabled": true,
    "action": "block",
    "filters": [
      "dns"
    ],
    "traffic": "any(dns.security_category[*] in {68 178 80 83 176 175 117 131 134 151 153})",
    "identity": ""
  }'
  ```

* Terraform

  ```tf
  resource "cloudflare_zero_trust_gateway_policy" "block_security_threats" {
    account_id  = var.cloudflare_account_id
    name        = "All-DNS-SecurityCategories-Blocklist"
    description = "Block security categories based on Cloudflare's threat intelligence"
    precedence  = 20
    enabled     = true
    action      = "block"
    filters     = ["dns"]
    traffic     = "any(dns.security_category[*] in {68 178 80 83 176 175 117 131 134 151 153})"
  }
  ```

## Block content categories

The categories included in this policy are not always a security threat, but blocking them can help minimize the risk that your organization is exposed to. For more information, refer to [domain categories](https://developers.cloudflare.com/cloudflare-one/policies/gateway/domain-categories/).

* Dashboard

  | Selector | Operator | Value | Action |
  | - | - | - | - |
  | Content Categories | in | *Questionable Content*, *Security Risks*, *Miscellaneous* | Block |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data '{
    "name": "All-DNS-ContentCategories-Blocklist",
    "description": "Block common content categories that may pose a risk",
    "precedence": 30,
    "enabled": true,
    "action": "block",
    "filters": [
      "dns"
    ],
    "traffic": "any(dns.content_category[*] in {17 85 87 102 157 135 138 180 162 32 169 177 128 15 115 119 124 141 161})",
    "identity": ""
  }'
  ```

* Terraform

  ```tf
  resource "cloudflare_zero_trust_gateway_policy" "block_content_categories" {
    account_id  = var.cloudflare_account_id
    name        = "All-DNS-ContentCategories-Blocklist"
    description = "Block common content categories that may pose a risk"
    enabled     = true
    action      = "block"
    filters     = ["dns"]
    traffic     = "any(dns.content_category[*] in {17 85 87 102 157 135 138 180 162 32 169 177 128 15 115 119 124 141 161})"
    identity    = ""
  }
  ```

## Block a dynamic list of categories

You can add a list of category IDs to the [EDNS header](https://datatracker.ietf.org/doc/html/rfc6891) of a request sent to Gateway as a JSON object using OPT code `65050`. For example:

```json
{
  "categories": [2, 67, 125, 133]
}
```

With the [Request Context Categories](https://developers.cloudflare.com/cloudflare-one/policies/gateway/dns-policies/#request-context-categories) selector, you can block the category IDs sent with EDNS. This is useful to filter by categories not known at the time of creating a policy, or to enforce device-specific DNS content filtering without reaching your account limit. When Gateway uses this selector to block a DNS query, the request will return an Extended DNS Error (EDE) Code 15 - Blocked error, along with a field containing an array of the matched categories.

* Dashboard

  | Selector | Operator | Value | Action |
  | - | - | - | - |
  | Request Context Category | is | *Present* | Block |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data '{
    "name": "All-DNS-Bock-Category-Matches-In-Request",
    "description": "Block all category matches in the request EDNS context",
    "enabled": true,
    "action": "block",
    "filters": [
      "dns"
    ],
    "traffic": "dns.categories_in_request_context_matches",
    "identity": ""
  }'
  ```

* Terraform

  ```tf
  resource "cloudflare_zero_trust_gateway_policy" "block_content_categories" {
    account_id  = var.cloudflare_account_id
    name        = "All-DNS-Bock-Category-Matches-In-Request"
    description = "Block all category matches in the request EDNS context"
    enabled     = true
    action      = "block"
    filters     = ["dns"]
    traffic     = "dns.categories_in_request_context_matches"
    identity    = ""
  }
  ```

## Block unauthorized applications

Note

After seven days, view your [shadow IT analytics](https://developers.cloudflare.com/cloudflare-one/insights/analytics/shadow-it-discovery/) and block additional applications based on what your users are accessing.

To minimize the risk of [shadow IT](https://www.cloudflare.com/learning/access-management/what-is-shadow-it/), some organizations choose to limit their users' access to certain web-based tools and applications. For example, the following policy blocks known AI tools:

* Dashboard

  | Selector | Operator | Value | Action |
  | - | - | - | - |
  | Application | in | *Artificial Intelligence* | Block |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN>" \
  --data '{
    "name": "All-DNS-Application-Blocklist",
    "description": "Block access to unauthorized AI applications",
    "precedence": 40,
    "enabled": true,
    "action": "block",
    "filters": [
      "dns"
    ],
    "traffic": "any(app.type.ids[*] in {25})",
    "identity": ""
  }'
  ```

* Terraform

  ```tf
  resource "cloudflare_zero_trust_gateway_policy" "block_unauthorized_apps" {
    account_id  = var.cloudflare_account_id
    name        = "All-DNS-Application-Blocklist"
    description = "Block access to unauthorized AI applications"
    enabled     = true
    action      = "block"
    filters     = ["dns"]
    traffic     = "any(app.type.ids[*] in {25})"
    identity    = ""
  }
  ```

## Block banned countries

You can implement policies to block websites hosted in countries categorized as high risk. The designation of such countries may result from your organization's customers or through the implementation of regulations including [EAR](https://www.tradecompliance.pitt.edu/embargoed-and-sanctioned-countries), [OFAC](https://orpa.princeton.edu/export-controls/sanctioned-countries), and [ITAR](https://www.tradecompliance.pitt.edu/embargoed-and-sanctioned-countries).

* Dashboard

  | Selector | Operator | Value | Action |
  | - | - | - | - |
  | Resolved Country IP Geolocation | in | *Afghanistan*, *Belarus*, *Congo (Kinshasa)*, *Cuba*, *Iran*, *Iraq*, *Korea, North*, *Myanmar*, *Russian Federation*, *Sudan*, *Syria*, *Ukraine*, *Zimbabwe* | Block |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data '{
    "name": "Block banned countries",
    "description": "Block access to banned countries",
    "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\"})",
    "identity": ""
  }'
  ```

## Block top-level domains

Blocking [frequently misused](https://www.spamhaus.org/statistics/tlds/) top-level domains (TLDs) can 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 like [ITAR](https://www.tradecompliance.pitt.edu/embargoed-and-sanctioned-countries) or [OFAC](https://orpa.princeton.edu/export-controls/sanctioned-countries).

* Dashboard

  | Selector | Operator | Value | Logic | Action |
  | - | - | - | - | - |
  | Domain | matches regex | `[.](cn\|ru)$` | Or | Block |
  | Domain | matches regex | `[.](rest\|hair\|top\|live\|cfd\|boats\|beauty\|mom\|skin\|okinawa)$` | Or | |
  | Domain | matches regex | `[.](zip\|mobi)$` | | |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data '{
    "name": "Block top-level domains",
    "description": "Block top-level domains that are frequently used for malicious practices",
    "enabled": true,
    "action": "block",
    "filters": [
      "dns"
    ],
    "traffic": "any(dns.domains[*] matches \"[.](cn|ru)$\") or any(dns.domains[*] matches \"[.](rest|hair|top|live|cfd|boats|beauty|mom|skin|okinawa)$\") or any(dns.domains[*] matches \"[.](zip|mobi)$\")",
    "identity": ""
  }'
  ```

## Block phishing attacks

To protect against [sophisticated phishing attacks](https://blog.cloudflare.com/2022-07-sms-phishing-attacks/), you could prevent users from accessing phishing domains that are specifically targeting your organization. The following policy blocks specific keywords associated with an organization or its authentication services (such as *okta*, *2fa*, *cloudflare* or *sso*), while still allowing access to official corporate domains.

* Dashboard

  | Selector | Operator | Value | Logic | Action |
  | - | - | - | - | - |
  | Domain | not in list | *Corporate Domains* | And | Block |
  | Domain | matches regex | `.*okta.*\|.*cloudflare.*\|.*mfa.*\|.sso.*` | | |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data '{
    "name": "Block phishing attacks",
    "description": "Block attempts to phish specific domains targeting your organization",
    "enabled": true,
    "action": "block",
    "filters": [
      "dns"
    ],
    "traffic": "not(any(dns.domains[*] in $<LIST_UUID>)) and any(dns.domains[*] matches \".*okta.*\\|.*cloudflare.*\\|.*mfa.*\\|.sso.*\")",
    "identity": ""
  }'
  ```

  To get the UUIDs of your lists, use the [List Zero Trust lists](https://developers.cloudflare.com/api/resources/zero_trust/subresources/gateway/subresources/lists/methods/list/) endpoint.

## Block online tracking

To safeguard user privacy, some organizations will block tracking domains such as `dig.whatsapp.com` as well as other tracking domains embedded at the OS level. This policy is implemented by creating a custom blocklist. Refer to [this repository](https://github.com/nextdns/native-tracking-domains/tree/28991a0d5b2ab6d35588a74af82162ea7caff420/domains) for a list of widespread tracking domains that you can add to your blocklist.

* Dashboard

  | Selector | Operator | Value | Action |
  | - | - | - | - |
  | Domain | in list | *Top tracking domains* | Block |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data '{
    "name": "Block online tracking",
    "description": "Block domains used for tracking at an OS level",
    "enabled": true,
    "action": "block",
    "filters": [
      "dns"
    ],
    "traffic": "any(dns.domains[*] in $<LIST_UUID>)",
    "identity": ""
  }'
  ```

  To get the UUIDs of your lists, use the [List Zero Trust lists](https://developers.cloudflare.com/api/resources/zero_trust/subresources/gateway/subresources/lists/methods/list/) endpoint.

## Block malicious IPs

Block specific IP addresses that are known to be malicious or pose a threat to your organization. This policy is usually implemented by creating custom blocklists or by using blocklists provided by threat intelligence partners or regional Computer Emergency and Response Teams (CERTs).

* Dashboard

  | Selector | Operator | Value | Action |
  | - | - | - | - |
  | Resolved IP | in list | *DShield* | Block |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data '{
    "name": "Block malicious IPs",
    "description": "Block specific IP addresses that are known to be malicious or pose a threat to your organization",
    "enabled": true,
    "action": "block",
    "filters": [
      "dns"
    ],
    "traffic": "any(dns.resolved_ips[*] in $<LIST_UUID>)",
    "identity": ""
  }'
  ```

  To get the UUIDs of your lists, use the [List Zero Trust lists](https://developers.cloudflare.com/api/resources/zero_trust/subresources/gateway/subresources/lists/methods/list/) endpoint.

## Turn on CIPA filter

The CIPA (Children's Internet Protection Act) Filter is a collection of subcategories that encompass a wide range of topics that could be harmful or inappropriate for minors. It is used as a part of [Project Cybersafe Schools](https://developers.cloudflare.com/fundamentals/reference/policies-compliances/cybersafe/) to block access to unwanted or harmful online content. Upon creating this policy, your organization will have minimum [CIPA compliance](https://www.fcc.gov/consumers/guides/childrens-internet-protection-act).

* Dashboard

  | Selector | Operator | Value | Action |
  | - | - | - | - |
  | Content Categories | in | *CIPA Filter* | Block |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data '{
    "name": "Turn on CIPA filter",
    "description": "Block access to unwanted or harmful online content for children",
    "enabled": true,
    "action": "block",
    "filters": [
      "dns"
    ],
    "traffic": "any(dns.content_category[*] in {182})",
    "identity": ""
  }'
  ```

## Hide explicit search results

SafeSearch is a feature of search engines that helps you filter explicit or offensive content. You can force SafeSearch on search engines like Google, Bing, Yandex, YouTube, and DuckDuckGo:

* Dashboard

  | Selector | Operator | Value | Action |
  | - | - | - | - |
  | Content Categories | in | *Search Engines* | Safe Search |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data '{
    "name": "Hide explicit search results",
    "description": "Force SafeSearch on search engines to filter explicit or offensive content",
    "enabled": true,
    "action": "safesearch",
    "filters": [
      "dns"
    ],
    "traffic": "any(dns.content_category[*] in {145})",
    "identity": ""
  }'
  ```

## Check user identity

Configure access on a per user or group basis by adding [identity-based conditions](https://developers.cloudflare.com/cloudflare-one/policies/gateway/identity-selectors/) to your policies.

* Dashboard

  | Selector | Operator | Value | Logic | Action |
  | - | - | - | - | - |
  | Application | in | *Salesforce* | And | Block |
  | User Group Names | in | `Contractors` | | |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data '{
    "name": "Check user identity",
    "description": "Filter traffic based on a user identity group name",
    "enabled": true,
    "action": "block",
    "filters": [
      "dns"
    ],
    "traffic": "any(app.ids[*] in {606})",
    "identity": "any(identity.groups.name[*] in {\"Contractors\"})",
  }'
  ```

## Restrict access to specific groups

Filter DNS queries to allow only specific users access.

The following example includes two policies. The first policy allows the specified group, while the second policy blocks all other users. To ensure the policies are evaluated properly, place the Allow policy above the Block policy. For more information, refer to the [order of precedence](https://developers.cloudflare.com/cloudflare-one/policies/gateway/order-of-enforcement/#order-of-precedence).

### 1. Allow a group

* Dashboard

  | Selector | Operator | Value | Logic | Action |
  | - | - | - | - | - |
  | Content Categories | in | *Social Networks* | And | Allow |
  | User Group Names | in | `Marketing` | | |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data '{
    "name": "Allow social media for Marketing",
    "description": "Allow access to social media sites for users in the Marketing group",
    "precedence": 1,
    "enabled": true,
    "action": "allow",
    "filters": [
      "dns"
    ],
    "traffic": "any(dns.content_category[*] in {149})",
    "identity": "any(identity.groups.name[*] in {\"Marketing\"})",
  }'
  ```

### 2. Block all other users

* Dashboard

  | Selector | Operator | Value | Action |
  | - | - | - | - |
  | Content Categories | in | *Social Networks* | Block |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data '{
    "name": "Block social media",
    "description": "Block social media for all other users",
    "precedence": 2,
    "enabled": true,
    "action": "block",
    "filters": [
      "dns"
    ],
    "traffic": "any(dns.content_category[*] in {149})",
    "identity": ""
  }'
  ```

## Control IP version

Enterprise users can pair these policies with an [egress policy](https://developers.cloudflare.com/cloudflare-one/policies/gateway/egress-policies/) to control which IP version is used to egress to the origin server.

Optionally, you can use the Domain selector to control the IP version for specific sites.

Note

To ensure traffic routes through your preferred IP version, turn off **Modify Gateway block behavior**.

### Force IPv4

Force users to connect with IPv4 by blocking IPv6 resolution.

* Dashboard

  | Selector | Operator | Value | Action |
  | - | - | - | - |
  | Query Record Type | is | *AAAA* | Block |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data '{
    "name": "Force IPv4",
    "description": "Force users to connect with IPv4 by blocking IPv6 resolution",
    "enabled": true,
    "action": "block",
    "filters": [
      "dns"
    ],
    "traffic": "dns.query_rtype == \"AAAA\"",
    "identity": ""
  }'
  ```

### Force IPv6

Force users to connect with IPv6 by blocking IPv4 resolution.

* Dashboard

  | Selector | Operator | Value | Action |
  | - | - | - | - |
  | Query Record Type | is | *A* | Block |

* API

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data '{
    "name": "Force IPv6",
    "description": "Force users to connect with IPv6 by blocking IPv4 resolution",
    "enabled": true,
    "action": "block",
    "filters": [
      "dns"
    ],
    "traffic": "dns.query_rtype == \"A\"",
    "identity": ""
  }'
  ```
