How do I block ads on YouTube?


I noticed the same thing using as a wildcard. You can load a video and then watch the query log and it will load 5-6 variations of before it quits loading entirely. Some of those variations are the video, some are the advertisement. If you right click on the ad when it loads in Firefox and copy the debug info to notepad you can see which domain is the ad by scrolling down to ad_lvh (or is it ad_lbh?) near the bottom.

I am still getting youtube video ads on my videos using the default settings but all the other site ads are gone so im not sure what you are doing differently than me to get rid of them. At this point I’ve reached the limit of what I can accomplish with my current abilities so i’ve kinda given up for now.

Really hope we can figure out a way to bypass these ads, good luck!


have you tryed to load the video with disabled javascript?
your regex is correct i ve tested it with

# "r\d+\W+sn\-.*\.googlevideo\.com" 

The video ads on Youtube are no longer being blocked for me even though I am using the list that was linked to earlier.


I would look at how Kodi does it.

I haven’t ever seen a single ad when watching a youtube video via the YT plugin in Kodi.
so there has to be a way that it can source just the video and not play the ads. Either that or the overlays are blocked by kodi somehow? But I’m watching kodi on an android box connected to my TV and it should be able to play adverts just the same way that my mobile phone can… but it doesn’t… it strips them out completely. I wonder how they do it ?


The Kodi youtube plugin is simply coded in such a way as to not show ads. Pi-hole cannot reprogram your youtube player or the website itself, so it can’t work in the same way that Kodi does it.


I’m using YouTube adway apk. No ads whatsoever. You can download it on apk is clean. All credit goes to the respective developer.

1 Like

So how I remove YouTube ads?


So how I remove YouTube ads on PC and tablets …?


pihole removes most of the youtube ads but not all. If you combine uBlock with pihole you can get rid off all ads. Another way is to use a firewall like pfSense with e.g. pfBlockerNG. You can pick the one which matches your needs best :wink:


Yes, I know that.
Thought without using AdBlock and uBlock software.

Recipe on youtube i think at the beginning of the video. You know what I mean?


No it doesn’t, as I have tested videos are delivered using blocking these will prevent videos from loading. Also these are region specific (in my case India). Also ad domains have some sort of commonality, for example I get ads from and from 6 other domains, so I blacklisted from r1 to r20 for each domain. I haven’t seen any ads from a couple of days.


Mod Edit: Removed link to site that has AUP’s and Terms that are not compatible with the Pi-hole. Please do not link to sites that are bulk downloaders or circumvent the Acceptable Use of a service.


I know what you mean - until now I was not able to block the ads at the beginning of the video only with pihole :disappointed:


How can I use these commands? Or how can I actually implement them, I have no idea how to use it. And ADS are everywhere in YouTube.


I use that too works great whit youtube ads :smile:


Hi guys! Is there any additional software I can install on raspberry to help pihole to kill youtube ads?
Raspberry pi3 with raspbian


If you’re using Android take a look at this thread on XDA, it’s a modified version of YouTube app. Works well and has some other cool features too!

1 Like

Well i combined some ideas and small improvements found on this topic into a install script

Requirements: Pi-hole Version v3.2.1 Web Interface Version v3.2.1 FTL Version.

Default scriptcode: ubuntu / debian.
You can convert the script to other platforms by simple replace the scriptcode line:

“apt-get python-pip install”

Replace it with the install command required to install python pip on your distro.

create file as following:

  • sudo -i (and login)

  • nano /etc/pihole/

  • paste the scriptcode below:

  • exit nano with ctrl+x and save the install script

  • chmod +x /etc/pihole/

  • run /etc/pihole/


echo "created for public use and use."
echo "Start with re-install cleanup."
rm -r /etc/dnsdumpster
rm /var/www/html/youtube-ads-list.txt
rm /etc/pihole/
echo "cleanup done."
echo "installing python-pip and dnsdumpster."
apt-get install python-pip
pip install --upgrade pip
pip uninstall dnsdumpster
mkdir /etc/dnsdumpster
echo "" > /etc/dnsdumpster/youtube-domains.txt
echo "" > /etc/dnsdumpster/youtube-filtered.txt
echo "" > /etc/dnsdumpster/youtube-ads.txt
cd /etc/dnsdumpster
pip install --target /etc/dnsdumpster/
pip install --user
echo "copying dnsdumpster script and modify it as"
echo "replacing domain '' with ''."
sed 's/' /etc/dnsdumpster/dnsdumpster/ > /etc/dnsdumpster/dnsdumpster/
echo "remove some script lines from script to resolve XLS base64 errors as it is not required"
awk 'NR!~/^(35|36|37|38)$/' /etc/dnsdumpster/dnsdumpster/ > /etc/dnsdumpster/dnsdumpster/
echo " script created."
echo "cleanup temp script file."
rm /etc/dnsdumpster/dnsdumpster/
echo "create update script /etc/pihole/"
echo " is used for maintaining youtube generated list youtube-ads-list.txt in pihole webroot for pihole update access."
echo "echo off" >> /etc/pihole/
echo "rm /etc/dnsdumpster/youtube-domains.txt" >> /etc/pihole/
echo "rm /etc/dnsdumpster/youtube-filtered.txt" >> /etc/pihole/
echo "rm /etc/dnsdumpster/youtube-ads.txt" >> /etc/pihole/
echo "python /etc/dnsdumpster/dnsdumpster/ > /etc/dnsdumpster/youtube-domains.txt" >> /etc/pihole/
echo "grep ^r /etc/dnsdumpster/youtube-domains.txt >> /etc/dnsdumpster/youtube-filtered.txt" >> /etc/pihole/
echo "sed 's/\s.*$//' /etc/dnsdumpster/youtube-filtered.txt >> /etc/dnsdumpster/youtube-ads.txt" >> /etc/pihole/
echo "cat /etc/dnsdumpster/youtube-ads.txt > /var/www/html/youtube-ads-list.txt" >> /etc/pihole/
echo "#greps the log for youtube ads and appends to /var/www/html/youtube-ads-list.txt" >> /etc/pihole/
echo "grep r* /var/log/pihole.log | awk '{print $6}'| grep -v '^\|redirector' | sort -nr | uniq >> /var/www/html/youtube-ads-list.txt" >> /etc/pihole/
echo "#removes duplicate lines from /var/www/html/youtube-ads-list.txt" >> /etc/pihole/
echo "perl -i -ne 'print if ! $x{$_}++' /var/www/html/youtube-ads-list.txt" >> /etc/pihole/
echo "#updates pihole blacklist/whitelist" >> /etc/pihole/
echo "pihole -g" >> /etc/pihole/
echo " script created."
echo "chmod script to executable."
chmod +x /etc/pihole/
echo "add maintained list youtube-ads-list.txt from local webroot: http://localhost/youtube-ads-list.txt to pihole lists."
echo "http://localhost/youtube-ads-list.txt" >> /etc/pihole/adlists.list
echo "save current crontab to mycron.sav, add crontab job, to run updater every 15 minutes."
crontab -l > mycron.sav
echo "*/15 * * * * /etc/pihole/" > mycron
crontab mycron
rm mycron
echo "manual update first."
echo "done, now enjoy youtube ad free, thru your pihole."

Test or View generated youtube ads list in your webbrowser:

http://< pihole weburl >/youtube-ads-list.txt

Here you go: :popcorn::popcorn::popcorn:

use it free,it works for me :slight_smile:

YouTube Werbespots in App


Awesome work man. Can you please make it work on rasbian, too?


Have you tried it? If so, which command fails? Although I haven’t tried it there seems to be nothing that’s obvious why it shouldn’t just work on Raspbian.