How to create your own .mmdb for gdnsd or any other nameserver

NeoonNeoon OGSenpai
edited April 2023 in Technical

Hey,

Simple Tutorial to create your own .mmdb for gdnsd.

You need a .mmdb writer, I suggest coded in python3, but there is also one in Perl and Go, depending on what you prefer.

Python3 writer can be found here:
https://github.com/vimt/MaxMind-DB-Writer-python
https://github.com/maxmind/mmdbwriter (Go)
https://github.com/maxmind/MaxMind-DB-Writer-perl (Perl)

I slightly needed to modify it, because of the data type, gdnsd strictly validates the geo cordinates.
https://github.com/Ne00n/MaxMind-DB-Writer-python

After Installing, you can build your own, .mmdb, that works out of the box with gdnsd.

from netaddr import IPNetwork, IPSet
from mmdb_writer import MMDBWriter
import geoip2.database

writer = MMDBWriter(4, 'GeoIP2-City', languages=['EN'], description="Mah own .mmdb")
subnets = ["1.1.1.0/24","8.8.8.0/24"]
writer.insert_network(IPSet(subnets), {'location':{"latitude":1.11,"longitude":2.22}})
writer.to_db_file('geo.mmdb')

reader = geoip2.database.Reader("geo.mmdb")

response = reader.city("1.1.1.1")
print(response.location.latitude,response.location.longitude)

response = reader.city("8.8.8.8")
print(response.location.latitude,response.location.longitude)

Will return.

1.11 2.22
1.11 2.22

Put the geo.mmdb into /etc/gdnsd/geoip
Example gdnsd config for that setup.

plugins => { geoip => {
  maps => {
    prod => {
      geoip2_db => geo.mmdb,
      datacenters => [1,2,3],
      auto_dc_coords => {
       1 => [ 52.22, 21.01 ],
       2 => [ 1.35, 103.81 ],
       3 => [ 40.71, -74 ],
      }
    }
  },
  resources => {
    prod_www => {
      map => prod
      service_types => up
      dcmap => {
       1 => 1.1.1.1,
       2 => 2.2.2.2,
       3 => 3.3.3.3,
      }
    }
  }
}}

You can install gdnsd simply with apt-get.
gdnsd is not available for Ubuntu 22.04, however for 20.04, 23.04, Debian 10, Debian 11 and Debian 12.

Given the low memory usage and good performance by gdnsd, you can even run this with a fat .mmdb on low end boxes, like I do.

Enjoy.

Comments

  • NeoonNeoon OGSenpai

    You probably want to define your own zone too in /etc/gdnsd/zones

    $TTL 86400
    @     SOA ns1 mahdomain.net (
          1      ; serial
          7200   ; refresh
          30M    ; retry
          3D     ; expire
          900    ; ncache
    )
    @       NS      ns1
    ns1 3600 A 1.1.1.1
    @       NS      ns2
    ns2 3600 A 2.2.2.2
    
    test   30        DYNA     geoip!prod_www
    
    Thanked by (2)Not_Oles tuc
  • FrankZFrankZ Moderator
    edited April 2023

    gDNSd is a great geo-cast dns server, I have been using it for many years. Since there is no package available via yum/dnf for CentOS/Alma/Rocky Linux I made a compiled 3.7 version gDNSd, and all the required binaries, with install/uninstall script for these O/S. It currently downloads the IP MMDB from db-ip.com, which can be turned off if anyone wants to use their own DB like you have done. You can download the tarball here use tar -xf to untar, cd to directory gdnsd-37-alma8-centos7-8-rocky, and run ./install, then follow the prompts. To uninstall just run ./uninstall from the same directory.

    I am not sure what verson of gDNSd is being offered by apt-get in Debian/Ubuntu these days, but last I checked it was version 2.4. If this is still the case, I also have the same install script for gDNSd version 3.8, with all the required binaries, for deb10-ubuntu18, and deb11-ubuntu20-21 if anyone needs it.

    @Neoon what are you using to manage your gDNSd servers ?
    I made a panel to keep my 16 gDNSd servers in sync, but the downside to general release of the panel is that it requires root ssh access to update/reload the gDNSd servers on each VM.

    NOTE: It seems that if you geo-cast the DNS servers with gDNSd it seems to work rather well after the first lookup at the registry. I know that seems to be counter intuitive, but in my comparisons it had shorter DNS lookup times from around the world than using something like BuyVM's anycast in 3/4 locations.

    EDIT: added download location for CentOS/Alma/Rocky gDNSd install tarball.

    Thanked by (2)Not_Oles atomi

    For staff assistance or support issues please use the helpdesk ticket system at https://support.lowendspirit.com/index.php?a=add

  • NeoonNeoon OGSenpai

    @FrankZ said:
    gDNSd is a great geo-cast dns server, I have been using it for many years. Since there is no package available via yum/dnf for CentOS/Alma/Rocky Linux I made a compiled 3.7 version gDNSd, and all the required binaries, with install/uninstall script for these O/S. It currently downloads the IP MMDB from db-ip.com, which can be turned off if anyone wants to use their own DB like you have done. You can download the tarball here use tar -xf to untar, cd to directory gdnsd-37-alma8-centos7-8-rocky, and run ./install, then follow the prompts. To uninstall just run ./uninstall from the same directory.

    yea, compiling gdnsd even on Debian is pain.

    I am not sure what verson of gDNSd is being offered by apt-get in Debian/Ubuntu these days, but last I checked it was version 2.4. If this is still the case, I also have the same install script for gDNSd version 3.8, with all the required binaries, for deb10-ubuntu18, and deb11-ubuntu20-21 if anyone needs it.

    Debian 12 is going to ship with 3.8 anyway in a few weeks, despite that, 3.5 works fine on Debian 11.
    Ubuntu 23.04 has been released too, ships with 3.8.

    @Neoon what are you using to manage your gDNSd servers ?
    I made a panel to keep my 16 gDNSd servers in sync, but the downside to general release of the panel is that it requires root ssh access to update/reload the gDNSd servers on each VM.

    I use https://github.com/Ne00n/woodCDN/tree/gdnsd
    Running https://cdn.kurwa.dev/ (with lets encrypt)

    It uses rqlite as distributed database, fast enough for my use case.
    Python keeps nginx and gdnsd in sync, plus keep alive if a server has an outage, the dns servers will reroute traffic.

    Right now I am playing around with BuyVM anycast, once again. (anycast.kurwa.dev)

    NOTE: It seems that if you geo-cast the DNS servers with gDNSd it seems to work rather well after the first lookup at the registry. I know that seems to be counter intuitive, but in my comparisons it had shorter DNS lookup times from around the world than using something like BuyVM's anycast in 3/4 locations.

    Tell me more.

Sign In or Register to comment.