There are a couple of products for this already: &quot;AdTrap&quot; and for the Raspberry Pi &quot;pihole&quot;. (Content warning on <a href="https:&#x2F;&#x2F;pi-hole.net&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pi-hole.net&#x2F;</a> : contains piping curl into bash, slow-loading SPA site)