How do I block ads on YouTube?



We were talking about YouTube specifically.

So we know that ads and videos are served from the same YouTube domains. So you can’t block based on that.

We also know that when you click a video YouTube calls the YouTube api and asks for what to show - likely an ad url and or a video url. Of course uBlock can filter on that an pi hole can’t.

What I was actually talking about was if you are in the US that YouTube api knows you are there ‘somehow’ and sends back 1 of a million YouTube ads for the US.

If on the other hand you are in some tiny obscure country it will send you 1 of maybe 100 ads available - in other words you will see a lot less ads in a small obscure country than the US.

Now the question is how does it know which country you are in? There’s a few possibilities:

  1. it checks which ip the request comes from ie your ip.

  2. when you request the dns for some domain let’s say, the dns server sends the ip of a google server setup to respond with ads AND videos for your country. Basically a regional server that handles all YouTube api requests. We still can’t block this ip as it’s needed by YouTube for everything.

I would have assumed it was 1) BUT testing out some vpn servers which show the ip as US I see Dubai ads.

This leads me to think this vpn setup may be using a Dubai dns server which incorectly sends back ips for google servers in Dubai. Ok their setup is broken but it raises the question that could 2) be how youtube serve you ads for your country?

Most public dns servers should serve you local ips based on where you are requesting from - but some probabaly don’t. Has anyone tried an alternative dns and actually got ads from a different country ever?

Someone further up said they did exactly that, I was skeptical but after the vpn test I did it may be worth a second look.

Edit: I am neither in US or Dubai so it’s got nothing to do with where I really am!


Tell us :wink:


CDN, Content Delivery Network

These server can even be located inside the nerwork of your ISP. If you use the DNS of your ISP you will stay completely inside the nerwork of your ISP.

Google will have installed a tracking system on those CDN to not miss out of userdata.

If you use VPN you will go directly to servers in the internet connection node and those can be area, country or several countries.

VPN let you appear as you surfing from a different location but the DNS is inside the network of you VPN provider.

You can get in trouble if you use DNS of your ISP then it could point to a CDN that is not reachable through the VPN you are using.

So the source address is the best indication where are and ofcourse Alphabet and other tracking firms have tools installed on you mobile devices to track you always and everywhere.


This particular vpn uses its own dns. The ips it returns can’t be reached outside of the vpn network whereas all other YouTube addresses seem to be reachable from anywhere in the world.

It’s likely Dubai have special youtube nodes to comply with local policy, but that wasn’t really my point.

What this means is that an IP address in the US (the vpn end point) was able to be served ads from Dubai because of the dns resolution. So in that case we could redirect some host (which one?) to a tiny countries youtube node to reduce the ads significantly.

Anyway it needs more investigation. It’s also possible that the app itself is connecting to a site or non http/s protocol somewhere to get its external up like STUN does.


I don’t think that this will fly in the end.

You are using DNS nodes that havesome kind of repression forced on them. Lets say we are going to usea DNS on a small country or island that is free. It will serve general general DNS information because it will not a CDN infrastructure/datacenters.

The Y-o-u-t-u-b-e behaviour is not a problem on my PC or Android devices because software filters out that stuff.

If you want to outsmart them you have find a domain rewrite program that sits in front of Pi-hole