How do I block ads on YouTube?

You are matching:


And we are over the 200 posting and time for a party.

yeah ^r+.\$ didnt work, on my vizio I get the PPG ad still. (hands beer to @msatter ;-P)


Does not work for me on Youtube and regex is blocking the video’s and the advertisements.

r4— is an example.

1 Like

Anyone have a Solution yet?

Ok so i validated that the following regex are able to match the required r patterns of, however pihole doesnt seem to be blacklisting them, they are still being forwarded. can someone explain this?

here are the two regexs I made and I know they work:

(^r\d+\.+[a-z]+\-\w+\.)googlevideo\.com$ // for type pattern

(^r\d+\-+[a-z]+\-\w+\.)googlevideo\.com$ //for rXX–sn type pattern

could it be that there is something before the rXX that we are not seeing example some encoding charaters?

Sorry @pk198105 but it doesn’t work here (netherlands), i use on my laptop chrome without any browserextension but the ad video’s are not blocked at all.

Here’s what I came up with:

I am no pro at regex…
It matched the following domains:

NOTE: See the very top of this page: some things will work, some will not. You’re better off getting the fingerprints/definitions from the variations of the script(s) above and having it block the ads for you that way. Otherwise, it becomes to tedious to keep up with and is really hit-or-miss.

Best Regards,

Jayke P.

@jaykepeters, the regular video’s are with your regex command blocked, in my case anyway.
When i delete your regex it works again

I’m sorry, I forgot to mention that it breaks YouTube for me too. I am experimenting with other ways to block YouTube ads using pi-hole.

OK @jaykepeters , no problem.
To block all youtube ads with pihole is impossible, i spend may hours in all topics on these forum, i read and treid a lot of things until i ruined my pihole and start over from scratch again… haha, the only way is to add “uBlock Origin” as browser extension, anyway, that is what i use on my regular PC.
So it has no sence to block any domain, there are many thousands of them.

I auto download new vids from my sub feed on my NAS, no ads that way

1 Like

How do you manage to do that?

If I had the time, I would create a Google Chrome extension that detects video ads and submits those domains to pi-hole via the api. I don’t even know how that would work, but I could create a php script to add it to a file in the web root and then pihole will use that as an ad list and update every Sunday night or whenever that cron job is scheduled. Still working on some other projects at the moment.

That will only work if you load youtube on a PC (no blocking extension needed).

Anything that will be loaded on a mobile device (connected to the same network with Pi-hole as DNS, phone or tablet) will never load due to the way the mobile platform queries youtube.

It seems that anything loaded via mobile (youtube app or browser) has a bit check or something (some sort of validation) at video load, originating from those (seemingly) random domain names that never validates, and the video will not load.

1 Like

Using synology download station

1 Like

Hey guys,

I’ve been following all of this here, Reddit and the web pretty closely and been playing with DD-WRT IPTables to intercept all port 53 requests and redirect them to Pi-Hole / some other DNS server.

I’ve also tried several Regex expressions and it’s mostly a failure, and the videos get broken quickly and the ads keep playing anyway.

One thing I might have noticed is that, depending on the upstream DNS used, you get “more” or “less” ads. For example, if I leave my DNS from the ISP, Cloudflare or similar, I get all the crappy cookie, cleaners, etc. local ads. If I use a crazy russian DNS (I’d rather not post it here so Google spies don’t get a heads up! :slight_smile:), I mostly stop seeing ads; maybe that white YouTube logo 5 second silent thing at most, every so often. But if I leave my local DNS from the ISP, I get bombarded with ads.

Have any of you guys noticed this behavior and can confirm it? Maybe we can find an even crazier DNS that show even less ads? My silly theory is that, since ads seem to be localized, a DNS in a specific country might not have advertisers paying to show ads there; hence why I’m experiencing this behavior. Or, I’m going crazy after having wasted countless hours with this! :stuck_out_tongue:

Also, as another solution, wouldn’t it be great to have a proxy service running on a computer/server that would intercept the YouTube Chromecast calls, get the video, if it’s less than 1 minute (check by size or whatever), drop it and send the Chromecast the next video? How crazy is that?

Thanks and let me know what you think!

That last proxy solution is well beyond the scope of Pi-Hole.

I have had very good success with a basic collection of block lists (Wally3K ticked) and uBlock Origin on Mac Safari. No ads.

With the basic blocklists on another Pi-Hole, and no uBlock, I get just a few ads on IOS devices and just skip them after 5 seconds.

I logged into a European IP via VPN, turned off uBlock, and got one ad in an 8 minute YouTube video.

HI jfb,

Yes, of course the proxy solution would be a different thing running on a different server/docker/VM (UNRAID for example), but that might be something that could be developed by someone who has some free time and knowledge! :slight_smile:

And about uBlock and the other countless of blockers, they work great by themselves - they don’t even need Pi-Hole for that. The problem is when you are trying to block ads in Chromecast (or any other embedded YouTube app for that matter), you can only relay on intercepting/proxying the requests that it makes and returning something cleaner, without the ads. For every device we are more than covered (PC, Android, etc.); what we are missing sadly is those embedded apps blocking.


here are the regex that will block the random stuff google tries to throw:

this will block all other ads instream:


this will block preroll but as of writing 8 out of 10 times it will stop the video from playing as google keeps redirecting to a different site randomly which is also blocked by the regex therefore the video wont play until a response is sent of a successful connection: