{"id":370,"date":"2006-07-11T13:52:57","date_gmt":"2006-07-11T12:52:57","guid":{"rendered":"http:\/\/wp.devco.net\/?p=370"},"modified":"2009-10-09T16:51:21","modified_gmt":"2009-10-09T15:51:21","slug":"location_aware_bind","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2006\/07\/11\/location_aware_bind.php","title":{"rendered":"Location aware Bind"},"content":{"rendered":"

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.
\nThe obvious answer is to just use Akamai<\/a>, 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.
\nI googled a bit and came across
a guy who made a patch<\/a> to bind 9.2.4. He bascially hooks the Maxmind<\/a> GeoIP C Library<\/a> into ISC Bind. As it turns out thats exactly the version RedHat uses in their Enterprise distribution so it seemed like a winner.
\nThe basic idea is to setup a
view<\/a> that matches countries rather than just IP Blocks as is the default supported scenario. A sample view:<\/p>\n

\n
\nview \"us\" {\nmatch-clients { country_US; };\nzone \"geotest.devco.net\" {\ntype master;\nfile \"data\/us-geotest.devco.net\";\n};\n};\nview \"other\" {\nmatch-clients { any; };\nzone \"geotest.devco.net\" {\ntype master;\nfile \"data\/other-geotest.devco.net\";\n};\n};\n<\/pre>\n<\/blockquote>\n

The above will serve us-geotest.devco.net<\/i> to visitors from the United States and everyone else will get other-geotest.devco.net<\/i>. These 2 zone files are stock standard bind zone files, my sample just set a different A record in each.
\nTo see this in action, first a query from my UK hosted machine:<\/p>\n

\n
\n% host geotest.devco.net\ngeotest.devco.net has address 193.201.200.135\n<\/pre>\n<\/blockquote>\n

and now a query from the states:<\/p>\n

\n
\n% host geotest.devco.net\ngeotest.devco.net has address 72.21.58.28\n<\/pre>\n<\/blockquote>\n

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:
\n
The actual patch from GeoDNS<\/a> – 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.
\n
Changes made to the RPM Spec file<\/a>
\n
Sample config<\/a> – this gets placed in the standard documentation directory
\nI’ve build a full RPMs of this on a
CentOS<\/a> 4.3 machine, the files are:
\n
bind-9.2.4-2geodns.i386.rpm<\/a>
\n
bind-libs-9.2.4-2geodns.i386.rpm<\/a>
\n
bind-utils-9.2.4-2geodns.i386.rpm<\/a>
\n
bind-devel-9.2.4-2geodns.i386.rpm<\/a>
\n
bind-chroot-9.2.4-2geodns.i386.rpm<\/a>
\nand finally a Source RPM that you can use to build this all on your own machine:
\n
bind-9.2.4-2geodns.src.rpm<\/a>
\nBefore you can install these you’ll need to get GeoIP on your machine, CentOS has an extras<\/i> Yum repository that you can enable in \/etc\/yum.repos.d\/CentOS-Base.repo<\/i>. Once enabled you can install it with yum:<\/p>\n

\n
\n# yum install GeoIP GeoIP-data\n<snip>\nRunning Transaction\nInstalling: GeoIP                        ######################### [1\/2]\nInstalling: GeoIP-data                   ######################### [2\/2]\nInstalled: GeoIP.i386 0:1.3.14-2.c4 GeoIP-data.i386 0:20060501-2.c4\n<\/pre>\n<\/blockquote>\n

RedHat Enterprise has an extras CD, you can find GeoIP on there and install it using RPM.
\nThe 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.<\/p>\n","protected":false},"excerpt":{"rendered":"

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 […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","footnotes":""},"categories":[7],"tags":[31,19],"_links":{"self":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/370"}],"collection":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/comments?post=370"}],"version-history":[{"count":1,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/370\/revisions"}],"predecessor-version":[{"id":604,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/370\/revisions\/604"}],"wp:attachment":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/media?parent=370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/categories?post=370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/tags?post=370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}