社内や家庭内でローカルな名前解決をする際、
ある一つのドメインの中で、
キャッシュリゾルバであるUnboundにはlocal-data
Unboundのインストール
UnboundはUbuntu
$ sudo apt-get install unbound
これだけで自動的にUnboundが動作します。ローカルホストの53番ポートをunboundがLISTENしているのを確認してみましょう
$ sudo ss -lntp | grep unbound LISTEN 0 5 127.0.0.1:8953 *:* users:(("unbound",17014,8)) LISTEN 0 5 127.0.0.1:53 *:* users:(("unbound",17014,6)) LISTEN 0 5 ::1:8953 :::* users:(("unbound",17014,7)) LISTEN 0 5 ::1:53 :::* users:(("unbound",17014,4))
resolvconfとの連携
Ubuntuではresolvconfによって/etc/
$ sudo service unbound stop $ cat /etc/resolv.conf # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 192.168.1.3 $ sudo service unbound start $ cat /etc/resolv.conf # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 127.0.0.1
/etc/
# If set, the unbound init script will provide unbound's listening
# IP addresses as nameservers to resolvconf.
RESOLVCONF=true
# If set, resolvconf nameservers will be configured as forwarders
# to be used by unbound.
RESOLVCONF_FORWARDERS=true
ここでRESOLVCONFとRESOLVCONF_
resolv.
/sbin/resolvconf -a lo.unbound
が行っています。この直前の条件分岐を見るとわかりますが、
Unboundの設定
このように、
# The following line includes additional configuration files from the
# /etc/unbound/unbound.conf.d directory.
include: "/etc/unbound/unbound.conf.d/*.conf"
このことからもわかるように、
server:
interface: 0.0.0.0
access-control: 127.0.0.1/32 allow
access-control: 172.16.0.0/16 allow
家庭内サーバーのDNSレコードも、
server:
local-data: "hoge.example.com. IN A 172.16.0.1"
local-data: "fuga.example.com. IN A 172.16.0.2"
local-data: "foo.example.com. IN A 172.16.0.3"
local-data: "bar.example.com. IN A 172.16.0.4"
(……略……)
/usr/
$ sudo service unbound restart
LAN内の別のPCから、
$ dig hoge.example.com @(UnboundサーバーのIPアドレス) +norec (……略……) ;; ANSWER SECTION: hoge.example.com. 3600 IN A 172.16.0.1 (……略……)
ログの設定
サービスのログは設定の確認やトラブル時の問題解決に役立つのはもちろんのこと、
use-syslog: yes
log-queries: yes
Unboundがsyslogに出力するログファシリティはdaemonです。Ubuntuのデフォルト設定では、
daemon.* -/var/log/daemon.log
$ sudo service rsyslog restart
クエリーログはかなりの量になることが予想されるうえ、
(……略……)
/var/log/daemon.log
/var/log/kern.log
/var/log/auth.log
(……略……)
{
rotate 4
weekly
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
reload rsyslog >/dev/null 2>&1 || true
endscript
}
上記の部分から/var/
/var/log/daemon.log
{
rotate 180
daily
missingok
notifempty
delaycompress
compress
postrotate
reload rsyslog >/dev/null 2>&1 || true
endscript
}
unbound-controlを使う
unbound-controlは、
unbound-controlとUnboundが通信するためには、
次にリモートコントロールを有効にするため、
remote-control:
control-enable: yes
control-interface: 127.0.0.1
server-key-file: "/etc/unbound/unbound_server.key"
server-cert-file: "/etc/unbound/unbound_server.pem"
control-key-file: "/etc/unbound/unbound_control.key"
control-cert-file: "/etc/unbound/unbound_control.pem"
……と言いはしたものの、
unbound-controlからUnboundを操作するためには、
@@ -198,7 +198,7 @@ config_create(void)
cfg->local_zones_nodefault = NULL;
cfg->local_data = NULL;
cfg->python_script = NULL;
- cfg->remote_control_enable = 0;
+ cfg->remote_control_enable = 1;
cfg->control_ifs = NULL;
cfg->control_port = UNBOUND_CONTROL_PORT;
cfg->minimal_responses = 0;
control-enable: <yes or no>
The option is used to enable remote control, default is "yes". If turned off, the server does not listen for control commands.
長々と説明しましたが、
unbound-controlには様々なサブコマンドが用意されています。たとえばlocal-dataを追加するにはlocal_
$ sudo unbound-control local_data "www.example.com. IN A 172.16.0.10" ok $ host www.example.com www.example.com has address 172.16.0.10
Muninでのモニタリング
Unboundには、
まずUnbound側の設定です。/etc/
server:
statistics-interval: 0
extended-statistics: yes
statistics-cumulative: no
次にUnboundのソース
$ sudo apt-get install dpkg-dev
$ apt-get source unbound
$ sudo mkdir -p /usr/local/share/munin/plugins
$ sudo cp unbound-1.4.22/contrib/unbound_munin_ /usr/local/share/munin/plugins/
Muninプラグイン動作するために必要な設定を、
sudo vi /etc/munin/plugin-conf.d/munin-node
[unbound*]
user root
env.statefile /var/lib/munin-node/plugin-state/munin/unbound-state
env.unbound_conf /etc/unbound/unbound.conf
env.unbound_control /usr/sbin/unbound-control
シンボリックリンクを張ってプラグインを有効にします。munin-nodeを再起動した後は、
$ cd /etc/munin/plugins $ for n in unbound_munin_hits unbound_munin_queue unbound_munin_memory unbound_munin_by_type unbound_munin_by_class unbound_munin_by_opcode unbound_munin_by_rcode unbound_munin_by_flags unbound_munin_histogram do sudo ln -s /usr/local/share/munin/plugins/unbound_munin_ $n done $ sudo service munin-node restart
$ sudo munin-run unbound_munin_hits t0_n_queries.value .475341 t_n_queries.value .475341 t_n_chits.value .203717 t_n_prefetch.value 0 n_q_tcp.value 0 n_q_ipv6.value 0 u_queries.value 0 u_replies.value 0
5分ほど待てば、


さいごに
家庭内でちょっとだけ名前解決したいんだけど、