概要
piholeとunboundを使用した広告とSNS系の通信を遮断する方法
unboundを利用することで一度アクセスしたドメインへのアクセスが以上に早くなる(と思ってる)
簡易手順
- サーバー用意と初期設定
- piholeインストール
- unboundインストール
- piholeの設定
- 接続
サーバー用意と初期設定
proxmox上のコンテナに作成したが他のOSでも可
おすすめは「Ubuntu」「Debian」だとバージョンによっては追加の設定が必要
XXX@pihole2025feb:~$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.5 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.5 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
スペックなど
項目 | 値 |
---|---|
メモリ | 1024Mib |
swap | 512Mib |
CPU | 1コア |
HDD | 8Gib |
DNS | 設定なし(proxmoxの場合) |
作成できたら初期設定
サーバー立てる時にいつも使用しているコマンド↓
※バージョンアップとcurlコマンドのインストールは必須
※日本語の設定はやっといたほうがいいかな
sudo apt update && sudo apt upgrade -y
sudo apt install -y build-essential git curl wget unzip screen vim
sudo timedatectl set-timezone Asia/Tokyo
sudo apt autoremove -y
sudo apt clean
# 日本語表記確認
# 現在のロケール確認
locale
# 必要なロケールパッケージのインストール
sudo apt install -y language-pack-ja
# 日本語ロケールの生成
sudo locale-gen ja_JP.UTF-8
# システムのデフォルトロケールを設定
sudo update-locale LANG=ja_JP.UTF-8 LANGUAGE="ja_JP:ja"
ユーザーが必要なら↓
sudo adduser XXX
sudo usermod -aG sudo XXX
# 再起動した方が良い
再起動
接続してpiholeのインストールとwebコンソールへのログイン確認
curl -sSL https://install.pi-hole.net | bash
コマンド上に出てきた画面でいくつか項目がでてくるけど全部OKか、YesかContinueにした。
DNSに関しても今回はunbound使うけど後で変更するので初期のGoogleに
処理が完了するとここにアクセスしろってでてくるので
ブラウザでhttp://%サーバーのIP%/admin
にアクセス
この時にパスワードが求められたらコンソールに表示されているパスワードを入力
※記事作成時はいらなかった(なぜかw)
もしパスワードを忘れた場合など変更したかったら以下のコマンド
sudo pihole -a -p
接続できたらpiholeはこの時点で使える
unboundが要らなければDNSの設定して使用できる
unboundのインストール
sudo apt install unbound
Ubuntu以外のOSに関しては自分で調べてほしいがAIによると以下
# ======= Raspberry Pi OS / Armbian OS / Debian / Ubuntu の場合 =======
# APTパッケージマネージャを使用してUnboundをインストール
sudo apt update
sudo apt install unbound
# ======= Fedora の場合 =======
# DNFパッケージマネージャを使用してUnboundをインストール
# sudo dnf install unbound
# ======= CentOS Stream の場合 =======
# EPELリポジトリを追加してからUnboundをインストール
# sudo dnf install epel-release
# sudo dnf install unbound
そっかもうyumはつかえないのか
この時、自動でサービスが立ち上がってfaild
の文字が見えるが一旦無視
sudo vim /etc/unbound/unbound.conf.d/pi-hole.conf
以下の設定をコピー
server:
# If no logfile is specified, syslog is used
# logfile: "/var/log/unbound/unbound.log"
verbosity: 0
interface: 127.0.0.1
port: 5335
do-ip4: yes
do-udp: yes
do-tcp: yes
# May be set to no if you don't have IPv6 connectivity
do-ip6: yes
# You want to leave this to no unless you have *native* IPv6. With 6to4 and
# Terredo tunnels your web browser should favor IPv4 for the same reasons
prefer-ip6: no
# Use this only when you downloaded the list of primary root servers!
# If you use the default dns-root-data package, unbound will find it automatically
#root-hints: "/var/lib/unbound/root.hints"
# Trust glue only if it is within the server's authority
harden-glue: yes
# Require DNSSEC data for trust-anchored zones, if such data is absent, the zone becomes BOGUS
harden-dnssec-stripped: yes
# Don't use Capitalization randomization as it known to cause DNSSEC issues sometimes
# see https://discourse.pi-hole.net/t/unbound-stubby-or-dnscrypt-proxy/9378 for further details
use-caps-for-id: no
# Reduce EDNS reassembly buffer size.
# IP fragmentation is unreliable on the Internet today, and can cause
# transmission failures when large DNS messages are sent via UDP. Even
# when fragmentation does work, it may not be secure; it is theoretically
# possible to spoof parts of a fragmented DNS message, without easy
# detection at the receiving end. Recently, there was an excellent study
# >>> Defragmenting DNS - Determining the optimal maximum UDP response size for DNS <<<
# by Axel Koolhaas, and Tjeerd Slokker (https://indico.dns-oarc.net/event/36/contributions/776/)
# in collaboration with NLnet Labs explored DNS using real world data from the
# the RIPE Atlas probes and the researchers suggested different values for
# IPv4 and IPv6 and in different scenarios. They advise that servers should
# be configured to limit DNS messages sent over UDP to a size that will not
# trigger fragmentation on typical network links. DNS servers can switch
# from UDP to TCP when a DNS response is too big to fit in this limited
# buffer size. This value has also been suggested in DNS Flag Day 2020.
edns-buffer-size: 1232
# Perform prefetching of close to expired message cache entries
# This only applies to domains that have been frequently queried
prefetch: yes
# One thread should be sufficient, can be increased on beefy machines. In reality for most users running on small networks or on a single machine, it should be unnecessary to seek performance enhancement by increasing num-threads above 1.
num-threads: 1
# Ensure kernel buffer is large enough to not lose messages in traffic spikes
so-rcvbuf: 1m
# Ensure privacy of local IP ranges
private-address: 192.168.0.0/16
private-address: 169.254.0.0/16
private-address: 172.16.0.0/12
private-address: 10.0.0.0/8
private-address: fd00::/8
private-address: fe80::/10
上記configデータはpiholeのunboundに関するページを参照
unboundを再起動してDNSチェック
sudo service unbound restart
sudo service unbound status
dig pi-hole.net @127.0.0.1 -p 5335
digコマンドでローカルのDNSサーバー(インストールしたunboud)へpiholeのドメインの正引きをチェックしている
以下のようになっていればOk!
XXX@pihole2025feb:~$ dig pi-hole.net @127.0.0.1 -p 5335
; <<>> DiG 9.18.30-0ubuntu0.22.04.2-Ubuntu <<>> pi-hole.net @127.0.0.1 -p 5335
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3332
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;pi-hole.net. IN A
;; ANSWER SECTION:
pi-hole.net. 300 IN A 3.18.136.52
;; Query time: 352 msec
;; SERVER: 127.0.0.1#5335(127.0.0.1) (UDP)
;; WHEN: Tue Feb 25 01:17:43 JST 2025
;; MSG SIZE rcvd: 56
3.18.136.52の部分ね(まあ変わるかもだけど)
次はpiholeへ
piholeのwebコンソールにログインしてDNSを設定
右パネルの「Settings」>「DNS」
の項目でチェックをすべて外す
そして、画面下の「Custom DNS servers」に127.0.0.1#5335
を入力
そして保存!
後はパソコンやモバイル端末でDNSを自分が設定したIP
にすればOk!
私はVPNを使っているので参考にならないからネットでwindows dns 設定
とかで調べて
今回の記事作成で参考にしたyoutubeの最後にも解説があるのでそれも参照
この時点で広告ブロックはできているはず
Can You Block it ?などを使用してDNSを使っているときとそうでない時で比べてみて是非ほしい!
さてここが本題の人生を豊かにする設定
piholeのwebコンソールを開きます。
左のパネルから「Domains」をクリックして以下のドメインを一つずつブロックしていく
- youtube.com
- twitter.com
- x.com
- instagram.com
- tiktok.com
そうするとDNSを設定した端末からは上記のサイトにアクセスできなくなるよ!!
もしDNSが原因でアクセスできないサイト(よくあるのがt.co)があったら「white list」の方を選択して追加してあげて
今回は割愛したけど、piholeの設定で端末ごとに設定したり、端末をグループごとに設定したりもできる
定期的にブロックする広告のアップデートを
広告のドメインはどんどん新しいものが出てくるのでサーバーにログインして以下
pihole -up
ちなみにデフォルでブロックされている広告リスト以外もダウンロードできるけど今回は割愛
ここだけのハナシ
PCではyoutube見られるようにするけど、見終わった後の横のリコメンド(推奨動画)を消すだけでもQOLは上がると思う
それでstyle bot
っていうchromeの拡張機能を入れて以下を設定すると横を消せる
.ytd-watch-flexy[id="secondary"] {
display: none;
}
div.style-scope.ytd-rich-shelf-renderer {
display: none;
}
aside.css-175oi2r.r-1habvwh.r-eqz5dr.r-uaa2di.r-1mmae3n.r-3pj75a.r-bnwqim {
display: none;
}
参照
海外のyoutuberが解説している動画 | youtube
piholeのインストール方法 | pi-hole.net
unboundのインストール方法 | pi-hole.net