Miscellaneous » Block access by country
TL;DR
WP fail2ban Premium lets you reject requests from selected countries before normal WordPress processing continues. You can return 403 Forbidden for an ordinary access policy or 451 Unavailable For Legal Reasons when the restriction is legal, and each refusal is recorded as a hard-filter event.
Premium uses the client's IP address to look up its apparent country and keeps the MaxMind GeoLite2 database current automatically. This is a practical way to reduce traffic from places your site does not serve; it is not a claim about the person behind the address.
Apply the geographic policy your site needs
Your site may serve a defined market, avoid jurisdictions where it does not operate, or need to apply a legal restriction. WP fail2ban turns that decision into a clear list of countries whose requests WordPress should refuse.
The block is applied early, before normal WordPress processing continues. WP fail2ban is enforcing the policy you chose rather than treating every visitor from that country as inherently hostile.
The decision depends on the client address WordPress receives. If a reverse proxy or CDN supplies it, WP fail2ban can preserve that address before making the country lookup.
More about getting the real client IP behind a proxy.
Choose the response that explains the block
For an ordinary geographic restriction, WP fail2ban returns 403 Forbidden.
When access is unavailable for legal reasons, you can use 451 Unavailable For Legal Reasons instead. WP fail2ban also supplies the corresponding blocked-by link information, so the response describes why the request was refused rather than presenting it as a generic access failure.
Keep the location data current
You provide a MaxMind licence key, and WP fail2ban Premium downloads the GeoLite2 country database and keeps it current through its regular weekly maintenance.
That removes the need to manage a static geolocation database yourself. Your country policy continues to use current address-allocation data as networks change.
See the policy being enforced
Every rejected request is recorded with the apparent country and the HTTP response status. The standard hard filter can match the event, and Premium keeps it in the event log for investigation and reporting.
The WordPress request has already been refused. Where fail2ban is available, the event also gives it a clear decision to enforce outside WordPress.
Use country as a practical boundary
IP geolocation tells you where an address appears to be located. It does not determine a person's nationality, residence, or physical location, and someone can appear elsewhere by using a VPN or another proxy.
Country blocking is therefore best-effort, which is usually enough for its intended job: reducing routine exposure to countries your site has decided not to serve.