Skip to content

Block an IP range

Block requests from a list of IPv4 and IPv6 addresses and CIDR blocks with a WAF rule.

Updated View as Markdown
  1. Read the WAF with 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:

    {
      "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, 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:

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.

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

Navigation

Type to search…

↑↓ navigate↵ selectEsc close