The IPFire Location Database can be downloaded by anybody, without registering, without a licence key, and without accepting an EULA. It is licensed under CC BY-SA 4.0.
There are several free databases that map IP addresses to countries: MaxMind GeoLite2, DB-IP Lite, IP2Location LITE, IPinfo Lite, and the IPFire Location Database, which libloc reads. This page explains what is different about libloc.
The IPFire Location Database can be downloaded by anybody, without registering, without a licence key, and without accepting an EULA. It is licensed under CC BY-SA 4.0.
| Database | Account Needed | Licence | Updated |
|---|---|---|---|
| IPFire Location | No | CC BY-SA 4.0 | Daily |
| MaxMind GeoLite2 | Yes (licence key) | GeoLite EULA | Twice a week |
| DB-IP Lite | No | CC BY 4.0, link back required | Monthly |
| IP2Location LITE | Yes | Own terms, attribution required | Monthly |
| IPinfo Lite | Yes (token) | CC BY-SA 4.0, attribution required | Daily |
The database is built by
location-importer(1),
which is part of libloc.
It reads the databases of the five Regional Internet Registries,
routing data, geofeeds that network operators publish themselves,
and lists like Spamhaus DROP.
Anybody can read how a network ended up in a country,
and run the importer to build the database themselves.
Every database is signed.
location(1)
checks the signature before it replaces the old database,
so that a database that has been tampered with on the way is never used.
Whether there is a new database is announced in the DNS, so that clients only download anything when there is something new.
One lookup returns the country, the Autonomous System and whether the network is special. The database knows which networks are:
A1),A2),A3),XD).
The names of all Autonomous Systems and countries are in the same file. Some other free databases need a second database for the Autonomous Systems.
libloc can walk through all networks of a country, an Autonomous System
or with a flag, and break them down so that none of them overlap.
location(1) exports them for ipset, nftables and xt_geoip,
and it can list all bogons: address space that should not be seen
on the Internet at all.
This is what IPFire uses for its location-based firewall.
One lookup in libloc returns the country and the Autonomous System. With a database in the MaxMind format, that takes two lookups in two databases. Compared with libmaxminddb and DB-IP Lite, on one thread:
| Country + ASN | libloc | libmaxminddb |
|---|---|---|
| IPv4, C | 320 ns | 710–740 ns |
| IPv6, C | 680 ns | 950–1,120 ns |
| IPv4, Python | 0.9 µs | 6.3–7.1 µs |
| IPv6, Python | 1.3 µs | 8.2–8.6 µs |
Even when only the country is needed, libmaxminddb takes 370–490 ns for IPv4 and 520–590 ns for IPv6, so libloc is about as fast for IPv4 and faster for IPv6, while returning more.
With more threads, libloc reached 8–9 million lookups per second on 16 threads for IPv4 and 7–8 million for IPv6, compared with 7–8.5 and 5–8 million for libmaxminddb. There, both are mostly limited by the machine, which they shared with other virtual machines.
These numbers are for a database written by libloc 0.9.20, which stores the tree in the order in which lookups walk through it. Databases written by older versions take 400 ns for IPv4 and 1.5 µs for IPv6 in C. All versions of libloc can read both.