Blocking IP addresses and countries without blocking customers

IP blocking refuses requests from chosen addresses or ranges, and geo blocking does the same for whole countries. Both are quick to switch on and easy to get wrong, because an address says where traffic comes from, not who sends it. Used narrowly and with an expiry, they help; used broadly, they refuse real people who share an address with someone else.

Section Operations Updated Covers block, allow, geo

Quick facts

Blocklist
Refuse listed addresses or ranges, allow the rest
Allowlist
Allow listed addresses or ranges, refuse the rest
Geo blocking
Refuse or allow by the country an address is registered or located in
Where it is applied
Server configuration, the network in front of the site, or a firewall
Main risk
Shared addresses: one block can refuse a whole office, mobile carrier or VPN

Address blocks are a tool for specific, narrow problems. For broad automation they are the weakest control available.

How to block an IP address

To block an IP address is to make the server, the firewall or the network in front of the site refuse every request whose source address matches a rule. The five steps below keep that rule narrow and reversible.

  1. Confirm the address is the source. Check that traffic really comes from it and is not a proxy or CDN address in front of many visitors.
  2. Block as narrowly as possible. A single address before a range, a small range before a whole network.
  3. Apply it at the right layer. In front of the site for floods; in the server or application for a specific path.
  4. Write down why and until when. Every block should have a reason and an expiry date; see WAF exceptions for the same rule applied to allowances.
  5. Watch what it refuses. If the block catches requests you did not expect, narrow it or remove it.

Never block or allow special-purpose ranges by accident: private, loopback and documentation addresses are listed in RFC 6890, and a rule written for one of them can behave unexpectedly behind a proxy. Country blocks have their own page: geo-blocking.

Blocking an IP address on the web server

In nginx, the access module takes deny 203.0.113.7; for one address or deny 198.51.100.0/24; for a range, inside a server or location block, and checks rules in order until one matches. In Apache, the mod_authz_host module does the same with Require not ip 203.0.113.7 inside a RequireAll block alongside Require all granted.

Behind a proxy or CDN the server sees the proxy's address, not the visitor's, so such a rule would block the proxy and everyone behind it. The server first has to be told which header carries the real client address, and to trust that header only from the proxy's own addresses.

Blocking IP ranges

Ranges are written in CIDR notation: an address followed by the number of fixed leading bits. In IPv4, a /24 covers 256 addresses and a /16 covers 65,536, so each step down in the number multiplies how many people a block can catch.

IPv6 changes the unit. A single network is usually given a whole /64, and a device can pick a new address inside it at will, so blocking one IPv6 address rarely stops anyone; the smallest useful block is normally the /64. The addresses in these examples are reserved for documentation and reach nobody.

IP whitelisting: when an allowlist is better

An allowlist, sometimes still called IP whitelisting, refuses everything except the addresses you name. It suits places with a known, short list of users: an administration panel, a staging site, an internal API, a webhook receiver.

It fails where users are many or mobile. Home and mobile addresses change, and a person travelling or working from a café is refused. For those cases, sign-in and a second factor protect the resource better than an address list.

WHICH ADDRESS CONTROL FITS WHICH RESOURCE ALLOWLIST FITS BLOCKLIST FITS NEITHER: USE IDENTITY ADMIN PANEL PARTNER WEBHOOK PUBLIC SIGN-IN WHOLE PUBLIC SITE // the larger and more mobile the audience, the less an address list helps
// four resources, and which address control fits each

Geo blocking: what it does and does not do

Geo blocking, also written geoblocking or geoblock, has a short meaning: refusing or allowing a request according to the country its address maps to. A visitor who meets that refusal is geoblocked.

Geo blocking refuses requests by country, using a database that maps addresses to locations. It is used to meet legal or licensing limits, and sometimes to cut traffic from places a site has no customers.

It is coarse and leaky. Location databases are not perfect, VPNs move a visitor to another country in a click, and attackers rent addresses wherever they need them. Blocking a country also refuses travellers, expatriates and partners there, and those refusals are silent.

If you are the one who is geoblocked

Only the side that applied a geo block can lift it. Write to the site owner or its support with your address and the time of the refusal; a wrongly recorded location is a fair reason to ask for a correction.

A VPN moves you to another country, but it routes around the block instead of removing it, and a site can refuse VPN addresses as well. To remove a block you set yourself, delete the country from the rule or add an exception for the address that was refused, with a reason and an expiry.

Why address blocks misfire

One address can stand for thousands of people: a company behind one gateway, a mobile carrier sharing addresses between customers, a university, a VPN exit. Blocking it for one person's behaviour refuses all of them.

Addresses also change hands. An address that sent abuse last month may belong to a customer today, which is the limit of IP reputation. If your own address is the one being refused elsewhere, IP blacklist check explains how to find out why. Before an address goes onto any list, the waf logs show what it was actually refused for.

Questions

How do I block an IP address from my website?

Add the address or range to a deny rule in the server configuration or in the network or firewall in front of the site, as narrowly as possible, with a written reason and an expiry date, and watch what it refuses.

What is IP whitelisting?

IP whitelisting, or allowlisting, permits only listed addresses and refuses the rest. It suits small, fixed groups such as administrators or a partner's servers, not public audiences.

What is geo blocking?

Geo blocking refuses or allows requests by the country an address maps to. It is coarse: location data is imperfect and VPNs move visitors between countries easily.

How do I remove geo blocking?

Only the site or network that applied it can lift it: the owner deletes the country from the rule or adds an exception for the refused address. A visitor can write to the site owner; a VPN routes around a geo block but does not remove it.

Is blocking IP addresses effective against bots?

Only against a few fixed sources. Botnets and residential proxies use many changing addresses, so behaviour-based limits work better.