[Eisfair] GeoIP und Block Complete Networks - Anleitung

Jürgen Pfautsch newsreply6 at clubeckstein.de
Mi Mär 6 12:46:30 CET 2024


Moin.
Da es das Paket Block_Complete Countries nicht mehr gibt, war ich auf 
der Suche nach einer Alternative und bin auf

https://www.seenlyst.com/blog/geo-blocking-ufw-iptables

fündig geworden. Die Anleitung dort ist nicht mehr ganz aktuell und paßt 
eh nicht zum Eisfair, weswegen ich sie hier adaptiert habe.

Folgende Pakete sind erforderlich:
eisman upgrade curl perl xtables-geoipupdate xtables-geoipupdate-legacy 
unzip perl-text-csv-xs -y

Weiterhin:
xtables-addons und dazu die dem Kernel entsprechenden Modul Pakete
nicht erforderlich: perl-moosex, weil die tables nicht mehr von Maxmind 
geladen werden, sondern von einer anderen Adresse

Jetzt wird die Datenbank heruntergeladen und vorbereitet.
Das läuft über ein Script, welches wir hier erstellen:

sudo mkdir -p /usr/share/xt_geoip
sudo nano /usr/local/bin/update-geoip.sh

Dor hinein kopiert ihr folgenden Text

#!/bin/bash
# Create temporary directory
mkdir -p /usr/share/xt_geoip/tmp/
mkdir -p /usr/share/xt_geoip/tmp/ip2loc/

# Download latest from db-ip.com
cd /usr/share/xt_geoip/tmp/
/usr/libexec/xtables-addons/xt_geoip_dl

# Download latest from https://github.com/sapics/ip-location-db
wget -P /usr/share/xt_geoip/tmp/ 
https://cdn.jsdelivr.net/npm/@ip-location-db/geo-whois-asn-country/geo-whois-asn-country-ipv4.csv
#wget -P /usr/share/xt_geoip/tmp/ 
https://cdn.jsdelivr.net/npm/@ip-location-db/geo-whois-asn-country/geo-whois-asn-country-ipv6.csv
wget -P /usr/share/xt_geoip/tmp/ 
https://cdn.jsdelivr.net/npm/@ip-location-db/iptoasn-country/iptoasn-country-ipv4.csv
#wget -P /usr/share/xt_geoip/tmp/ 
https://cdn.jsdelivr.net/npm/@ip-location-db/iptoasn-country/iptoasn-country-ipv6.csv
wget -P /usr/share/xt_geoip/tmp/ 
https://cdn.jsdelivr.net/npm/@ip-location-db/dbip-country/dbip-country-ipv4.csv
#wget -P /usr/share/xt_geoip/tmp/ 
https://cdn.jsdelivr.net/npm/@ip-location-db/dbip-country/dbip-country-ipv6.csv
wget -P /usr/share/xt_geoip/tmp/ 
https://cdn.jsdelivr.net/npm/@ip-location-db/geolite2-country/geolite2-country-ipv4.csv
#wget -P /usr/share/xt_geoip/tmp/ 
https://cdn.jsdelivr.net/npm/@ip-location-db/geolite2-country/geolite2-country-ipv6.csv

# Combine all csv and remove duplicates
cd /usr/share/xt_geoip/tmp/
cat *.csv > geoip.csv
sort -u geoip.csv -o /usr/share/xt_geoip/dbip-country-lite.csv

# Remove temp directory and update geoip xtables
rm -r /usr/share/xt_geoip/tmp/
/usr/libexec/xtables-addons/xt_geoip_build -D /usr/share/xt_geoip -i 
/usr/share/xt_geoip/dbip-country-lite.csv
rm /usr/share/xt_geoip/dbip-country-lite.csv

#End of script

Jetzt noch die datei ausführbar machen und ausführen:

sudo chmod +x /usr/local/bin/update-geoip.sh
/usr/local/bin/update-geoip.sh

Ein
iptables -I INPUT -m geoip --src-cc IR,CN,RU,UA,RO,VN,IN,CA,FR,IT,NL -j DROP

blockt bei mir einige der häufigsten Verursacher.

Ein
iptables -I INPUT -m geoip ! --src-cc DE -j DROP
hat mich selber leider auch ausgeperrt :-/

systemctl restart iptables

und einen Haufen Leute damit frustrieren ;-)

Ob und wie man daraus ein Paket basteln kann - davon habe ich keine Ahnung.

Vielen Dank an Holger und Marcus für hilfreiche Hinweise.
Jürgen	


Mehr Informationen über die Mailingliste Eisfair