A short guide on how to setup powerdns with the geo and mysql backends to redirect visitors to servers closer to their geographic location.
So how does it work?
We delegate geo.www.domain.com to our powerdns servers that run the geo backend. The backend looks up the IP address of the user’s resolver in a data structure obtained from zz.countries.nerd.dk.
This returns the ISO country code, which is then fed through a map file to determine what CNAME to respond with. Our www.domain.com record is actually just a CNAME to www.geo.domain.com which is driven by the geo backend. Our map contains the following:
$RECORD www
$ORIGIN domain.com
After the above each ISO country code is listed and essentially where you want to send them, for example:
0 pool
# Andorra
20 eu
# United Arab Emirates
784 eu
# Afghanistan
4 eu
# Antigua and Barbuda
28 eu
# Angola
24 za
0 pool is a round robin DNS pool of all our servers located across the globe.
The rest, as you can see, is redirected to either eu or za. Note, the file is HUGE and only a few entries has been pasted here.
Our powerdns configuration looks like this:
geo-zone=geo.domain.com
geo-soa-values=ns0.domain.com,hostmaster@domain.com
geo-ns-records=ns0.domain.com,ns1.domain.com
geo-ip-map-zonefile=/home/geo/zz.countries.nerd.dk.rbldnsd
geo-maps=/etc/powerdns/geo-maps
launch=geo,gmysql
The zz.countries.nerd.dk.rbldnsd file countains all countries and their ISO country numbers. More information and how to get a copy of this (rsync once a week) can be obtained from http://countries.nerd.dk/more.html.
Our normal DNS domains and records are stored in MySQL, more information regarding that can be found in the powerdns documentation.
Here are some DNS query examples:
dig @ns0.coretanium.net nosuchdomainhere.com A
;www.nosuchdomainhere.com. IN A
www.nosuchdomainhere.com. 604800 IN CNAME www.geo.nosuchdomainhere.com.
www.geo.nosuchdomainhere.com. 3600 IN CNAME eu.nosuchdomainhere.com.
eu.nosuchdomainhere.com. 86400 IN A 87.194.37.132
As you can see, www.nosuchdomainhere.com is a CNAME to www.geo.nosuchdomainhere.com, from there it passes through the geo backend and it says your coming from lets say Germany, our geo mapping file then says country code 276 needs to go to eu(.nosuchdomainhere.com) and eu.nosuchdomainhere.com resolves to 127.0.0.1.
And that’s it. A brief explanation on how to use powerdns with the geo backend.
Hi,
Thanks for the very interesting introduction. However, I have been looking all over the internet for a /complete/ tutorial for this and the resources are extremely minimal. Most of them uses a seperate BIND, and I want to have an all in one powerdns with mysql and geo like yours.
I was wondering if I can show you what I have done and if you can help me a little in showing what I did wrong.
Thanks