PowerDNS recursor Lua scripting examples
Today, while on the train, i finally took some time to extract some Lua scripting examples to run in PowerDNS recursor from my code.
UPDATE: because someone asked if they could use my code for their presentations i hereby declare the code examples linked in this article licensed Creative Commons Attribution 3.0 Unported License
ANOTHER UPDATE: These examples assume that you are using the latest and greatest svn trunk version of PowerDNS recursor, for v 3.1.7.2 and below (you really should update) the scripts will work if you remove any occurence of the destination variable. Also please note that the Packet Cache for the recursor in svn trunk will collide with said destination variable, you will have to disable it to use the lower two scripts in their original form.
YET ONE MORE UPDATE: With the upcoming version 3.2 of PowerDNS recursor instead of
function preresolve ( ip, destination, domain, qtype )
you would need to write
function preresolve ( ip, domain, qtype )
destination=getlocaladdress()
Would you like to know more?
So here we go.
The first one is a simple override.
The second one is about query logging with some conditions.
And finally this should be a working example for NXDOMAIN Redirection aka the Sitefinder way. Yes i know, i know, one does simply not do such an ugly thing but i fear these days many ISPs actually do it. sigh
Just in case if you wanna mock about me using iframe ins this article, i simply was tired of integrating javascript code highlighting into it and turned to pygmentize:
for file in
ls *.lua; do rm $file.html; echo '" >> $file.html; pygmentize -l lua -f html -F highlight -O style=trac $file >> $file.html; done
grr

