Install pi-hole docker on synology to remove ads

这里介绍一下怎么在群晖上安装pi-hole docker屏蔽广告。

在synology的dsm的docker里面。

  1. 1 首先到docker search “pihole” -> 下載 “pihole/pihole” -> “latest”
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

可接外部連結箭咀查看Docker hub上詳細說明, 及參考安裝參數

Image for post
Image for post

1.2 到映像檔中 -》選擇剛下載的 pihole/pihole -》佈署

Image for post
Image for post
Image for post
Image for post

1.3 從參數中,我們見到有 -v 的要求,按要求開兩個folder俾佢用

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

1.4 佢本身要求 -p 80:80 同 p 53:53/tcp -p 53:53/udp,但在DSM中我地俾唔到80佢,所以只可縛定 53: (53是DNS用的port)

Image for post
Image for post
Image for post
Image for post

1.5 從參數中,我們見到有 -e 的要求

Image for post
Image for post
Image for post
Image for post

1.5.1 我們只用其中 recommended 的那些:
-e ServerIP=<Host’s IP> (DMS IP)
-e TZ=<Timezone> (Asia/Hong_Kong)
-e WEBPASSWORD=<Admin password> (設定密碼)
-e IPv6=<True\False> (設成false完全禁止IPv6)

Image for post
Image for post
Image for post
Image for post

1.6 設定完成後套用:

Image for post
Image for post

1.7 點詳細資訊可看到本機連接口是多少。(ie. 32772)

Image for post
Image for post

2.0 我們可以到 http://<dsm ip>:<本機連接口(port)>/admin,登入pihole
eg. http://192.168.1.202:32772/admin

if use http://192.168.1.202:32772, you will see:

[ERROR]: Unable to parse results from queryads.php: Unhandled error message (Invalid domain!)

Image for post
Image for post

password是之前set的 WEBPASSWORD (step 1.2.1)

但是过滤youtube广告似乎并不理想。

ssh到synology,然后

sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
77xxxx6480 pihole/pihole:latest “/s6-init” 33 minutes ago Up 51 seconds (healthy) pihole-pihole1
sudo docker exec -it 77bxxxx6480 /bin/bash

就进入到docker container了。

container里面其实是个debian,run

apt-get update 更新一下。然后

更新一下,然后

apt-get install vim
vim /etc/pihole/youtube-adblock-install.sh

贴入如下代码:

echo "created for public use and use."
echo "Start with re-install cleanup."
rm -r /etc/dnsdumpster
rm /var/www/html/youtube-ads-list.txt
rm /etc/pihole/youtube-ads.sh
echo "cleanup done."
echo "installing python-pip and dnsdumpster."
apt-get install python-pip
pip install --upgrade pip
pip uninstall dnsdumpster
mkdir /etc/dnsdumpster
echo "" > /etc/dnsdumpster/youtube-domains.txt
echo "" > /etc/dnsdumpster/youtube-filtered.txt
echo "" > /etc/dnsdumpster/youtube-ads.txt
cd /etc/dnsdumpster
pip install https://github.com/PaulSec/API-dnsdumpster.com/archive/master.zip --target /etc/dnsdumpster/
pip install https://github.com/PaulSec/API-dnsdumpster.com/archive/master.zip --user
echo "copying dnsdumpster API_example.py script and modify it as ADS_youtube.py."
echo "replacing API_example.py domain 'tsebo.com' with 'googlevideo.com'."
sed 's/tsebo.com/googlevideo.com/g' /etc/dnsdumpster/dnsdumpster/API_example.py > /etc/dnsdumpster/dnsdumpster/ADS_youtube-temp.py
echo "remove some script lines from script to resolve XLS base64 errors as it is not required"
awk 'NR!~/^(35|36|37|38)$/' /etc/dnsdumpster/dnsdumpster/ADS_youtube-temp.py > /etc/dnsdumpster/dnsdumpster/ADS_youtube.py
echo "ADS_youtube.py script created."
echo "cleanup temp script file."
rm /etc/dnsdumpster/dnsdumpster/ADS_youtube-temp.py
echo "create update script /etc/pihole/youtube-ads.sh."
echo "youtube-ads.sh is used for maintaining youtube generated list youtube-ads-list.txt in pihole webroot for pihole update access."
echo "echo off" >> /etc/pihole/youtube-ads.sh
echo "rm /etc/dnsdumpster/youtube-domains.txt" >> /etc/pihole/youtube-ads.sh
echo "rm /etc/dnsdumpster/youtube-filtered.txt" >> /etc/pihole/youtube-ads.sh
echo "rm /etc/dnsdumpster/youtube-ads.txt" >> /etc/pihole/youtube-ads.sh
echo "python /etc/dnsdumpster/dnsdumpster/ADS_youtube.py > /etc/dnsdumpster/youtube-domains.txt" >> /etc/pihole/youtube-ads.sh
echo "grep ^r /etc/dnsdumpster/youtube-domains.txt >> /etc/dnsdumpster/youtube-filtered.txt" >> /etc/pihole/youtube-ads.sh
echo "sed 's/\s.*$//' /etc/dnsdumpster/youtube-filtered.txt >> /etc/dnsdumpster/youtube-ads.txt" >> /etc/pihole/youtube-ads.sh
echo "cat /etc/dnsdumpster/youtube-ads.txt > /var/www/html/youtube-ads-list.txt" >> /etc/pihole/youtube-ads.sh
echo "#greps the log for youtube ads and appends to /var/www/html/youtube-ads-list.txt" >> /etc/pihole/youtube-ads.sh
echo "grep r*.googlevideo.com /var/log/pihole.log | awk '{print $6}'| grep -v '^googlevideo.com\|redirector' | sort -nr | uniq >> /var/www/html/yo
utube-ads-list.txt" >> /etc/pihole/youtube-ads.sh
echo "#removes duplicate lines from /var/www/html/youtube-ads-list.txt" >> /etc/pihole/youtube-ads.sh
echo "perl -i -ne 'print if ! $x{$_}++' /var/www/html/youtube-ads-list.txt" >> /etc/pihole/youtube-ads.sh
echo "#updates pihole blacklist/whitelist" >> /etc/pihole/youtube-ads.sh
echo "pihole -g" >> /etc/pihole/youtube-ads.sh
echo "youtube-ads.sh script created."
echo "chmod script to executable."
chmod +x /etc/pihole/youtube-ads.sh
echo "add youtube-ads.sh maintained list youtube-ads-list.txt from local webroot: http://localhost/youtube-ads-list.txt to pihole lists."
echo "http://localhost/youtube-ads-list.txt" >> /etc/pihole/adlists.list
echo "save current crontab to mycron.sav, add crontab job, to run youtube-ads.sh updater every 15 minutes."
crontab -l > mycron.sav
echo "*/15 * * * * /etc/pihole/youtube-ads.sh" > mycron
crontab mycron
rm mycron
echo "manual update first."
/etc/pihole/youtube-ads.sh
echo "done, now enjoy youtube ad free, thru your pihole."

然后run这个script就好了。

chmod +x /etc/pihole/youtube-adblock-install.sh
/etc/pihole/youtube-adblock-install.sh
https://raw.githubusercontent.com/HenningVanRaumle/pihole-ytadblock/master/ytadblock.txt
https://raw.githubusercontent.com/anudeepND/youtubeadsblacklist/master/domainlist.txt
https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/annoyances.txt
https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badware.txt
https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/experimental.txt
https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters.txt
https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/privacy.txt
https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/resource-abuse.txt
https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/resources.txt
https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/unbreak.txt

(^r[[:digit:]]+(\.|\-+)[[:alnum:]]+\-+[[:alnum:]]+\-+[[:alnum:]]+\.)(googlevideo|gvt1)\.com$

Reference:

Written by

自由撰稿人,时评人,平等公义追求者

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store