{"id":1869,"date":"2013-08-01T19:56:41","date_gmt":"2013-08-01T18:56:41","guid":{"rendered":"http:\/\/kudzia.eu\/b\/?p=1869"},"modified":"2013-12-08T19:15:28","modified_gmt":"2013-12-08T18:15:28","slug":"chrooted-bind9-with-geodns-under-debian-wheezy","status":"publish","type":"post","link":"https:\/\/kudzia.eu\/b\/2013\/08\/chrooted-bind9-with-geodns-under-debian-wheezy\/","title":{"rendered":"chrooted bind9 with geodns under debian wheezy"},"content":{"rendered":"<p>at work we&#8217;ll soon make use of dns-based geo load balancing to have users in americas \/ asia &#8216;talk&#8217; with north am site and rest of the world &#8211; with the european site. we preferred to avoid modifying the client application so the dns based solution seemed reasonable. below &#8211; quick overview of the setup under debian.<br \/>\n<!--more--><br \/>\ninstall bind:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\napt-get install bind9\r\n<\/pre>\n<p>as described in https:\/\/wiki.debian.org\/Bind9#Bind_Chroot :<\/p>\n<ul>\n<li>stop bind\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\/etc\/init.d\/bind9 stop\r\n<\/pre>\n<\/li>\n<li> in  \/etc\/default\/bind9 add:\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nOPTIONS=&quot;-u bind -t \/var\/bind9\/chroot&quot;\r\nPIDFILE=\/var\/bind9\/chroot\/var\/run\/named\/named.pid\r\n<\/pre>\n<\/li>\n<li>create needed directories \/ inodes, move configs and create links, adjust permissions:\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nmkdir -p \/var\/bind9\/chroot\/{etc,dev,var\/cache\/bind,var\/run\/named}\r\nmknod \/var\/bind9\/chroot\/dev\/null c 1 3\r\nmknod \/var\/bind9\/chroot\/dev\/random c 1 8\r\nchmod 660 \/var\/bind9\/chroot\/dev\/{null,random}\r\nmv \/etc\/bind \/var\/bind9\/chroot\/etc\r\nln -s \/var\/bind9\/chroot\/etc\/bind \/etc\/bind \r\nchown -R bind:bind \/etc\/bind\/*\r\nchmod 775 \/var\/bind9\/chroot\/var\/{cache\/bind,run\/named}\r\nchgrp bind \/var\/bind9\/chroot\/var\/{cache\/bind,run\/named}\r\n<\/pre>\n<\/li>\n<li>configure syslog:\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\necho &quot;\\$AddUnixListenSocket \/var\/bind9\/chroot\/dev\/log&quot; &gt; \/etc\/rsyslog.d\/bind-chroot.conf\r\n<\/pre>\n<\/li>\n<li>restart rsyslogd, bind:\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n\/etc\/init.d\/rsyslog restart; \/etc\/init.d\/bind9 start\r\n<\/pre>\n<\/li>\n<\/ul>\n<p>debian&#8217;s bind9 supports geoip out of the box &#8211; it&#8217;s already patched. normally the geoip database is kept in debian under \/usr\/share\/GeoIP\/GeoIP.dat ; since bind is chrooted we need to copy that file:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\napt-get install geoip-database\r\nmkdir -p \/var\/bind9\/chroot\/usr\/share\/GeoIP\/\r\ncp \/usr\/share\/GeoIP\/* \/var\/bind9\/chroot\/usr\/share\/GeoIP\/\r\n<\/pre>\n<p>this database should be updated periodically, in both locations.<\/p>\n<p>to make use of the &#8216;split view&#8217; configuration where we define different responses depending on the country from which dns request has arrive i:<\/p>\n<ul>\n<li>edit \/var\/bind9\/chroot\/etc\/bind\/named.conf and comment out the line &#8216;include &#8220;\/etc\/bind\/named.conf.default-zones&#8221;;&#8217;<\/li>\n<li>add new content in named.conf.local:\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nview &quot;sweden&quot; {\r\n        match-clients { country_SE; };\r\n        allow-recursion { recurseallow_acl; };\r\n        zone &quot;test.kudzia.eu&quot; {\r\n                type master;\r\n                file &quot;\/etc\/bind\/zones\/sweden-test.kudzia.eu&quot;;\r\n                notify no;\r\n        };\r\n        include &quot;\/etc\/bind\/otherZones.conf&quot;;\r\n        include &quot;\/etc\/bind\/named.conf.default-zones&quot;;\r\n};\r\nview &quot;other&quot; {\r\n        match-clients { any; };\r\n        allow-recursion { recurseallow_acl; };\r\n        zone &quot;geo.test.kudzia.eu&quot; {\r\n                type master;\r\n                file &quot;\/etc\/bind\/zones\/rest-test.kudzia.eu&quot;;\r\n                notify no;\r\n        };\r\n        include &quot;\/etc\/bind\/otherZones.conf&quot;;\r\n        include &quot;\/etc\/bind\/named.conf.default-zones&quot;;\r\n};\r\n<\/pre>\n<p>this might look convoluted but makes sense. to avoid duplication zones that do not require geo-dns are defined in otherZones.conf and only the part that needs to be geo-dependent goes to \/var\/bind9\/chroot\/etc\/bind\/rest-test.kudzia.eu and \/var\/bind9\/chroot\/etc\/bind\/sweden-test.kudzia.eu.<\/p>\n<p>for me it even made sense to have main records s1.test.kudzia.eu and s2.test.kudzia.eu use CNAME to point to s1.geo.test.kudzia.eu and s2.geo.test.kudzia.eu and have only the geo.test.kudzia.eu zone configured with 2 different views depending on the geo-location of the dns resolver sending us the query.\n<\/li>\n<\/ul>\n<p>secondary dns server[s] will not be able to use ordinary zone transfer mechanism for the zones that provide different responses based on geoip lookup. configure it as if it was a master and copy the zone files\/configs manually whenever they get changed.<\/p>\n<p><b>2013-12-08<\/b> i&#8217;ve been using this setup in the production for the last few weeks and all seems fine. i&#8217;m getting some percent of &#8216;incorrect&#8217; assignments &#8211; especially users from the UK end up on the north american servers instead of european ones [ google dns users? ] &#8211; but it&#8217;s not grave. having a dns server that understands <a href=\"http:\/\/tools.ietf.org\/html\/draft-vandergaast-edns-client-subnet-01\">edns-client-subnet<\/a> would be nice, but it seems quite cumbersome &#8211; i&#8217;d have to notify operators like google, easydns and others that i can &#8216;understand&#8217; this record correctly &#8211; this does not seem scalable. related <a href=\"http:\/\/serverfault.com\/q\/555421\/2413\">question<\/a> on the serverfault.<\/p>\n<p>helpful materials:<\/p>\n<ul>\n<li>http:\/\/www.caraytech.com\/geodns\/<\/li>\n<li>https:\/\/wiki.debian.org\/Bind9#Bind_Chroot<\/li>\n<li>http:\/\/www.criten.org\/2011\/08\/bind-with-geoip-on-debian\/<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>at work we&#8217;ll soon make use of dns-based geo load balancing to have users in americas \/ asia &#8216;talk&#8217; with north am site and rest of the world &#8211; with the european site. we preferred to avoid modifying the client application so the dns based solution seemed reasonable. below &#8211; quick overview of the setup [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-1869","post","type-post","status-publish","format-standard","hentry","category-tech"],"_links":{"self":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/1869","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/comments?post=1869"}],"version-history":[{"count":17,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/1869\/revisions"}],"predecessor-version":[{"id":1967,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/posts\/1869\/revisions\/1967"}],"wp:attachment":[{"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/media?parent=1869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/categories?post=1869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kudzia.eu\/b\/wp-json\/wp\/v2\/tags?post=1869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}