Skip to content

Instantly share code, notes, and snippets.

Last active November 11, 2016 19:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
-- load this and the previous snippet as 'lua-dns-script=macfilter.lua'
function macPrint(a)
return string.format("%02x:%02x:%02x:%02x:%02x:%02x", a:byte(1), a:byte(2), a:byte(3), a:byte(4), a:byte(5), a:byte(6))
function preresolve(dq)
print("Got question for "..dq.qname:toString().." from "..dq.remoteaddr:toString().." to "..dq.localaddr:toString())
local a=dq:getEDNSOption(65001)
if(a ~= nil) then
print("There is an EDNS option 65001 present: "..macPrint(a))
if(filter[dq.remoteaddr:toString()][macPrint(a)] and baddomains:check(dq.qname)) then
print("Wanted filtering")
dq:addAnswer(pdns.CNAME, "")
return true
-- an obvious enhancement is to implement a 'default' mac address describing the default
-- filtering an IP address wants
return false
Copy link

pdifeo commented Nov 11, 2016


I'm a PowerDNS newbie, and after many time of work on your script I realize that there is missing code after

dq:addAnswer(pdns.CNAME, "")

Maybe 2 lines of code must be inserted

dq.rcode = 0

Please, tell me if this is correct or no.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment