<div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hey Simon,<br>
<br>
On Thu, 2021-04-01 at 23:55 +0100, Simon Kelley wrote:<br>
> I could do with a handle on exactly how people are configuring dnsmasq<br>
> to do ad blocking. It's not something I have much experience of.<br>
<br>
The situation for Pi-hole (a popular ad blocker based on dnsmasq) is the<br>
following:<br>
<br>
Traditionally, Pi-hole used "addn-hosts" to add HOSTS-like files containing<br>
domains (example: <br>
<a href="https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" rel="noreferrer" target="_blank">https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts</a>). This<br>
list contains roughly 80,000 domains. This is doable with dnsmasq on all<br>
platforms having at least 512 MB of memory. However, Pi-hole users<br>
typically want to take it to the extremes. They added more and more lists,<br>
often going beyond the one million domains mark. This became a problem<br>
regarding memory. I don't recall complains about slow replies, though.<br>
<br>
Anyway, as this became more and more an issue and since we wanted to have<br>
something more professional than a text file (so users can easily add<br>
comments, etc.), we amended the dnsmasq code with an interface to a SQLite3<br>
database holding all domains to be blocked. We also added support for<br>
regular expressions (and hereby wildcards). With this new approach, we<br>
stopped storing anything about blocked domains in dnsmasq's cache: blocked<br>
domains are short-circuited and replied to with a mock answer. They are<br>
never added to the cache. This is done because we allow different lists to<br>
be assigned to different clients so some devices using the DNS server can<br>
be limited further down while other may be fully open on the same process.<br>
<br>
This works really fast because the balanced-tree (B-tree) index on the<br>
domain is very efficient. The tree lives transparently in page cache so<br>
accessing it is very fast even in the 1 mio. range (lookup speed scales<br>
logarithmic, typically < 5 ms on Raspberry Pis for 3mio. blocked domains).<br>
<br>
Note that we are hooking into dnsmasq's code from "outside" to keep changes<br>
in the dnsmasq codebase minimal so we can straightaway apply any patches<br>
from dnsmasq's git.<br>
<br>
So even when this is a bit outside of the current discussion, I thought<br>
it'd be interesting to mention that Pi-hole used to use "addn-hosts" but<br>
stopped to do so some time ago.<br>
<br>
Best,<br>
Dominik<br><br></blockquote><div>I was indeed in pi-hole's dnsmasq changes a while go and tried to use it to replace dnsmasq(for its sqlite3, cname etc), however that turns out to be too challenging as they're really geared towards pi-holes specifically. Especially the way it forks dnsmasq. I would be great if pihole's dnsmasq changes can be used standalone(e.g. a dnsmasq variant with sqlite3/cname-nesting etc).</div><div><br></div><div>Though the performance issue I mentioned in my last reply about local/address/cname parsing remains the same, you will have to use hosts files to a quick reload when you have large blocklists.</div><div><br></div><div>Thanks,</div><div>Gordon</div></div></div>