Skip to content
Cloudflare Docs

DNS filtering

Secure Web Gateway allows you to inspect DNS traffic — the queries your devices make to translate domain names like example.com into IP addresses — and control which websites users can visit. Because every connection starts with a DNS lookup, DNS filtering blocks threats at the earliest stage of a connection, before the device ever reaches the destination. Use DNS policies to block malware domains, phishing sites, or entire content categories across your organization.

1. Connect to Gateway

You can filter DNS queries from individual devices (for example, employee laptops) or from entire network locations (for example, an office router). Choose the option that matches your deployment.

Connect devices

To filter DNS requests from an individual device such as a laptop or phone:

  1. Install the WARP client on your device. WARP is a lightweight agent that routes the device's DNS queries through Cloudflare so Gateway can inspect and filter them.
  2. In the WARP client, open Settings and log in to your organization's Zero Trust instance. This tells WARP which Gateway policies to enforce.
  3. (Optional) If you want to display a custom block page instead of a generic browser error when a request is blocked, install a Cloudflare root certificate on your device.

Connect DNS locations

To filter DNS requests from a network location such as an office or data center without installing software on each device:

  1. Add the location to your Cloudflare One settings. A DNS location represents a network (such as an office) whose DNS queries you want to filter.
  2. On your router, browser, or OS, change the DNS server setting to point to the Cloudflare address shown in the location setup UI. This forwards all DNS queries from that network through Gateway.

2. Verify device connectivity

To confirm that your device's DNS queries are flowing through Gateway:

  1. In Cloudflare One, go to Traffic policies > Traffic settings.
  2. Under Log traffic activity, enable activity logging for all DNS logs.
  3. On your device, open a browser and go to any website.
  4. In Cloudflare One, go to Insights > Logs > DNS.
  5. Make sure DNS queries from your device appear.

3. Create your first DNS policy

A DNS policy has two parts: a traffic condition that defines which queries to match (for example, all queries to gambling sites) and an action that defines what to do with matching queries (for example, block them). To create a new DNS policy:

  1. In Cloudflare One, go to Traffic policies > Firewall policies.
  2. In the DNS tab, select Add a policy.
  3. Name the policy.
  4. Under Traffic, use the condition builder to define which DNS queries this policy applies to. Select a selector (such as Security Categories), an operator (such as in), and one or more values.
  5. Choose an Action to take when traffic matches the condition. For example, we recommend adding a policy to block all security categories:
    SelectorOperatorValueAction
    Security CategoriesinAll security risksBlock
  6. Select Create policy.

For more information, refer to DNS policies.

4. Add optional policies

Once your first policy is active, refer to common DNS policies for other policies you may want to add. Common additions include blocking specific content categories (such as social media or streaming), enabling SafeSearch on search engines, and restricting DNS queries so devices can only use resolvers that you have approved.