• home
  • about
  • 全ての投稿
  • ソフトウェア・ハードウェアの設定のまとめ
  • 分析関連のまとめ
  • ヘルスケア関連のまとめ
  • 生涯学習関連のまとめ

unbound

date: 2020-05-22 excerpt: unboundの使い方と注意点

tag: unbounddns


unbound

  • DNS cacheサーバ
  • ラウンドロビン機能やキャッシュサイズが可変である等、便利で高速な機能が多い
    • 1.1.1.1などは高負荷のトラフィックを特定のIPアドレスから受けると、通信を止めることがあるので自衛的にunboundなどのサーバを持っておくとよい

install

ubuntu

$ sudo apt install unbound

config files

$ ls /etc/unbound/unbound.conf
unbound.conf

サービスの開始

# systemctl start unbound
# systemctl enable ubound

サービスが開始できない時

  • stublinner等の他のDNSサーバが起動していてport 53が利用できない
    • sudo lsof -i -P -n | grep LISTEN | grep :53のコマンドで確認できる

ローカルのunboundをDNSとして指定する際の注意点

  • systemd-resolvedのキャッシュサーバは127.0.0.53を利用する
  • 一方、unboundはローカルにアクセスする場合、127.0.0.1からのアクセスになる
    • 接続できない際はdig @127.0.0.1 google.comをすると正常に起動して機能しているかが確認できる

unbound.conf設定例 

高速なunbound設定はここのサイトを参考にして設定した

# Unbound configuration file for Debian.
#
# See the unbound.conf(5) man page.
#
# See /usr/share/doc/unbound/examples/unbound.conf for a commented
# reference config file.
#
# The following line includes additional configuration files from the
# /etc/unbound/unbound.conf.d directory.
server:
  access-control: 10.0.0.0/8 allow
  access-control: 127.0.0.0/8 allow
  access-control: 192.168.0.0/16 allow
  aggressive-nsec: yes
  cache-max-ttl: 144000
  cache-min-ttl: 12000
  interface: 0.0.0.0
  interface-automatic: yes # ホストにいくつかIPが割り当てられているときに、複数のIPアドレスでアクセスを許可するのに必要
  rrset-roundrobin: yes
  use-caps-for-id: yes
  verbosity: 1
  num-threads: 128
  msg-cache-slabs: 128
  rrset-cache-slabs: 128
  infra-cache-slabs: 128
  key-cache-slabs: 128
  # perform prefetching of close to expired message cache entries.  If a client
  # requests the dns lookup and the TTL of the cached hostname is going to
  # expire in less than 10% of its TTL, unbound will (1st) return the ip of the
  # host to the client and (2nd) pre-fetch the dns request from the remote dns
  # server. This method has been shown to increase the amount of cached hits by
  # local clients by 10% on average
  prefetch: yes
  
  # Increase the memory size of the cache. Use roughly twice as much rrset cache
  # memory as you use msg cache memory. Due to malloc overhead, the total memory
  # usage is likely to rise to double (or 2.5x) the total cache memory. The test
  # box has 4gig of ram so 256meg for rrset allows a lot of room for cacheed objects.
  rrset-cache-size: 1035m
  msg-cache-size: 512m

  # buffer size for UDP port 53 incoming (SO_RCVBUF socket option). This sets
  # the kernel buffer larger so that no messages are lost in spikes in the traffic.
  so-rcvbuf: 512m

  forward-zone:
    name: "."
    forward-addr: 1.0.0.1@53#one.one.one.one
    forward-addr: 1.1.1.1@53#one.one.one.one
    forward-addr: 8.8.4.4@53#dns.google
    forward-addr: 8.8.8.8@53#dns.google
    forward-addr: 9.9.9.9@53#dns.quad9.net
    forward-addr: 149.112.112.112@53#dns.quad9.net


unbounddns Share Tweet