How do I block ads on YouTube?



Thanks for you reply!

Ok, I think I will use a plugin for chrome to block youtube add, and don´t use the pihole for that


http://pi.hole/youtube-ads.txt is no long accessible, or it’s down. Any workaround?


Friend, that is a url that goes directly to your pi hole. If that doesn’t load that means you don’t have the file in your html /var/www/html/.. directory


I have made that running every minute. Still some adds propagated through.

UBlock fixes it.
Youtube is something that requires application level filtering.


indeed, i’m just an idiot and wasn’t paying attention. thanks

YouTube plays ads on my nVidia Shield, like Pi-Hole never existed

Well with the hackertarget api there is no need for dnsdumpster so temp files will be saved in pihole dir from now:

uninstall dnsdumpster, python python-pip, or let it as it is.

important part:
Update the /etc/pihole/ file to the following:

echo off
rm /etc/pihole/youtube-filtered.txt
rm /etc/pihole/youtube-ads.txt
curl -s “” | awk -F, ‘NR>1 {print $1}’ | sudo tee /etc/pihole/youtube-filtered.txt > /dev/null
sed 's/\s.$//’ /etc/pihole/youtube-filtered.txt >> /etc/pihole/youtube-ads.txt
cat /etc/pihole/youtube-ads.txt > /var/www/html/youtube-ads-list.txt
#greps the log for youtube ads and appends to /var/www/html/youtube-ads-list.txt
grep r /var/log/pihole.log | awk ‘{print $6}’| grep -v ‘^|redirector’ | sort -nr | uniq >> /var/www/html/youtube-ads-list.txt
#removes duplicate lines from /var/www/html/youtube-ads-list.txt
perl -i -ne ‘print if ! $x{$_}++’ /var/www/html/youtube-ads-list.txt
#updates pihole blacklist/whitelist
pihole -g

flush your logs from within the pihole admin interface.
wait or manualy run /etc/pihole/ (2x)

thanks ppl good luck


The page somehow did generate some of the
fingerprints of but didn’t have the that my phone received so all the ads just slipped through. Can you help me with this ?


had to change the collumn AWK selects to filter the “r5—” look-alike lines from the pihole log. Collumn 6 seems to feed my device ipaddresses to the youtube-ads-list.txt instead.

“grep /var/log/pihole.log | awk ‘{print $6}’| grep -v ‘^|redirector’ | sort -nr | uniq >> /var/www/html/youtube-ads-list.txt” to
"grep /var/log/pihole.log | awk ‘{print $8}’| grep -v ‘^|redirector’ | sort -nr | uniq >> /var/www/html/youtube-ads-list.txt


Based on the info in this thread I’ve put together a simple script. I don’t use the YouTube app that often, so I’m not 100% this works perfectly. It also appends the urls with the r00— pattern, which are not in the hackertarget list.

Place it somewhere convenient, add execute permissions (chmod +x and add it to your cron jobs.

I have noticed some ads still (although less than I used to). I’m not sure yet if the domains provided by hackertarget are incomplete or that I need to run my cron job more often (now it runs every 24h). I did find a longer list on Wolfram Alpha (click on subdomains) but they don’t seem to have an easy way to get those in plain text.


see my script below, it fixes those urls too :slight_smile:

curl '$APPID$&format=plaintext&podstate=WebSiteStatisticsPod:InternetData__Subdomains&podstate=WebSiteStatisticsPod:InternetData__Subdomains_More' | grep -Po "r\" >> $FILE

To get more subdomains from Wolfram, add this after line 16
Replace $APPID$ with your AppId from Wolfram


I think you missed a \ after the curl, also I used ’ insted of ’ dont know if that matters though.

curl '$APPID$&format=plaintext&podstate=WebSiteStatisticsPod:InternetData__Subdomains&podstate=WebSiteStatisticsPod:InternetData__Subdomains_More' \

| grep -Eo “r\d±–” >> $FILE


this does not send anything to the file.

(i do have a Wolfram ID for the app. The curl command does pull information)

| grep -Eo "r\" >> $FILE

copy pasting removed the 3 ‘-’ after the ‘+’


sudo curl “ 5” | sudo grep -Eo “r\d±–” >> /tmp/bla.txt

bla.txt is blank

(I do have the corrected grep command - seems to auto truncate when pasting here)


Switch grep -Eo with grep -Po … -E flag doesn’t work in raspbian for me for -P does


That did the trick. Thank you.


nice, thanks


Hi Guys,

I have Pi-hole in an Ubuntu Server. I am trying this script. I added the lines:

sudo curl ''

| sudo grep -Eo “r\d±–” >> /etc/pihole/youtube

I get this error in command line:

</queryresult> line 21: syntax error near unexpected token `|' line 21: `| sudo grep -Eo “r\d±–” >> etc/pihole/youtube
hernando@pihole:~$  syntax error near unexpected token `|'

There is a file in /etc/

It contains lines like this:

Can someone please help me.

If this means it’s working, how can I check in the Pi-hole web GUI that these are being blocked?

Thank you. I love my Pi-Hole.


Hey, I had the same problem but following Sergeant_Salz’s advice, adding a \ to the end of the first line fixed it for me.

curl ‘$APPID$&format=plaintext&podstate=WebSiteStatisticsPod:InternetData__Subdomains&podstate=WebSiteStatisticsPod:InternetData__Subdomains_More’ \

Not sure how to test if the script worked however.