Categories
Hacky Crud

Simple Script to Block YouTube Ads with Pi-hole

I was going over far too many MB of tcpdumps trying to figure out the problem of YouTube ads. It looked like just before an ad would roll, a lookup was done for a googlevideo.com hostname that would often return a different IP than the one that it had been returning earlier. What if the IP returned was one of my own choosing? Hmm…

On a hunch I wrote a quick and dirty test script that can run on a Pi-hole and it seems to be working flawlessly. Ads will show up early on but their frequency will drop to (near) zero. I’ve had YouTube running for two days straight with only a handful of ads. The last one was this morning about 13 hours ago.

Gitlab link here.

Original Reddit post here.