---
title: "Block an IP range"
description: "Block requests from a list of IPv4 and IPv6 addresses and CIDR blocks with a WAF rule."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.ezghcloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Block an IP range

1. Read the WAF with [GetWaf](/waf-api/GetWaf/), and keep its `ETag`: the WAF's `version`, in
   quotes.

2. Add a rule at the top of `rules`. Rules run in order, so a block placed above an `allow` rule
   blocks even what that rule allows:

   ```json
   {
     "name": "block-range",
     "action": "block",
     "mode": null,
     "rateLimit": null,
     "conditions": [
       { "type": "ipSet", "negate": false, "cidrs": ["203.0.113.0/24", "2001:db8:1234::/48", "198.51.100.7"] }
     ]
   }
   ```

   One condition takes up to 1,000 addresses and CIDR blocks. A single address needs no prefix length.

3. Replace the WAF with [UpdateWaf](/waf-api/UpdateWaf/), sending the `ETag` in `If-Match`. A
   `412 precondition_failed` means it changed since you read it: read it again.

With the CLI, `ezgh waf rules add` reads the WAF, adds the rule and replaces it in one step:

```sh
ezgh waf rules add waf_8m2k4q6t9x1c --name block-range --action block --position 1 \
  --ip-set 203.0.113.0/24 --ip-set 2001:db8:1234::/48 --ip-set 198.51.100.7/32
```

Requests from those addresses are answered `403` within seconds on every load balancer the WAF is
attached to, unless the WAF is in log-only mode.

To block a whole network operator instead, use an `asn` condition. To block countries, use a
`country` condition. See [Custom rules](/waf/custom-rules#conditions).

To allow only the range instead, set `negate` to `true`: the rule then blocks every address outside it.

Source: https://docs.ezghcloud.com/waf/guides/block-an-ip-range/index.mdx
