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))