LoginSignup
0
1

More than 1 year has passed since last update.

[unbound] docker 使って、さくっと広告ブロックやってみた

Posted at

ずーっと気になっていたので、DNSを使った広告ブロッカーをスキマ時間でちょっと作ってみました。

実際の設定方法

ひとまず ~/unbound フォルダ内に必要な設定ファイルを突っ込んでおきます。

custom.conf

server:
        interface: 0.0.0.0
        interface: ::0
        access-control: 192.168.0.0/24 allow

forward-zone:
        name: "."
        forward-addr: 8.8.8.8
        forward-addr: 8.8.4.4

280blocker さんの広告ブロックリストを利用する

280blocker

unbound.conf 内の server: 配下に local-zone: を記載すれば良さそうな感じです。
こちらのサイトで提供されているtextをベースにして、unbound用のconfigを生成させました。
こちらも~/unboundフォルダ内へ出力しています。

awk版

adblock-conf.sh

#!/bin/bash

OUTPUT='./unbound/static.conf'
d=`date '+%Y%m'`

echo "server:" > ${OUTPUT} && \
  curl -L https://280blocker.net/files/280blocker_domain_${d}.txt | \
  grep -e '^[a-zA-Z0-9]' | \
  awk '{ print "\tlocal-zone: \""$1".\" static"}' >> ${OUTPUT}

sedの場合

なお、grepawk部分をsedでまるっと実行したいみたいな時は、こちらです(macで確認)。
このsedだと、元の注釈部分を生かす形になります。

sed -e 's/^\([0-9a-zA-Z].*\)/\tlocal-zone: "\1." static/g'

docker で unbound サーバを立てましょう

後は、dockerで起動するだけ。カンタン。

sudo docker run -d --name unbound -p 53:53/tcp -p 53:53/udp -v ~/unbound:/etc/unbound/custom.conf.d klutchell/unbound

参考情報

AWSを使って広告をブロックするDNSサーバを構築する
unboundによるDNSブロッキング - それマグで!
klutchell/unbound

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1