Blockieren des Zugriffs aus einem bestimmten Land: Unterschied zwischen den Versionen

(Auf Mod_maxminddb umgeändert, da geoip nicht mehr aktiv)
Zeile 5: Zeile 5:
 
== Mithilfe von mod_geoip in der .htaccess: ==
 
== Mithilfe von mod_geoip in der .htaccess: ==
  
=== Syntax ab Apache 2.3: ===
+
=== Blockieren von IPs eines Landes ===
  
 
'''Grundsätzlich:'''  
 
'''Grundsätzlich:'''  
  
  RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(Country_Code)$
+
  <IfModule mod_maxminddb.c>
  RewriteRule ^(.*)$ - [F,L]
+
  MaxMindDBEnable On
 +
  MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
 +
  MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
 +
  SetEnvIf MM_COUNTRY_CODE ^(Country_Code) BlockCountry
 +
  Deny from env=BlockCountry
 +
  </IfModule>
  
'''Beispiel: Russland & China & Südkorea''':
+
'''Beispiel: Russland & China & Vietnam''':
  
  RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(RU|CN|KR)$
+
  <IfModule mod_maxminddb.c>
  RewriteRule ^(.*)$ - [F,L]
+
  MaxMindDBEnable On
 +
  MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
 +
  MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
 +
  SetEnvIf MM_COUNTRY_CODE ^(RU|CN|VN) BlockCountry
 +
  Deny from env=BlockCountry
 +
  </IfModule>
  
 
==== Erlauben von IPs eines Landes ====
 
==== Erlauben von IPs eines Landes ====
Zeile 21: Zeile 31:
 
'''Grundsätzlich:'''  
 
'''Grundsätzlich:'''  
  
  RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^(Country_Code)$
+
  <IfModule mod_maxminddb.c>
  RewriteRule ^(.*)$ - [F,L]
+
  MaxMindDBEnable On
 +
  MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
 +
  MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
 +
  SetEnvIf MM_COUNTRY_CODE ^(Country_Code) AllowCountry
 +
  Order Allow,Deny
 +
  Allow from env=AllowCountry
 +
  </IfModule>
 +
 
  
 
'''Beispiel: Deutschland''':
 
'''Beispiel: Deutschland''':
  
  RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^(DE)$
+
  <IfModule mod_maxminddb.c>
  RewriteRule ^(.*)$ - [F,L]
+
  MaxMindDBEnable On
 +
  MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
 +
  MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
 +
  SetEnvIf MM_COUNTRY_CODE ^(DE) AllowCountry
 +
  Order Allow,Deny
 +
  Allow from env=AllowCountry
 +
  </IfModule>
  
 +
'''Wichtig: Dadurch werden nur IP-Adressen aus Deutschland erlaubt.'''
  
 
'''Eine Liste für die verschiedenen Ländercodes (ISO-3166 alpha2): https://www.geonames.org/countries/'''
 
'''Eine Liste für die verschiedenen Ländercodes (ISO-3166 alpha2): https://www.geonames.org/countries/'''

Version vom 20. Oktober 2023, 18:36 Uhr


Falls man gewisse Länder aufgrund von vielen Bot-Aktivitäten sperren möchte, kann man hierbei die Ländererkennung bei apache2 in der .htaccess verwenden. Hierzu braucht man nur ein paar Zeilen mit dem jeweiligen Land (siehe hier), was man sperren möchte, einfügen:

Mithilfe von mod_geoip in der .htaccess:

Blockieren von IPs eines Landes

Grundsätzlich:

<IfModule mod_maxminddb.c>
 MaxMindDBEnable On
 MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
 MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
 SetEnvIf MM_COUNTRY_CODE ^(Country_Code) BlockCountry
 Deny from env=BlockCountry
</IfModule>

Beispiel: Russland & China & Vietnam:

<IfModule mod_maxminddb.c>
 MaxMindDBEnable On
 MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
 MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
 SetEnvIf MM_COUNTRY_CODE ^(RU|CN|VN) BlockCountry
 Deny from env=BlockCountry
</IfModule>

Erlauben von IPs eines Landes

Grundsätzlich:

<IfModule mod_maxminddb.c>
 MaxMindDBEnable On
 MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
 MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
 SetEnvIf MM_COUNTRY_CODE ^(Country_Code) AllowCountry
 Order Allow,Deny
 Allow from env=AllowCountry
</IfModule>


Beispiel: Deutschland:

<IfModule mod_maxminddb.c>
 MaxMindDBEnable On
 MaxMindDBFile DB /usr/local/share/maxminddb/GeoLite2-Country.mmdb
 MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
 SetEnvIf MM_COUNTRY_CODE ^(DE) AllowCountry
 Order Allow,Deny
 Allow from env=AllowCountry
</IfModule>

Wichtig: Dadurch werden nur IP-Adressen aus Deutschland erlaubt.

Eine Liste für die verschiedenen Ländercodes (ISO-3166 alpha2): https://www.geonames.org/countries/