---
title: Protect against random prefix attacks · Cloudflare DNS docs
description: In order to enable automatic mitigation of random prefix attacks:
lastUpdated: 2024-12-16T22:33:26.000Z
source_url:
  html: https://a74404c8.preview.developers.cloudflare.com/dns/dns-firewall/random-prefix-attacks/setup/index.md
  md: https://a74404c8.preview.developers.cloudflare.com/dns/dns-firewall/random-prefix-attacks/setup/
---

In order to enable automatic mitigation of [random prefix attacks](https://developers.cloudflare.com/dns/dns-firewall/random-prefix-attacks/about/):

1. Set up [DNS Firewall](https://developers.cloudflare.com/dns/dns-firewall/setup/).

2. Send a [`PATCH` request](https://developers.cloudflare.com/api/resources/dns_firewall/methods/edit/) to update your DNS Firewall cluster.

   ```bash
   curl --request PATCH "https://api.cloudflare.com/client/v4/accounts/{account_id}/dns_firewall/{cluster_tag}" \
   --header "Authorization: Bearer <API_TOKEN>" \
   --header "Content-Type: application/json" \
   --data '{
     "attack_mitigation": {
       "enabled": true,
       "only_when_upstream_unhealthy": true
     }
   }'
   ```

Once you receive a `200` success response from the API, queries identified as being part of a random prefix attack will receive a `REFUSED` response.

Note

If you do not specify otherwise in your API call, Cloudflare automatically sets the `"only_when_upstream_unhealthy"` parameter to true, which means that Cloudflare will only mitigate attacks when we detect that the upstream is unresponsive (possibly as a result of an attack). This setting can also be changed via the API, using a request similar to the ones shown above.
