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.

3 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

Not intending to 'blow my own trumpet' here, but I figured out a way of making BIND geo-aware without having to patch the source code.

See: http://phix.me/geodns/

I like this method better as it allows for upgrades to BIND as and when ISC release new versions, without having to try and re-fit source code patches in!

Hope you find this useful! :-)

Leave a comment

Recent Entries

  • Bayes Host Classification

    I run a little anti spam service and often try out different strategies to combat spam.  At present I have a custom nameserver that I...

  • Load Balancing with HAProxy

    Load Balancers are some of the most expensive bits of equipment small to medium size sites are likely to buy, even more expensive than database...

  • SixXS IPv6 and CentOS

    I thought its high time I get to spend some time with IPv6 so I signed up for a static tunnel from sixxs.net, apart from...

  • Location aware Bind for RedHat 5.3

    Previously I wrote about RPMs I built to GeoIP enable Bind using the original patches at http://www.caraytech.com/geodns/.I have now refreshed this for the latest CentOS...

  • CentOS 5.3

    CentOS 5.3 was released on the 1st of April, I've since updated a whole lot of my machines to this version and been very happy.There...

Close