The MaxMind GeoLite database has always been popular, as the only free (as in beer) source of information to try and figure our what country requests are coming from.
It's incredibly inaccurate, but it is useful if you want a simple fast way to block a whole country or region from your web site.
Cloudflare would be a better bet for 90%+ accuracy.
Why did MaxMind change the database format?
Unfortunately the original database format only supported IPV4. So MaxMind had a pretty good reason to move to a format that also supported IPV6.
And why is that a problem?
Because, Open Source projects like HAProxy have tended to use the original IPV4 only MaxMind .DAT format database. Why? Because it was fast, simple and easy to use. Now, you can usually work out a way to use the newer, and more complex .MMDB format with open source tools...
For instance, most of the HAProxy GeoIP examples you'll find on the internet use the old format... :-(.
But, if I have a MaxMind license can't I just download the file?
Well yes, that would definitely be easier... But unfortunately they've stopped providing the old format!
Thankfully, the tool I'm going to explain essentially acts as a translator, taking the raw data and re-packaging it so your open source tool can actually read it.
A simple (ish) Open Source conversion tool for MaxMind DB
OK, what I thought was a simple problem, turned out to be slightly trickier than expected!
When I looked into this I realised that a lot of the open source libraries for doing the conversion are no longer supported... And so I had to create a stable and predictable environment to run legacy libraries... Otherwise automatic security updates would probably break everything..
So I decided to build it all in a docker container, and you'll need a suitable environment to run it....
Infrastructure prerequisites
Before we start, I'm going to make the following assumptions:
- You have a working Docker host with internet access
- You have a MaxMind Licences (API) key
- You have sign up for GeoLite on the MaxMind website
How to get the tool up and running in Docker
Follow the simple steps below:
- Obtain the latest version of the GeoIP Convert tool: download the package here and download CheckSums from here.
- Transfer the folder called 'File For Docker Host' to your docker host:
scp -r ./Geoip-Converter-mk1.tar.gz <User>@<Host>:~- Decompress the file:
tar -xvzf ./Geoip-Converter-mk1.tar.gz
- Move it into a new directory:
cd Geoip-Converter-mk1- Restore the docker image:
docker load -i geoip_convert-v2-v1.tar
- Make the required folder:
mkdir geoip_data- Check the image has been restored - you should see “ geoip_convert-v2-v1:<tag> " :
docker image ls- Edit the docker-compose.yml and enter your MaxMond API key (keeping the quotation marks):
- Run the docker compose file:
docker compose up -d - Once complete the container will exit:
docker ps- Clean up the exited container:
Docker compose down - The file then needs to be transferred to the load balancer. The file path is: /usr/local/geo/data
Was it all worth it?
I knocked this up for fun to address a specific customer requirement. And, I'm sure there is a much simpler way of doing it.
Do you know? If so, please do the right thing and let everyone else in on your secret. Just add a comment to this blog post...
Thank you!