GeoIP-Datenbanken

dbip

https://db-ip.com/

Die freie Variante wird monatlich aktualisiert, kommt ohne Account aus, ist aber auch etwas ungenauer als die von Maxmind.

timestamp=$(date "+%Y-%m")

# dbip Country Database in CSV format:
wget https://download.db-ip.com/free/dbip-country-lite-$timestamp.csv.gz -O- | gzip -cd > dbip-country-lite.csv

# dbip City Database in GeoIP2 binary format:
wget https://download.db-ip.com/free/dbip-city-lite-$timestamp.mmdb.gz

Maxmind

Um die neuen „GeoLite2“ GeoIP-Datenbank von Maxmind zu nutzen, benötigt man bei ihnen einen Online-Account. Wie folgt vorgehen:

  • MaxMind-Account erstellen.

  • Nach der Account-Erstellung erhält man nach ein paar Stunden eine Bestätigungs-E-Mail mit den Anmeldedaten.

  • Anmelden > „My license key“ > „Generate a new license key“

  • Beschreibung des Lizenzschlüssels eingeben, z. B. „iptables“ oder „Matomo“, und „No“ bei „Will this key be used for GeoIP Update?“ wählen.

Edition-IDs:

  • GeoLite2-ASN

  • GeoLite2-ASN-CSV

  • GeoLite2-City

  • GeoLite2-City-CSV

  • GeoLite2-Country

  • GeoLite2-Country-CSV

Die Datenbanken sollten typischerweise 1x pro Woche aktualisiert werden.

Download per wget (empfohlen)

Das Einschliessen der Download-URL in Double-Quotes ist wegen & erforderlich. Das Skript ist auch gleichzeitig für Cron, Systemd-Timer etc. nutzbar:

update-maxmind.sh
#!/usr/bin/env bash

MM_LIC=mylic
MM_DB=GeoLite2-Country

cd /tmp
wget "https://download.maxmind.com/app/geoip_download?edition_id=$MM_DB&suffix=tar.gz&license_key=$MM_LIC" -O $MM_DB.tar.gz
tar xzf $MM_DB.tar.gz
\cp GeoLite2-Country_*/GeoLite2-Country.mmdb /usr/share/GeoIP/
rm -rf /tmp/GeoLite2-Country*
Download per Maxmind-Tools

Wer die Datenbanken nur im GeoIP2 Binary-Format (.mmdb) benötigt, kann für die einfache Pflege die Maxmind-Tools herunterladen (das Tool zieht keine CSV-Dateien):

# https://github.com/maxmind/geoipupdate
VER=4.8.0
yum -y install https://github.com/maxmind/geoipupdate/releases/download/v$VER/geoipupdate_"$VER"_linux_amd64.rpm
/etc/GeoIP.conf
AccountID 999999
LicenseKey mylic

# example editions:
EditionIDs GeoLite2-ASN GeoLite2-Country GeoLite2-City

Download der binären Datenbanken nach /usr/share/GeoIP/:

geoipupdate

Maxmind „Legacy“

Die alten „legacy“ GeoLite-Datenbanken finden sich hier:

wget https://legacy-geoip-csv.ufficyo.com/Legacy-MaxMind-GeoIP-database.tar.gz

Country Codes

Siehe https://en.wikipedia.org/wiki/ISO_3166-1 (Alpha-2 code)

Built on 2024-04-18