Adblocking Lua generator for the PowerDNS Recursor

Download all wanted block lists and place them as TXT in the same directory as the following script. You can find lots of them on


# Output Lua script file

echo "return{" > "$LUA_SCRIPT"

# Download all blocklists as .txt from and place then
# in the same directory

# Use awk to process all .txt files and append to LUA_SCRIPT
awk '!/^#/ && NF { 
        sub(/\r$/,"");  # Remove carriage return at the end of line
        if ($1 == "" && NF > 1) 
            print "\"" $2 "\",";
        else if ($1 != "") 
            print "\"" $1 "\",";
     }' *.txt >> "$LUA_SCRIPT"

echo "}" >> "$LUA_SCRIPT"

echo "Lua script written to $LUA_SCRIPT"

Move the output file to: /etc/powerdns/blocklist.lua

Create a new script /etc/powerdns/adblock.lua

function preresolve(dq)
	if(not adservers:check(dq.qname)) then
		return false
	if(dq.qtype == pdns.A) then
		dq:addAnswer(dq.qtype, "")
	elseif(dq.qtype == pdns.AAAA) then
		dq:addAnswer(dq.qtype, "::1")
	return true


Add this to the configuration (recursor.conf):


Inspired by: