次の Cloudflare Gateway DNS ポリシーは、DNS トラフィックの保護によく使われます。各例には、組織向けに調整できるダッシュボードと API の手順があります。
推奨ポリシーの基準セットは インターネットトラフィックと SaaS アプリを保護する を参照してください。
ほかのセレクター、演算子、アクションの一覧は DNS ポリシーのページ を参照してください。
このポリシーは、公式の社内ドメインへのアクセスを許可します。優先順位 を高くしてデプロイすると、Newly seen domains や Login pages などのブロック対象カテゴリに該当しても、従業員は信頼できるドメインへアクセスできます。
| セレクター | 演算子 | 値 | アクション | 優先度 |
|---|---|---|---|---|
| Domain | in list | Allowed domains | Allow | 1 |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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": ""
}'リストの UUID を取得するには、List Zero Trust lists エンドポイントを使います。
Cloudflare の脅威インテリジェンスに基づき、Command & Control、Botnet、Malware などの セキュリティカテゴリ をブロックします。
| セレクター | 演算子 | 値 | アクション |
|---|---|---|---|
| Security Categories | in | All security risks | Block |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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": ""
}'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})"
}このポリシーに含めるカテゴリは、常にセキュリティ脅威であるとは限りません。ただしブロックすると、組織がさらされるリスクを下げられます。詳細は ドメインカテゴリ を参照してください。
| セレクター | 演算子 | 値 | アクション |
|---|---|---|---|
| Content Categories | in | Questionable Content, Security Risks, Miscellaneous | Block |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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": ""
}'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 = ""
}Gateway へ送るリクエストの EDNS(Extension Mechanisms for DNS) ↗ ヘッダーに、OPT コード 65050 を使い、カテゴリ ID のリストを JSON オブジェクトとして追加できます。EDNS では、標準フィールド以外の追加メタデータを DNS クエリに付けられます。例:
{
"categories": [2, 67, 125, 133]
}Request Context Categories セレクターを使うと、EDNS で送られたカテゴリ ID をブロックできます。ポリシー作成時に不明なカテゴリでフィルターする場合や、アカウント上限に達せずにデバイス固有の DNS コンテンツフィルタリングを適用する場合に便利です。Gateway がこのセレクターで DNS クエリをブロックすると、リクエストは Extended DNS Error(EDE)Code 15(Blocked)と、一致したカテゴリの配列を含むフィールドを返します。
| セレクター | 演算子 | 値 | アクション |
|---|---|---|---|
| Request Context Category | is | Present | Block |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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": ""
}'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 = ""
}シャドーIT のリスクを抑えるため、一部の組織はユーザーが使えるウェブツールやアプリケーションを制限します。たとえば、次のポリシーは既知の AI ツールをブロックします。
| セレクター | 演算子 | 値 | アクション |
|---|---|---|---|
| Application | in | Artificial Intelligence | Block |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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": ""
}'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 = ""
}リスクが高いと分類された国でホストされている Web サイトをブロックするポリシーを実装できます。対象国の指定は、組織の要件や、EAR(Export Administration Regulations) ↗、OFAC(Office of Foreign Assets Control) ↗、ITAR(International Traffic in Arms Regulations) ↗ などの規制に基づくことがあります。このポリシーは、指定した国に地理位置される IP アドレスへ解決する DNS クエリをブロックします。
| セレクター | 演算子 | 値 | アクション |
|---|---|---|---|
| Resolved Country IP Geolocation | in | Afghanistan、Belarus、Congo (Kinshasa)、Cuba、Iran、Iraq、Korea, North、Myanmar、Russian Federation、Sudan、Syria、Ukraine、Zimbabwe | Block |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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": ""
}'悪用されやすい ↗ トップレベルドメイン(TLD。ドメイン名の末尾、.com や .ru など)をブロックすると、アクセスを許可する明確な利点がない場合に特に、セキュリティリスクを下げられます。同様に、特定の国別 TLD へのアクセス制限は、ITAR ↗ や OFAC ↗ などの規制への対応に必要なことがあります。
| セレクター | 演算子 | 値 | 論理演算 | アクション |
|---|---|---|---|---|
| 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)$ |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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": ""
}'高度なフィッシング攻撃 ↗ から守るため、組織を標的にしたフィッシングドメインへのアクセスを防げます。次のポリシーは、組織またはその認証サービスに関連する特定のキーワード(okta、2fa、cloudflare、sso など)をブロックしつつ、公式の社内ドメインへのアクセスは許可します。
| セレクター | 演算子 | 値 | 論理演算 | アクション |
|---|---|---|---|---|
| Domain | not in list | Corporate Domains | And | Block |
| Domain | matches regex | .*okta.*|.*cloudflare.*|.*mfa.*|.sso.* |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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": ""
}'リストの UUID を取得するには、List Zero Trust lists エンドポイントを使います。
ユーザーのプライバシーを守るため、一部の組織は dig.whatsapp.com などのトラッキングドメインや、OS レベルに埋め込まれたほかのトラッキングドメインをブロックします。このポリシーは、カスタムブロックリストを作成して実装します。ブロックリストに追加できる広く使われているトラッキングドメインの一覧は このリポジトリ ↗ を参照してください。
| セレクター | 演算子 | 値 | アクション |
|---|---|---|---|
| Domain | in list | Top tracking domains | Block |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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": ""
}'リストの UUID を取得するには、List Zero Trust lists エンドポイントを使います。
組織に脅威となる、または悪意があると分かっている特定の IP アドレスをブロックします。このポリシーは通常、カスタムブロックリストを作成するか、脅威インテリジェンスパートナーや地域の Computer Emergency and Response Team(CERT)が提供するブロックリストを使って実装します。
| セレクター | 演算子 | 値 | アクション |
|---|---|---|---|
| Resolved IP | in list | DShield | Block |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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": ""
}'リストの UUID を取得するには、List Zero Trust lists エンドポイントを使います。
CIPA(Children's Internet Protection Act、児童インターネット保護法)フィルターは、未成年者に有害または不適切な幅広いトピックを含むサブカテゴリの集合です。Project Cybersafe Schools の一部として、望ましくない、または有害なオンラインコンテンツへのアクセスをブロックするために使います。このポリシーを作成すると、組織は最低限の CIPA 準拠 ↗ を満たします。
| セレクター | 演算子 | 値 | アクション |
|---|---|---|---|
| Content Categories | in | CIPA Filter | Block |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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": ""
}'SafeSearch は、露骨または攻撃的なコンテンツをフィルターする検索エンジンの機能です。Google、Bing、Yandex、YouTube、DuckDuckGo などの検索エンジンで SafeSearch を強制できます。
| セレクター | 演算子 | 値 | アクション |
|---|---|---|---|
| Content Categories | in | Search Engines | Safe Search |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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": ""
}'ポリシーに ID ベースの条件 を追加して、ユーザーまたはグループ単位でアクセスを設定します。
| セレクター | 演算子 | 値 | 論理演算 | アクション |
|---|---|---|---|---|
| Application | in | Salesforce | And | Block |
| User Group Names | in | Contractors |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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\"})"
}'DNS クエリをフィルターし、特定のユーザーだけにアクセスを許可します。
次の例は 2 つのポリシーで構成します。1 つ目のポリシーは指定したグループを許可し、2 つ目のポリシーはその他のユーザーをすべてブロックします。正しく評価されるよう、Allow ポリシーを Block ポリシーより上に置いてください。詳細は 優先順位 を参照してください。
| セレクター | 演算子 | 値 | 論理演算 | アクション |
|---|---|---|---|---|
| Content Categories | in | Social Networks | And | Allow |
| User Group Names | in | Marketing |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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\"})"
}'| セレクター | 演算子 | 値 | アクション |
|---|---|---|---|
| Content Categories | in | Social Networks | Block |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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": ""
}'Enterprise ユーザーは、これらのポリシーを エグレスポリシー と組み合わせ、Gateway が宛先サーバーへ接続するときの IP バージョンを制御できます。
任意で Domain セレクターを使い、特定サイトの IP バージョンを制御することもできます。
AAAA(IPv6)レコードの解決をブロックし、ユーザーを IPv4 で接続させます。
| セレクター | 演算子 | 値 | アクション |
|---|---|---|---|
| Query Record Type | is | AAAA | Block |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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": ""
}'A(IPv4)レコードの解決をブロックし、ユーザーを IPv6 で接続させます。
| セレクター | 演算子 | 値 | アクション |
|---|---|---|---|
| Query Record Type | is | A | Block |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"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": ""
}'