Network filtering
Secure Web Gateway allows you to apply policies at the network level to control which websites and non-HTTP applications users can access. This is useful when you need to control traffic that is not web browsing — for example, blocking remote desktop connections or restricting file-transfer tools across your organization.
Network policies inspect individual TCP and UDP packets (the low-level data units that carry all Internet traffic), which means you can filter traffic that DNS and HTTP policies cannot reach. DNS policies only see domain lookups, and HTTP policies only see web requests — network policies go deeper and can catch protocols like SSH (remote terminal access), RDP (remote desktop), and custom applications running on non-standard ports.
To filter network traffic from a device such as a laptop or phone:
- Install the WARP client on your device.
- In the WARP client Settings, log in to your organization's Cloudflare One instance.
- (Optional) If you want to display a custom block page when users are blocked, install the Cloudflare root certificate on your device. Without the certificate, blocked users will see a generic browser connection error instead of an informative page.
- Enable the Gateway proxy for TCP. The Gateway proxy is what routes your device's traffic through Cloudflare so network policies can inspect it — without it enabled, your policies will have no effect. Optionally, enable the UDP proxy to also inspect QUIC traffic (a newer protocol used by HTTP/3 connections) on port 443.
To filter traffic from private networks (internal corporate networks not exposed to the public Internet), refer to the Cloudflare Tunnel guide.
Verifying connectivity ensures that traffic from your device is actually flowing through Cloudflare before you build policies against it.
To verify your device is connected to Cloudflare One:
- In Cloudflare One ↗, go to Traffic policies > Traffic settings.
- Under Log traffic activity, enable activity logging for all Network logs. This tells Cloudflare to record network-level traffic so you can confirm your device appears in the logs.
- On your WARP-enabled device, open a browser and visit any website. This generates traffic that should appear in the logs.
- Determine the Source IP for your device (the public-facing address Cloudflare sees for your connection):
- Open the WARP client settings.
- Go to Preferences > General.
- Note the Public IP. This is the same address that will appear as the Source IP in your network logs.
- In Cloudflare One, go to Insights > Logs > Network logs. Before building network policies, make sure you see network logs from the Source IP assigned to your device.
If no logs appear after a few minutes, check two things: first, verify that the Gateway proxy is turned on. Second, confirm that the device is enrolled in your Zero Trust organization by checking the WARP client connection status.
A network policy has two parts: a matcher that selects which traffic to act on (for example, all packets destined for port 22, the default port for SSH) and an action that decides what to do with it (for example, block the connection).
To create a new network policy:
-
In Cloudflare One ↗, go to Traffic policies > Firewall policies.
-
In the Network tab, select Add a network policy.
-
Name the policy.
-
Under Traffic, build a logical expression that defines the traffic you want to allow or block.
-
Choose an Action to take when traffic matches the logical expression. For example, you can use a list of device serial numbers to ensure users can only access an application if they connect with the WARP client from a company device:
Selector Operator Value Logic Action SNI Domain is internalapp.comAnd Block Passed Device Posture Checks not in Device serial numbers -
Select Create policy.
-
Create an API token with the following permissions:
Type Item Permission Account Zero Trust Edit -
(Optional) Configure your API environment variables to include your account ID and API token.
-
Send a
POSTrequest to the Create a Zero Trust Gateway rule endpoint. For example, you can use a list of device serial numbers to ensure users can only access an application if they connect with the WARP client from a company device:Create a Zero Trust Gateway rule curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \--request POST \--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \--json '{"name": "Enforce device posture","description": "Ensure only devices in Zero Trust organization can connect to application","precedence": 0,"enabled": true,"action": "block","filters": ["l4"],"traffic": "any(net.sni.domains[*] == \"internalapp.com\")","identity": "","device_posture": "not(any(device_posture.checks.passed[*] in {\"LIST_UUID\"}))"}'
{ "success": true, "errors": [], "messages": []}The API will respond with a summary of the policy and the result of your request.
For more information, refer to network policies.
Refer to our list of common network policies for policies you may want to create. Common additions include blocking traffic to specific IP ranges, restricting access to non-standard ports (ports other than well-known ones like 80 for HTTP and 443 for HTTPS), and using protocol detection to identify applications like BitTorrent based on their traffic patterns rather than port numbers alone.