Stephen Thomas <flabdablet@fastmail.fm>
Updated 12-May-2018
This is free software. Do anything you like with it except hold me accountable for any grief it causes you.
Here's how I added adblocking to my LAN's Internet gateway (a Beaglebone Black running Debian Testing) using only coreutils, dnsmasq, wget, xinetd and a smidgen of script.
DNS-based blocking like this wouldn't stop a skilled user but advertising is a nuisance, not a prohibited resource; this is a flyscreen, not a security door.
Using single transparent pixels as placeholders for blocked content doesn't break most web page layouts, and serving them locally saves time and WAN traffic. There are several 1-pixel server projects available, but I wanted to see if I could bring one up using only the packages already installed on my gateway. Here's what I ended up with:
This builds a pseudoservice that discards requests and regurgitates the same empty point on each connection, much like the industry whose intrusions it exists to frustrate. Replace 192.168.119.254 with your own gateway's LAN IP address (edit the text box above before copying and pasting if you like).
If you're already running a proper web server on that gateway, you'll need to add an extra IP address for the pixel server and bind it to that instead.
I'm completely in love with dnsmasq. If you're running a Linux gateway and you're not using dnsmasq to deal with your LAN's DHCP and DNS requirements, I think you're doing it the hard way.
In particular, dnsmasq is perfectly suited to exactly the kind of mass DNS spoofing needed for this project: a config line of the form address=/must.go/192.168.119.254
will make any hostname ending in must.go resolve to 192.168.119.254.
As packaged by Debian, dnsmasq comes preconfigured to scan /etc/dnsmasq.d for additional config so it's not even necessary to edit the main config file.
All that's needed is a little update script that runs once per week:
Again, replace 192.168.119.254 with your own gateway's LAN IP address (perhaps by editing the text box above before copying and pasting).
Peter Lowe has my undying gratitude for maintaining the upstream list.