Block YouTube ads at your OpenWRT router

UPDATE (2018-10-23): At some point over the past couple of months, YouTube started falling back in many cases to serving ads to TV and phone apps the same way that they serve videos, effectively bypassing all DNS-based ad blocking for YouTube apps. This probably does not work for you anymore, though I have noticed some ad breaks failing to load, so it may reduce the ad frequency even if it does not block them entirely.

I don’t have time to explain in depth how to set up OpenWRT in general. For you geeks who have already done it, here’s how you can block your smart TV and un-rooted phones and other devices from getting YouTube ads using your router!

In LuCI, go to Network – Firewall – Custom Rules and add this (change 192.168.0.1 to your router’s LAN IP address) and add this line and save/submit:

iptables -A PREROUTING -t nat -p udp --dport 53 -i br-lan -j DNAT --to 192.168.0.1:53

Add the following entries to /etc/hosts (change 192.168.0.1 to your router’s LAN IP address, or try 0.0.0.0 instead):

192.168.0.1 doubleclick.net
192.168.0.1 googleadservices.com
192.168.0.1 pagead2.googlesyndication.com
192.168.0.1 pubads.g.doubleclick.net
192.168.0.1 partnerad.l.doubleclick.net
192.168.0.1 beacons.extremereach.io
192.168.0.1 secure-us.imrworldwide.com
192.168.0.1 sb.scorecardresearch.com
192.168.0.1 secure.insightexpressai.com
192.168.0.1 googleads.g.doubleclick.net
192.168.0.1 ad.doubleclick.net
192.168.0.1 dart.l.doubleclick.net
192.168.0.1 dts.innovid.com
192.168.0.1 s0.2mdn.net
192.168.0.1 ade.googlesyndication.com

Google has a big list of ad servers so there may be more that I’ve missed, but after blocking these hosts I saw the ads stop without other problems.

2 thoughts on “Block YouTube ads at your OpenWRT router

Leave a Reply

Your email address will not be published. Required fields are marked *