GeoIP 簡単検索 Maxmind GeoLite2

目的

自動アップデートされる GeoIP データベースを無料で利用する

事前準備

MAXMIND アカウントの作成とアカウントへのログイン
 → "My License Key" の作成
   *作成時に下記の GeoIP update に使う設定ファイル (GeoIP.conf) が自動作成されるので、ダウンロードしておく
 

GeoLite2 DB 自動アップデートと検索

Ubuntu 20 では簡単
 
- install
 
$ lsb_release -d
Description: Ubuntu 20.04 LTS
$ sudo add-apt-repository ppa:maxmind/ppa
$ sudo apt update
$ sudo apt install geoipupdate
 
- import config file & configure
 
$ mkdir Maxmind
$ cd Maxmind
$ scp hoge@fuga:/GeoIP.conf .
$ echo "DatabaseDirectory $PWD" >> GeoIP.conf
 
- execute
 
$ geoipupdate -f GeoIP.conf 
$ ls
GeoIP.conf  GeoLite2-ASN.mmdb  GeoLite2-City.mmdb  GeoLite2-Country.mmdb
 
- auto update
 
$ crontab -l
5 1 * * * /usr/bin/geoipupdate -f /home/hoge/Maxmind/GeoIP.conf
 
- db search
 
$ sudo apt install libmaxminddb0 libmaxminddb-dev mmdb-bin
$ mmdblookup -f GeoLite2-City.mmdb -i 1.2.3.4
 
 
--------------------------------------------------