Plesk

How to block or whitelist specific countries through Plesk?

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:

  1. Log into Plesk

  2. Navigate to Tools & Settings > Firewall
  3. Click to add a new rule.
  4. 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:

  1. Download the Geo2ip lite database:

    # curl -Lo /usr/share/GeoIP/GeoLiteCountry.dat.gz https://dl.miyuru.lk/geoip/dbip/country/dbip4.dat.gz

  2. Unpack it:

    # gunzip /usr/share/GeoIP/GeoLiteCountry.dat.gz

  3. 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.