Location aware Bind

I have a client who needs to host graphic content closer to their audience, partly to speed things up for their audience but also to allow them to save some money on bandwidth bills by spreading it out to cheaper hosts.

The obvious answer is to just use Akamai, but unless you have a huge amount of bandwidth it does not really make financial sense. So I proposed we get a few UML / Virtual Machines at ISPs and host the images there. Typically we'd just round-robin the A record but this doesn't give us any geo-awareness.

I googled a bit and came across a guy who made a patch to bind 9.2.4. He bascially hooks the Maxmind GeoIP C Library into ISC Bind. As it turns out thats exactly the version RedHat uses in their Enterprise distribution so it seemed like a winner.

The basic idea is to setup a view that matches countries rather than just IP Blocks as is the default supported scenario. A sample view:

view "us" {
        match-clients { country_US; };
        zone "geotest.devco.net" {
                type master;
                file "data/us-geotest.devco.net";
        };
};
view "other" {
        match-clients { any; };
        zone "geotest.devco.net" {
                type master;
                file "data/other-geotest.devco.net";
        };
};

The above will serve us-geotest.devco.net to visitors from the United States and everyone else will get other-geotest.devco.net. These 2 zone files are stock standard bind zone files, my sample just set a different A record in each.

To see this in action, first a query from my UK hosted machine:

% host geotest.devco.net
geotest.devco.net has address 193.201.200.135

and now a query from the states:

% host geotest.devco.net
geotest.devco.net has address 72.21.58.28

So to make a long story short, I've patched the stock RedHat Enterprise 4 bind RPM with the GeoDNS patch and am making the files available here, first I have the source files up if you want to look through them to ensure I didn't put any funny stuff in them:

The actual patch from GeoDNS - I had to modify the file names in the patch since the one from the source site is made to patch from outside the bind source dir while RPM will change directory into the source directory before running the patch.
Changes made to the RPM Spec file
Sample config - this gets placed in the standard documentation directory

I've build a full RPMs of this on a CentOS 4.3 machine, the files are:
bind-9.2.4-2geodns.i386.rpm
bind-libs-9.2.4-2geodns.i386.rpm
bind-utils-9.2.4-2geodns.i386.rpm
bind-devel-9.2.4-2geodns.i386.rpm
bind-chroot-9.2.4-2geodns.i386.rpm

and finally a Source RPM that you can use to build this all on your own machine:
bind-9.2.4-2geodns.src.rpm

Before you can install these you'll need to get GeoIP on your machine, CentOS has an extras Yum repository that you can enable in /etc/yum.repos.d/CentOS-Base.repo. Once enabled you can install it with yum:

# yum install GeoIP GeoIP-data
<snip>
Running Transaction
  Installing: GeoIP                        ######################### [1/2] 
  Installing: GeoIP-data                   ######################### [2/2] 

Installed: GeoIP.i386 0:1.3.14-2.c4 GeoIP-data.i386 0:20060501-2.c4

RedHat Enterprise has an extras CD, you can find GeoIP on there and install it using RPM.

The bind RPMs above should simply install on your standard CentOS/RedHat Enterprise box, be sure to remove all the old bind stuff especially bind-libs before installing these.

2 Comments

looking for a way to make this work with BIND 9.4.1-P1 i have the patches but I am running into problems how hard would it be to get RPMS for that version of BIND for Redhat 4ES

Chroot bind+GeoIP will not work correctly unless copy the GeoIP.dat into /var/named/chroot/var/lib/GeoIP

Leave a comment

Recent Entries

  • flashpolicyd 2.0

    I wrote a multi threaded server for Adobe Flash Policy requests, some background from Adobe:Since policy files were first introduced, Flash Player has recognized /crossdomain.xml...

  • Adventures with Ruby

    Some more about my continuing experiences with ruby, in my last post I saidthe language does what you'd expect and as you'll see in my...

  • New programming language of choice - Ruby

    I have fallen out of love with Perl some time ago, I cannot point to one specific thing about it that put me off, I...

  • On working from home

    I've not been posting much here, work has been incredibly manic the last while, especially I need to still finish off my SSO posts with...

  • Rework of puppet facts for /etc/facts.txt

    Previously I blogged a custom fact that reads /etc/facts.txt to build up some custom facts for use in Puppet manifests, well I've since learned a...

Close