How do I block ads on YouTube?


Yes, I’ve tried it. The run command did not work proberly.

I was able to create the .sh install script, but the run command failed. I’m using Mac OS Terminal and connect to the Pi via ssh. This is, what it says:

“root@raspberrypi:~# chmod +x /etc/pihole/
root@raspberrypi:~# run /etc/pihole/
-bash: run: Kommando nicht gefunden.”

The third line means “-bash: run: Did not find command.”


Oh, that’s not how you run a shell script. Just do:


Well, but now it says:

root@raspberrypi:~# ./etc/pihole/
-bash: ./etc/pihole/ Datei oder Verzeichnis nicht gefunden

which means “file or directory not found”.

Sorry for me being such a noob :smiley:

Edit: Haha okay, just need to leave out the first dot. Then it works just fine.



I followed your instruction and the pi hole seems to block almost any youtube ads now.

Only a few ads are getting through.

I had two error messages during the installation:


The first one is no error, just a note you can safely ignore.

About the second one … what are the last lines of /etc/pihole/adlists.list ?


This is the content of the list:

GNU nano 2.7.4 Datei: /etc/pihole/adlists.list

##Zeustracker Tracking Ads



Awesome script, when I run it I get this error on the

syntax error at -e line 1, at EOF
Missing right curly or square bracket at -e line 1, at end of line
Execution of -e aborted due to compilation errors.


you need to remove the line starting with perl -i -ne 'print if

and replace it with

perl -i -ne 'print if ! $x{$_}++' /var/www/html/youtube-ads-list.txt


@Schrauber47 put a # in front of :this: entry and re-run pihole -g.


Hi and thanks for this script.
Right now I have about 150 domains in my list.


@itsme awesome, thank you for your help!


Is there a mistake in /etc/pihole/ ?
Line 10:
grep r* /var/log/pihole.log | awk '{print }'| grep -v '^\|redirector' | sort -nr | uniq >> /var/www/html/youtube-ads-list.txt
Isn’t anything missing after the awk'{print }'? Because it pastes the whole log there and not just the hostnames.
My idea was to just add the “$6” so it takes the hosts:
grep r* /var/log/pihole.log | awk '{print $6}'| grep -v '^\|redirector' | sort -nr | uniq >> /var/www/html/youtube-ads-list.txt

Thank you for the great work and the idea!

Best Regards


Since I ruined the script, Pi-hole is keeping resolving “dnsdumpster.com11” is this expected?

I don’t know why, it’s seems to be coming from the Raspberry pi himself.

I don’t understand why a such trafic and is that safe?


This is the original line from the script, but since the $ aren’t escaped, the echo command tries to evaluate them. In short, the script line should be

echo "perl -i -ne 'print if ! \$x{\$_}++' /var/www/html/youtube-ads-list.txt" >> /etc/pihole/

Likewise the reason for the missing $6 that Cheesman97 mentioned:

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/

The escapes get swallowed by the echo otherwise…


I changed the script form @Joshua_joezoef_B_ZzO a bit (/etc/pihole/youtube-ads.s):

echo "" > /etc/dnsdumpster/youtube-domains.txt
echo "" > /etc/dnsdumpster/youtube-filtered.txt
echo "" > /etc/dnsdumpster/youtube-ads.txt
python /etc/dnsdumpster/dnsdumpster/ > /etc/dnsdumpster/youtube-domains.txt
grep ^r /etc/dnsdumpster/youtube-domains.txt >> /etc/dnsdumpster/youtube-filtered.txt
sed 's/\s.*$//' /etc/dnsdumpster/youtube-filtered.txt >> /etc/dnsdumpster/youtube-ads.txt
cat /etc/dnsdumpster/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 /var/log/pihole.log.1 | 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

@idgers : On my rasbian it works without any escaping

Also make sure that the cronjob has a PATH variable:

*/15 * * * * PATH="$PATH:/usr/local/bin:/usr/bin" /etc/pihole/ >/dev/null

Something I found out:
It works on PC, but the YouTube-App on my iPhone doesn’t work anymore (doesn’t load any video).
I think the App can’t handle not avaiable ads.


Huh, I’m on raspbian also. Maybe you used single quotes? Or maybe a paste messed something up when I went though it the other day…that’s probably the most likely reason.

I found the same problem, though, where it doesn’t work for mobile devices…ended up disabling it all since I already have a browser extension that handles it on PC. Wish I had more time to dig into it.


My list ends up being empty after running the script of @Joshua_joezoef_B_ZzO.

I do get the following error:
Traceback (most recent call last):
File “/etc/dnsdumpster/dnsdumpster/”, line 35, in
print("\n\n\nRetrieved XLS hosts? {} (accessible in ‘xls_data’)".format(xls_retrieved))
NameError: name ‘xls_retrieved’ is not defined

I made the adjustments @idgers suggested:
changed the following lines:
echo “perl -i -ne ‘print if ! $x{$_}++’ /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/


seems that dnsdumpster is failing (server code 500) when is queried.
though it does appear to be working for others.

so if you folks see empty files, this is why :slight_smile:


First I will say thanks for the big work you all do

Are there any fix for line35 error


so, i remember fixing something, but unsure now what :confused:
but you are welcome to my copy of dnsdumpster folder … getting an error from dnsdumpster site (but it happens if you go to dnsdumpster and query regardless)

anyway, if you want - here is my dnsdumpster folder -