GeoIPLookup is available in Unix system as command line tool to look up for geolocation using IP address or hostname. It uses the GeoIP database/library usually found in:
/usr/share/GeoIP
When installed and updated, it comes up with Country and City edition databases. It would be nice if Smart IP module is also using same database and this is very useful for Drupal multi sites. We will only maintain one GeoIP database for all Drupal sites and server's GeoIPLookup tool. This article will guide to setup this use case. The following steps are tested running on my Linode server running Centos 7 64-bit. It is assumed that you have already installed Drupal with Smart IP module enabled.
-
Install the geoip:
yum install geoip
-
Initially, only one database is available:
lrwxrwxrwx. 1 root root 17 Aug 19 2015 GeoIP.dat -> GeoIP-initial.dat -rw-r--r--. 1 root root 1362244 Jun 10 2014 GeoIP-initial.dat
Let's execute the command below to download the Country and City edition databases:
geoipupdate
After the download, output should look something like this:
/usr/share/GeoIP/GeoLiteCountry.dat can't be opened, proceeding to download database Updating /usr/share/GeoIP/GeoLiteCountry.dat Updated database /usr/share/GeoIP/GeoLiteCity.dat can't be opened, proceeding to download database Updating /usr/share/GeoIP/GeoLiteCity.dat Updated database
-
To test the GeoIP Country edition database:
geoiplookup 121.1.11.166 -f /usr/share/GeoIP/GeoLiteCountry.dat
Output should be:
GeoIP Country Edition: PH, Philippines
To test the GeoIP City edition database:
geoiplookup 121.1.11.166 -f /usr/share/GeoIP/GeoLiteCity.dat
Output should be:
GeoIP City Edition, Rev 1: PH, D9, Manila, Manila, 1006, 14.604200, 120.982201, 0, 0
-
Login to your Drupal site and go to Smart IP admin page (http://www.webfoobar.com/admin/config/people/smart_ip). Under "Select Smart IP Source" select "Use Maxmind binary database", "Lite" for "Maxmind binary database version", "City" for "Maxmind binary database edition", "No" for "Automatic Maxmind binary database update" and enter "/usr/share/GeoIP" for "Maxmind binary database custom path":
-
Click "Save configuration" button.
-
To test, enter the IP address "121.1.11.166" under "Manual Lookup" and click "Lookup" button: