How do I block ads on YouTube?


I currently use the list above and additionally blacklisted “”.

At the moment I get no advertising on Youtube and I have for me no impairment on other sides found.


In the meantime advertising has shown.
I blocked also:


Ok, a few hours after the first tests comes again more frequent advertising. I have now created a list. I will try to keep them as up-to-date as possible. Feel free to test them.


At the moment I am using the list on the top of this thread and I have noticed that not all ads are blocked.
I will try out your updated list, thank you very much @Henning.


I still get ads on my android devices and searching for * in pi-hole’s log brings up results that were still not in any of the compiled lists. It’s really a whack-a-mole situation.
I was looking up how to use regex in dnsmasq and it seems that there is a patch but it has to be compiled, which I have never done.


Yes it is and I think even with regex support we will end up in a over blocking dead end, because we can not be sure that all domains serve ads maybe some of them are vital to play the videos.


So it is. I am currently collecting my YT data to see if there are overlaps. Currently I have a domain which apparently transmits advertising and normal videos. But could also be a mistake on my part.

Here is a link to my collected data.


Can you please make a version of the advertisement server list that can be imported into Pi-hole?


A few posts further up I already wrote the link.
Just write in “/etc/pihole/adlist.list”


Here are a few more to add to your list.


Thanks for the work.



I created a new python file called


with the following code:

#!env python
# -*- coding: utf-8 -*-

from DNSDumpsterAPI import DNSDumpsterAPI

res = DNSDumpsterAPI(False).search('')

for entry in res['dns_records']['host']:
    host = "{domain}".format(**entry)

    if host != '':

and then changed Giblet’s script to:

python /etc/dnsdumpster/ > /var/www/html/youtube.txt
pihole -g

There’s no need to delete the youtube.txt file. The > causes the file to be overwritten.

If you want to create a bind compatible file change the print line to:

print('zone "' + host + '" { type master; notify no; file "/var/lib/bind/dummy-block"; };')

– I don’t use pi-hole, but I am building my own ad blocking router, using bind, and came across this thread. Thanks for the info.


Am I correct in the assumption that the scipt lists all domains?

If so, it will use little. Because you will also block the normal videos.


Yes, it will add all of them. I’m in the process of testing which domains serve video.


@Henning, thank you very much! It seems to work. :slight_smile:


I’m going to try your list. Added now.


@Henning This is fantastic thank you for your efforts. It has worked well for me


Using both dnsdumpster method from @Giblet and @Henning’s list has worked well for me the last few days. Thanks

For dnsdumpster I use cron to update the list btw:
3 * * * * { /usr/local/bin/ > /var/www/html/youtube.txt && /usr/local/bin/pihole -g; } >/dev/null 2>&1

And I added http://localhost/youtube.txt to /etc/pihole/adlists.list and added Henning’s not-block-this.txt to /etc/pihole/whitelist.txt

You cannot use file:///youtube.list in adlists.list because uses cut -d'/' -f3 to determine the filename of the list :frowning:

Previously I used a script to grep all domains from pihole logs but as stated they also contain content. In case anyone still wants it:

P.S. Some of these domains seems pretty … interesting :slight_smile:

$ whois $( host -4 -t a | awk '{ print $NF }' ) | grep '\(descr\|country\)'
descr:          Google Node Server
country:        AT
descr:          Provider Local Registry Block
descr:          next layer Telekommunikationsdienstleistungs- GmbH

$ host $( host | awk '{ print $NF }' ) domain name pointer

$ whois $( host | awk '{ print $NF }' ) | grep '\(descr\|country\)'
descr:          DELTA  Wimax  Network
country:        AZ
descr:          Delta Telecom IP Range
descr:          International Communication Operator
1 Like

Hey so I have noticed that many of the domains that google uses for their ads are very similar except for the first section. See these examples that I pulled from ads that came up on youtube:



I would block one exactly like so: “r4—” only to have the same ad show up later with this domain: “r7—”.

Seeing this pattern I decided to try using a wildcard like so: “” and it seems to have worked quite well. Currently I am only using these blacklisted wildcard domains to block youtube ads. I deactivated the adlist that was posted here just to verify and it still works quite well. I think that if this doesn’t end up causing problems with desired video content then it could be a porwerful tool to help us weed out these ads.

let me know what you guys think.


Edit: nevermind, ads still load…

Might have had a bit of a breakthrough here. check out this Reddit thread.

They have a list of domains, some of which aren’t on any adlists that I have been using.

Using this list (minus the entry cause that blocks access to the site entirely) in addition to the entries we have collected I have had a much greater success rate in blocking ads.

It seems that google has a way of detecting when a specific domain doesn’t load and then tries to load an alternate. I noticed that an ad wouldn’t load for 3-5 seconds like it does when it’s blocked, but then the ad would play anyways after that pause. looking in the Query section of the ad console i could see it trying to load different domains before it found one that went through successfully as seen here:

This needs more testing and I’m but a simple truck driver. I’m sure you guys would be able to use this info in a better way than I can.

Good luck and thanks for all the hard work!

1 Like

I think we are getting closer!


Blocking absolutely every prevented me from playing any videos on youtube (Win10 & Android). All the images and comments load, but if played the buffering circle keeps going for like a minute, followed by an error.

I compiled dnsmasq with regex patch especially to test this.


PS: With a default pi-hole setup, I only see ads in the Android YT app; no ads on desktop browsers with or without blocker-addons.