The geolocation of Internet addresses has become very important or essential over the past few decades, which has led to the emergence of many providers offering this type of service.
There are many such providers, but the most notable one, offering some of the lowest latency, is MaxMind. In addition, it offers a free service called GeoLite2 that requires registration before use.
You can use different libraries to implement the service, but you can also use binaries on Linux, and in this article we will explain how to use them on Ubuntu/Debian.
Installing and configuring GeoIP
There is a package for quick and easy installation. By default, it is included in the system repository, although you can also add the MaxMind repository:
# add-apt-repository ppa:maxmind/ppaTo install the binaries and update package, run the following:
# apt update && apt install geoipupdate mmdb-bin geoip-bin
Once installed, edit the following file to enter your MaxMind account and key (MaxMind License Key):
# nano /etc/GeoIP.confThe result should look similar to the following:
# Please see https://dev.maxmind.com/geoip/geoipupdate/ for instructions
# on setting up geoipupdate, including information on how to download a
# pre-filled GeoIP.conf file.
# Enter your account ID and license key below. These are available from
# https://www.maxmind.com/en/my_license_key. If you are only using free
# GeoLite databases, you may leave the 0 values.
AccountID 00000
LicenseKey 00000000000
# Enter the edition IDs of the databases you would like to update.
# Multiple edition IDs are separated by spaces.
#
# Include one or more of the following edition IDs:
# * GeoLite2-ASN - GeoLite 2 ASN
# * GeoLite2-City - GeoLite 2 City
# * GeoLite2-Country - GeoLite2 Country
EditionIDs GeoLite2-Country GeoLite2-City GeoLite2-ASN
Once modified, update the files:
# geoipupdate -v && ls -la /var/lib/GeoIP/Once updated, you can perform an ASN, City, or Country lookup using the databases with the mmdblookup utility.
For example, to look up the ASN for the IP address 1.1.1.1:
# mmdblookup --file /var/lib/GeoIP/GeoLite2-ASN.mmdb --ip 1.1.1.1The ASN number and organization name will appear as in the following output:
{
"autonomous_system_number":
13335 <uint32>
"autonomous_system_organization":
"CLOUDFLARENET" <utf8_string>
}
We hope this tutorial has helped you 🙂. Remember, if you have any questions about this or any other issue related to your servers on Clouding, feel free to write to soporte@clouding.io We're here for whatever you need!