Question
How to block specific countries in Plesk?
Answer
On Plesk 18.0.52 and higher with Firewall extension 2.0 installed this could be achieved following the next steps:
- Navigate to Tools & Settings > Firewall
- Click to add a new rule.
- Specify the required countries in the following fields:
For older Plesk versions the following workaround is available:
By the means of ModSecurity:
Follow the next steps to block particular countries via ModSecurity:
- Download the Geo2ip lite database:
# curl -Lo /usr/share/GeoIP/GeoLiteCountry.dat.gz https://dl.miyuru.lk/geoip/dbip/country/dbip4.dat.gz
-
Unpack it:
# gunzip /usr/share/GeoIP/GeoLiteCountry.dat.gz
- Navigate to Tools & Settings > Web Application Firewall(ModSecurity) > Settings and add the following Custom directives:
SecGeoLookupDB /usr/share/GeoIP/GeoLiteCountry.dat
SecRule REMOTE_ADDR "@geoLookup" "phase:1,chain,id:99999932392,drop,log,msg:'Blocking %{geo.country_code}'"
SecRule GEO:COUNTRY_CODE "@pm XX XX XX"Note: "XX XX XX" are to be replaced with the required country codes.