Thanks for your time and patience to come up with that simple but very effective method.
I am the sole developer of Diversion, a router ad-blocker for Asus routers running a customized Asuswrt-Merlin firmware.
I ported your script into Diversion, with fully automatic IPv4 and IPv6 forced IP setup (if IPv6 is enabled on the router). It features a reset and enable/disable function within the UI.
I am currently in beta 3 phase and plan to make this feature a permanent part of Diversion. That is, as long as Googs does not block that loophole you found.
With the recent changes coming for Pi-hole 5 will this script still work? I know there have been changes to the list files to a sql database. Would like to know if this script is not supported on Pi-hole 5 if it would get updated to support it.
I'm new to the Raspberry Pi (Pi 4 2gb) and the Pi-hole. I'm interested in this script and looking forward to Pi-hole 5 but since I think I've worked out the Google Fiber bugs with the Pi-hole I'm not sure about doing a rebuild if I'll not have to.
I'm new to this and trying to set this up. First all my YouTube videos appear to be using ipv6 in the query logs, will this only block ipv4 requests or will it also block ipv6 requests?
sudo -i
enter password
cd /usr/local/bin
nano youtube.update.sh
paste the text from script and change IP
crtl x, yes to save
than: chmod a+x youtube.update.sh
./youtube.update.sh
pihole restartdns
thats it!
I haven’t had time over the weekend to merge in IPv6 or other functionality but hope to soon.
FWIW, I have a different method that seems to work better (only the very odd per-roll slips through), but it’s based on OpenBSD and pf. So it needs a different OS and it works down at the network layer.
opened a YT video on my iPhone with the YouTube app which shows an ad in the beginning
grabbed the googlevideo string from PiHole log, ran nslookup on it and extracted the IPv4 and IPv6.
navigated to /usr/local/bin and created the youtube.update.sh with the following content:
#deleted the initial stuff to keep this post short
forceIP="172.217.132.10"
#added for ipv6
forceIP6="2a00:1450:400e:4::a"
# nothing below here should need changing
piLogs="/var/log/pihole.log"
ytHosts="/etc/hosts.youtube"
workFile=$(mktemp)
dnsmasqFile="/etc/dnsmasq.d/99-youtube.grublets.conf"
if [ ! -f $dnsmasqFile ]; then
echo "addn-hosts=$ytHosts" > $dnsmasqFile
touch $ytHosts
piLogs="$piLogs*" # preload with results from all logs
echo "Setup complete! Execute 'pihole restartdns' as root."
echo "cron the script to run every minute or so for updates."
fi
cp $ytHosts $workFile
zgrep -e "reply.*-.*\.googlevideo.*\..*\..*\..*" $piLogs \
| awk -v fIP=$forceIP '{ print fIP, $6 }' >> $workFile
#this section added for ipv6
zgrep -e "$forceIP" $workFile \
| awk -v fIP6=$forceIP6 '{ print fIP6, $2 }' >> $workFile
sort -u $workFile -o $workFile
if ! cmp $workFile $ytHosts; then
mv $workFile $ytHosts
chmod 644 $ytHosts
/usr/local/bin/pihole restartdns reload
else
rm $workFile
fi
exit
ran the script, restarted the PiHole DNS
added the script to crontab
* * * * * /usr/local/bin/youtube.update.sh 2>&1
When I now open the YT video, the ads are skipped but the video doesn't load anymore. I checked the PiHole log and saw that s.youtube.com was blocked (??) but even whitelisting that didn't fix it.