[Pdns-users] Lua Script to block a list of domains and redirect to a block page

Clifford Dsouza clifford at microscan.co.in
Mon Feb 13 06:38:07 UTC 2023


I am using powerdns recursor 4.8.2 and the lua version is Lua 5.1.4

Am trying to achieve the function  to block a list of domains via the below lua script and then redirect the request to a local block page

-- Define new Domain Set
-- Load Domain Set from the file. Format of the file is: 'return {"a.com", "b.com", "a.fb.com"}'
-- blocked_domains:add(dofile("/etc/pdns-recursor/blocked_domains.txt"))
-- define a preresolve() function which gets called by PowerDNS to determine what to do with a domain
 function preresolve(dq)
  -- If we see that a query name is not part of one of the blocked domains,
         -- or the query is not for an IP(v6) address, we return false and the normal resolution process continues.
             if(not blocked_domains:check(dq.qname) or (dq.qtype ~= pdns.A and dq.qtype ~= pdns.AAAA)) then
                     return false


  dq:addAnswer(pdns.A, "")
return true

The thing is that this script only blocks and redirect the user if the site is an http domain, if its a https domain no block page is displayed though the site does not open

how do i improve the script so that the domain is blocked and redirected to the block page even if its a https site, some where on the internet it refered to set the code to nxdomain and  then redirect the request to the block page but i cant get the code right, some help will be much appreciated.

also currently I have redirected the block page to the IP "" can i also get the code to redirect to a domain name instead of an IP address?

Thanks you

Clifford Dsouza


NOTICE: This message contains privileged and confidential information intended only for the use of the addressee named above. If you are not the intended recipient of this message you are hereby notified that you must not disseminate, copy or take any action in reliance on it. If you have received this message in error please notify Microscan Infocommtech Pvt. Ltd. immediately. Any views expressed in this message are those of the individual sender, except where the sender has the authority to issue and specifically states them. Tel - 022-66870600 Fax - 022-66870800
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.powerdns.com/pipermail/pdns-users/attachments/20230213/b72bf5fa/attachment.htm>

More information about the Pdns-users mailing list