0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

unbound による DNS フィルタリング

Last updated at Posted at 2022-01-21

a-records.conf にフィルタリングしたい FQDN と、それに対応する dummy の A レコードを記載する

a-records.conf
# A Record
  #local-data: "somecomputer.local. A 192.168.1.1"
  local-data: "filtered.host.com A 0.0.0.0"

# PTR Record
  #local-data-ptr: "192.168.1.1 somecomputer.local."
  local-data-ptr: "192.168.1.2 laptop.local."

unbound の docker を動かして終わり。

docker stop my-unbound && \
docker rm my-unbound && \
docker run --name my-unbound -d -p 53:53/udp -v $(pwd)/a-records.conf:/opt/unbound/etc/unbound/a-records.conf:ro --restart=always mvance/unbound:latest

ちなみに

Chrome の dev tool で、 network のところで Copy all as HAR みたいにすると、 JSON でとれる。その URL を取得するには、以下のようなかんじで jq をすれば OK

cat xxx.json | jq .[].entries[].request.url > yyy.txt

あるいは

import json
from string import Template
from urllib.parse import urlparse

# JSON file をロード
a = json.load(open('./a.json', 'r'))

# hostname だけとる
hostname_set = set()
for e in a['log']['entries']:
    url = e['request']['url']
    u = urlparse(url)
    hostname_set.add(u.hostname)

# フィルタリングしたくない hostname のリスト
excepted_hostnames = [
    'google.analytics'
]

# Generate config string.
template = Template('  local-data: "${hostname} A 0.0.0.0"')
for h in sorted(hostname_set):
    if h in excepted_hostnames:
        continue
    print(template.substitute(hostname=h))
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?