How do I block ads on YouTube?

I've found a solution using DNS Lookup - Online Tool | HackerTarget.com

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

1 Like