# How do I block ads on YouTube?

**URL:** <https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253>\
**Category:** Help\
**Tags:** blacklisting\
**Created:** [October 19, 2016, 12:09am UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253 "2016-10-19T00:09:23Z")\
**Posts on this page:** 20\
**Page:** 6

<div class="post-metadata">

**Author:** ![Jeroen1](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Jeroen1](https://discourse.pi-hole.net/u/Jeroen1)\
**Post date:** [February 6, 2018, 3:11pm UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/112 "2018-02-06T15:11:04Z")

</div>

Hi,

Any option to share the end txt file for none bash capable users?....So we can add it to the lists on the config page.

Or add this feature into pihole with on/off toggle....lets go a step further.  
Lets combine forces and upload all individual found lists. Combine and reshare?

---

<div class="post-metadata">

**Author:** ![SiliconTraveller](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/s/a9a28c/32.png) [@SiliconTraveller](https://discourse.pi-hole.net/u/SiliconTraveller)\
**Post date:** [February 6, 2018, 3:21pm UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/113 "2018-02-06T15:21:39Z")

</div>

> [@Jeroen1](#):
>
> Lets combine forces and upload all individual found lists. Combine and reshare?

yes... i think this is a nice idea.  
unsure how to collect all the different submissions, i do this with 3 friends of mine through rsync  
anyone have any suggestions on how to combine or at least host the different files ( i can combine via scripts )

you are welcome to use the ones i use -  
[http://buffalo.biodome.org/m/youtube-ads-list.txt](http://buffalo.biodome.org/m/youtube-ads-list.txt)  
and  
[http://buffalo.biodome.org/m/youtube-hosts-list.txt](http://buffalo.biodome.org/m/youtube-hosts-list.txt) (hosts file format)

updated every 10 mins.... but like i mentioned before, currently there is an issue with the dnsdumpster.com website, it craps out on googlevideo.com - so files are very small/empty.

---

<div class="post-metadata">

**Author:** ![Jeroen1](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Jeroen1](https://discourse.pi-hole.net/u/Jeroen1)\
**Post date:** [February 6, 2018, 3:34pm UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/114 "2018-02-06T15:34:13Z")

</div>

We (you:)) could create/change the/a script that copies/renames the local files to something with a random name and upload every 24 hours..? Combing =\> pihole -g  
Good question: where to upload...making something open will result in chaos or abuse.

---

<div class="post-metadata">

**Author:** ![taxick](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/taxick/32/2660_2.png) [@taxick](https://discourse.pi-hole.net/u/taxick)\
**Post date:** [February 6, 2018, 3:55pm UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/115 "2018-02-06T15:55:30Z")

</div>

Hi.

Thanks for the files..

Are this the error you get???

> root@Pi-Hole-Server:/etc/pihole# ./youtube-ads.sh  
> Unexpected status code from [https://dnsdumpster.com/:](https://dnsdumpster.com/:) 500  
> Traceback (most recent call last):  
> File "/etc/dnsdumpster/dnsdumpster/ADS\_youtube.py", line 10, in   
> print(res['domain'])  
> TypeError: list indices must be integers, not str  
> grep: /var/log/pihole.log.1: No such file or directory  
> root@Pi-Hole-Server:/etc/pihole#

---

<div class="post-metadata">

**Author:** ![SiliconTraveller](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/s/a9a28c/32.png) [@SiliconTraveller](https://discourse.pi-hole.net/u/SiliconTraveller)\
**Post date:** [February 6, 2018, 4:00pm UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/116 "2018-02-06T16:00:20Z")

</div>

@taxick - yes - exactly  
if you go to the [http://dnsdumpster.com](http://dnsdumpster.com) website and try to look at googlevideo.com that's the error code you will get (500)

edit : i modified the youtube ads script slightly to look at /var/log/pihole.log.1 and pihole.log.2.gz (running 2 days worth of youtube queries) - get a bit more in the resulting file, unsure that they change this daily...  
but it seems to be working a little better for me.

---

<div class="post-metadata">

**Author:** ![taxick](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/taxick/32/2660_2.png) [@taxick](https://discourse.pi-hole.net/u/taxick)\
**Post date:** [February 6, 2018, 4:01pm UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/117 "2018-02-06T16:01:45Z")

</div>

Ok 🙂

Hope [http://dnsdumpster.com](http://dnsdumpster.com) fix the error.

But again, thanks for the files.

---

<div class="post-metadata">

**Author:** ![taxick](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/taxick/32/2660_2.png) [@taxick](https://discourse.pi-hole.net/u/taxick)\
**Post date:** [February 6, 2018, 4:10pm UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/118 "2018-02-06T16:10:53Z")

</div>

> [@SiliconTraveller](#):
>
> e youtube ads script slightly to look at /var/log/pihole.log.1 and pihole.log.2.gz (running 2 days worth of youtube queries) - get a bit more in the resulting file, unsure that they change this daily…

OK, how can i do the same on my pi? IM really a noob.

Btw. Here is a list of youtube blocks: [https://github.com/HenningVanRaumle/pihole-ytadblock](https://github.com/HenningVanRaumle/pihole-ytadblock)

---

<div class="post-metadata">

**Author:** ![SiliconTraveller](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/s/a9a28c/32.png) [@SiliconTraveller](https://discourse.pi-hole.net/u/SiliconTraveller)\
**Post date:** [February 6, 2018, 4:15pm UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/119 "2018-02-06T16:15:13Z")

</div>

that github link is really dated, and not updated, it seems.  
since they change those domains often, i do not use it. just sayin, ymmv.

as to the other entries - i added two lines to my shell script :  
after this line ...  
grep r\*.googlevideo.com /var/log/pihole.log | awk '{print $6}'| grep -v  
^googlevideo.com|redirector.googlevideo.com' | sort -nr | uniq \>\> /var/www/html/youtube-ads-list.txt

added these two :  
grep r\*.googlevideo.com /var/log/pihole.log.1 | awk '{print $6}'| grep -v '^googlevideo.com|redirector.googlevideo.com' | sort -nr | uniq \>\> /var/www/html/youtube-ads-list.txt  
zgrep r\*.googlevideo.com /var/log/pihole.log.2.gz | awk '{print $6}'| grep -v '^googlevideo.com|redirector.googlevideo.com' | sort -nr | uniq \>\> /var/www/html/youtube-ads-list.txt

---

<div class="post-metadata">

**Author:** ![taxick](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/taxick/32/2660_2.png) [@taxick](https://discourse.pi-hole.net/u/taxick)\
**Post date:** [February 6, 2018, 4:33pm UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/120 "2018-02-06T16:33:18Z")

</div>

Thx for your reply.

Yes, I can see the list i posted is over 10 months old.

Removed the list again!

---

<div class="post-metadata">

**Author:** ![darky](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/d/f14d63/32.png) [@darky](https://discourse.pi-hole.net/u/darky)\
**Post date:** [February 14, 2018, 8:33pm UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/121 "2018-02-14T20:33:32Z")

</div>

Any solution here?

---

<div class="post-metadata">

**Author:** ![ch32](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/ch32/32/2827_2.png) [@ch32](https://discourse.pi-hole.net/u/ch32)\
**Post date:** [February 18, 2018, 10:22am UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/122 "2018-02-18T10:22:34Z")

</div>

I've found a solution using [DNS Lookup - Online Tool | HackerTarget.com](https://hackertarget.com/dns-lookup/)

Luckily the site has an API to which makes downloading a list of DNS records simple using something like curl. The API is designed to be used in an ad-hoc fashion not for bulk queries and is limited to 100 (total) requests from a single IP Address per day.

Quick word of warning, I'm using this script on a pfSense server that's using pfblocker for ad domain blocking. Whilst the script uses standard FreeBSD/Linux type commands, the paths to those commands maybe different when run on a pi-hole.

Enough preamble, here's the script:

> ```
> echo "" > /root/youtube/youtube-domains.txt
> echo "" > /root/youtube/youtube-filtered.txt
> echo "" > /root/youtube/youtube-ads.txt
> /usr/local/bin/curl "https://api.hackertarget.com/hostsearch/?q=googlevideo.com" > 
> /root/youtube/youtube-domains.txt
> cat /root/youtube/youtube-domains.txt | cut -d, -f1 > /root/youtube/youtube-filtered.txt
> /usr/bin/sed '1d' /root/youtube/youtube-filtered.txt > /root/youtube/youtube-ads.txt 
> 
> ```

Lines 1 - 3 clear down text files, as per previous scripts above  
Line 4 downloads the DNS records from api.hackertarget.com in comma separated variables format: domain,IP address  
Line 5 removes the second entry per line (the IP address)  
Line 6 removes the top entry from the resulting file. This just has the text "googlevideo.com" in it

Done!

As I say, works for me under pfSense with pfblocker, so should work under pi-hole with minor modification

---

<div class="post-metadata">

**Author:** ![fafa](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/f/8e7dd6/32.png) [@fafa](https://discourse.pi-hole.net/u/fafa)\
**Post date:** [February 24, 2018, 7:38am UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/123 "2018-02-24T07:38:10Z")

</div>

wow !  
Works perfectly on my R-pi3 😀

Thank you.

---

<div class="post-metadata">

**Author:** ![WaLLy3K](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/wally3k/32/649_2.png) [@WaLLy3K](https://discourse.pi-hole.net/u/WaLLy3K)\
**Post date:** [February 24, 2018, 7:54am UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/124 "2018-02-24T07:54:01Z")

</div>

Your script could be be condensed a little bit, assuming all these `googlevideo.com` domains are in fact ad domains (ergo: I haven't tested this! 😆) :

```auto
curl -s "https://api.hackertarget.com/hostsearch/?q=googlevideo.com" | awk -F, 'NR>1 {print $1}' | sudo tee /var/www/html/youtube-ads.txt

```

This creates a blacklist you can use at `http://pi.hole/youtube-ads.txt` 🙂

---

<div class="post-metadata">

**Author:** ![taxick](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/taxick/32/2660_2.png) [@taxick](https://discourse.pi-hole.net/u/taxick)\
**Post date:** [February 24, 2018, 9:21am UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/125 "2018-02-24T09:21:23Z")

</div>

Can you make a step by step guide, to get it to work? I´m a big noob in Linux..

I want the script to run ones time a day and auto-update the youtube-ads.txt

Can i just make a youtube.sh file

and enter

```
#!/bin/bash
curl -s "https://api.hackertarget.com/hostsearch/?q=googlevideo.com" | awk -F, 'NR>1 {print $1}' | sudo tee /var/www/html/youtube-ads.txt
#Update Pihole Gravity
pihole -g
echo Update Done

```

Add this the to the block list: [http://pi.hole.ip/youtube-ads.txt](http://pi.hole.ip/youtube-ads.txt)

and then make cronjob that runs any night

---

<div class="post-metadata">

**Author:** ![WaLLy3K](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/wally3k/32/649_2.png) [@WaLLy3K](https://discourse.pi-hole.net/u/WaLLy3K)\
**Post date:** [February 24, 2018, 11:45pm UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/126 "2018-02-24T23:45:04Z")

</div>

As long as you added `http://pi.hole/youtube-ads.txt` to your block list, then yeah your steps would work. However, I have extreme doubts about the domains being provided being _ad-serving_ domains - therefore, you could be **very likely** blocking access to legitimate content.

The only way I know to verify an ad-serving content server is by coming across it yourself and verifying the host via YT's "Stats for nerds" panel.

---

<div class="post-metadata">

**Author:** ![taxick](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/taxick/32/2660_2.png) [@taxick](https://discourse.pi-hole.net/u/taxick)\
**Post date:** [February 26, 2018, 10:31am UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/127 "2018-02-26T10:31:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![last\_ship](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/l/85f322/32.png) [@last\_ship](https://discourse.pi-hole.net/u/last_ship)\
**Post date:** [March 2, 2018, 2:33am UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/128 "2018-03-02T02:33:07Z")

</div>

[http://pi.hole/youtube-ads.txt](http://pi.hole/youtube-ads.txt) is no long accessible, or it's down. Any workaround?

---

<div class="post-metadata">

**Author:** ![Chris\_Palmer](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/c/e47774/32.png) [@Chris\_Palmer](https://discourse.pi-hole.net/u/Chris_Palmer)\
**Post date:** [March 2, 2018, 8:29am UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/129 "2018-03-02T08:29:27Z")

</div>

> [@WaLLy3K](#):
>
> [http://pi.hole/youtube-ads.txt](http://pi.hole/youtube-ads.txt)

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

---

<div class="post-metadata">

**Author:** ![Comodore125](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/comodore125/32/2800_2.png) [@Comodore125](https://discourse.pi-hole.net/u/Comodore125)\
**Post date:** [March 2, 2018, 2:05pm UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/130 "2018-03-02T14:05:11Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![last\_ship](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/l/85f322/32.png) [@last\_ship](https://discourse.pi-hole.net/u/last_ship)\
**Post date:** [March 3, 2018, 1:16am UTC](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253/132 "2018-03-03T01:16:31Z")

</div>

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

[Previous page](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253.md?page=5)

[Next page](https://discourse.pi-hole.net/t/how-do-i-block-ads-on-youtube/253.md?page=7)
