「Unbound」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(他言語へのリンクを追加)
 
(5人の利用者による、間の19版が非表示)
1行目: 1行目:
 
[[Category:Domain Name System]]
 
[[Category:Domain Name System]]
 
[[en:Unbound]]
 
[[en:Unbound]]
[[zh-cn:Unbound]]
+
[[ru:Unbound]]
  +
[[zh-hans:Unbound]]
[https://unbound.net/ Unbound] は検証をおこなったり再帰・キャッシュをする DNS リゾルバです。
 
  +
{{Related articles start}}
  +
{{Related|ドメイン名前解決}}
  +
{{Related articles end}}
  +
[https://unbound.net/ Unbound] は検証をおこなったり再帰・キャッシュをする DNS リゾルバです。[[Wikipedia:Unbound (DNS Server)|Wikipedia]] によると
  +
  +
:Unboundは、いくつかのオープンソースプロジェクトにおいて、Berkeley Internet Name Domain ([[BIND]]) をデフォルトのベースシステムのネームサーバーとして置き換えており、ほとんどのアプリケーションにおいて、より小さく、よりモダンで、より安全であると認識されています。
   
 
== インストール ==
 
== インストール ==
   
[[公式リポジトリ]]から {{Pkg|unbound}} パッケージをインストールしてください。
+
[[公式リポジトリ]] から {{Pkg|unbound}} パッケージをインストールしてください。
   
さらに、[[DNSSEC]] 検証をするには {{Pkg|expat}} が必要です。
+
さらに、[[DNSSEC]] 検証をするには {{Pkg|expat}} パッケージが必要です。
   
 
== 設定 ==
 
== 設定 ==
   
''unbound'' の設定は簡単です。サンプル設定ファイル {{ic|/etc/unbound/unbound.conf.example}} 存在すので {{ic|/etc/unbound/unbound.conf}} にコピーし、必要に応じて修正を加えるけで、IPv4 と IPv6 の両方で動作せることができます
+
デフォルト設定は {{ic|/etc/unbound/unbound.conf}} に含まれています。さらに、他のオプションが使われているサンプル設定ファイル {{ic|/etc/unbound/unbound.conf.example}} 存在しま。以下セクションは様々な設定を説明します。詳しい設定は {{ic|man unbound.conf}} を見ださ
   
  +
特に指定しない場合、以下のセクションで説明しているオプションは設定ファイルの {{ic|server}} セクションの下に記述してください:
=== アクセス制御 ===
 
   
  +
{{hc|/etc/unbound/unbound.conf|
IP アドレスによってクエリに応答するインターフェイスを指定できます。''localhost'' で listen するには、以下を使用:
 
  +
server:
  +
...
  +
''setting'': ''value''
  +
...
  +
}}
   
  +
=== ローカル DNS サーバー ===
interface: 127.0.0.1
 
   
  +
ローカル DNS サーバーとして ''unbound'' を使いたい場合、[[resolv.conf]] でネームサーバーを {{ic|::1}} と {{ic|127.0.0.1}} に設定してください。
全てのインターフェイスで listen するには、以下を使用:
 
   
  +
{{hc|/etc/resolv.conf|
interface: 0.0.0.0
 
  +
nameserver ::1
  +
nameserver 127.0.0.1
  +
options trust-ad
  +
}}
   
  +
ネームサーバーの設定が[[Resolv.conf#DNS 設定の保護|変更されないように設定]]する必要があります。
{{ic|access-control}} オプションを使うことでさらに細かくアクセスを設定できます:
 
   
  +
{{Tip|1={{pkg|openresolv}} パッケージをインストールして {{ic|/etc/resolvconf.conf}} の {{ic|1=name_servers=127.0.0.1}} 行をアンコメントして {{ic|resolvconf -u}} を実行することで {{ic|/etc/resolv.conf}} を生成できます。}}
access-control: ''subnet'' ''action''
 
   
  +
設定のテスト方法については [[Resolv.conf#Linux における DNS]] を読んでください。
例:
 
   
  +
[[resolv.conf]] に変更を加えた後に {{ic|127.0.0.1}} が使用されていることを確認してください。
access-control: 192.168.1.0/24 allow
 
 
''action'' は {{ic|deny}} (drop message), {{ic|refuse}} (polite error reply), {{ic|allow}} (recursive ok), {{ic|allow_snoop}} (recursive and nonrecursive ok) のどれかに置き換えます。デフォルトでは、ローカルホスト以外の全てが拒否されます。
 
   
 
=== ルートヒント ===
 
=== ルートヒント ===
   
アドレスがキャッシュされていないホストを問い合わせられた場合、リゾルバはサーバーツリーの一番上からルートサーバーに問い合わせて、アドレスを問い合わせることができるトップレベルドメインの場所を知る必要があります。しがって、''unbound'' 設定ディレクトリに''ルートヒント''ファイルを配置なけばなりません。以下コマ実行するのが一番シンプルな方法です:
+
アドレスがキャッシュされていないホストを問い合わせられた場合、リゾルバはサーバーツリーの一番上からルートサーバーに問い合わせて、アドレスを問い合わせることができるトップレベルドメインの場所を知る必要があります。Unbound にはデフォルトで hints が付属ています、古くなっている可能性があるルートヒントファイルを使用することを推奨ます。したがって、パッケージが定期的に更新さている場合、手動での介入は必要ありません。そうでない場合は、組み込みトが古くなる可能性があるので、ルートヒントファイル使用するのが良い方法です
   
  +
''unbound'' に {{ic|root.hints}} ファイルを指定:
{{bc|<nowiki># curl -o /etc/unbound/root.hints https://www.internic.net/domain/named.cache</nowiki>}}
 
   
  +
root-hints: root.hints
ルートサーバーのリストを最新にするために、上記のコマンドは6ヶ月ごとに実行すると良いでしょう。手動で実行してもかまいませんが、[[cron]] ジョブでタスクを設定する方法もあります。
 
   
''unbound'' から {{ic|root.hints}} ファイルの場所を設定してください:
+
それからルートヒントファイルを ''unbound'' の設定ディレクトリに配置してください。以下のコマンドを実行するだけで配置できます:
   
root-hints: "/etc/unbound/root.hints"
+
{{bc|<nowiki># curl -o /etc/unbound/root.hints https://www.internic.net/domain/named.cache</nowiki>}}
   
  +
ルートサーバーのリストを最新に保つために {{ic|root.hints}} は6ヶ月ごとに更新すると良いでしょう。手動で実行してもよいですし、[[Systemd/タイマー]]を使う方法もあります。タイマーを使う場合は[[#ルートヒント systemd タイマー]]を参照。
=== ローカル DNS サーバーを使うように /etc/resolv.conf を設定 ===
 
   
  +
=== DNSSEC 検証 ===
{{ic|/etc/resolv.conf}} を編集 ([[resolv.conf]] を見て下さい):
 
   
  +
''unbound'' は自動的にルートサーバーの信頼鍵アンカーファイルを {{ic|/etc/trusted-key.key}} から {{ic|/etc/unbound/trusted-key.key}} にコピーします。DNSSEC 検証を使用するには以下の文字列を追加して ''unbound'' にファイルを指定してください:
nameserver 127.0.0.1
 
  +
trust-anchor-file: trusted-key.key
   
  +
DNS サーバーへの[[#クエリの転送|転送]]を設定した場合、上記をコメントアウトしてください。そうしないと、DNS クエリが失敗するようになります。DNS サーバーが対応している場合にのみ DNSSEC 検証が行われるようになります。
Also if you want to be able to use the hostname of local machine names without the fully qualified domain names, then add a line with the local domain such as:
 
   
  +
{{Note|DNSSEC のチェックを有効にすると最初のルックアップ時の DNS 問い合わせ時間が長くなります。アドレスがローカルにキャッシュされたら、瞬時に解決されます。}}
domain localdomain.com
 
nameserver 127.0.0.1
 
   
  +
==== 検証のテスト ====
That way you can refer to local hosts such as mainmachine1.localdomain.com as simply mainmachine1 when using the ssh command, but the drill command below still requires the fully qualified domain names in order to perform lookups.
 
   
  +
DNSSEC が機能しているかどうかをテストするには、{{ic|unbound.service}} を[[起動]]後に次の手順を実行します。
Testing the server before making it default can be done using the drill command from the {{Pkg|ldns}} package with examples from internal and external forward and reverse addresses:
 
   
  +
$ unbound-host -C /etc/unbound/unbound.conf -v sigok.verteiltesysteme.net
$ drill @127.0.0.1 www.cnn.com
 
$ drill @127.0.0.1 localmachine.localdomain.com
 
$ drill @127.0.0.1 -x w.x.y.z
 
   
  +
応答は、IP アドレスの横に {{ic|(secure)}} という文字があるはずです。
where {{ic|w.x.y.z}} can be a local or external IP address and the {{ic|-x}} option requests a reverse lookup. Once all is working, and you have {{ic|/etc/resolv.conf}} set to use {{ic|127.0.0.1}} as the nameserver then you no longer need the {{ic|@127.0.0.1}} in the ''drill'' command, and you can test again that it uses the default DNS server - check that the server used as listed at the bottom of the output from each of these commands shows it is {{ic|127.0.0.1}} being queried.
 
   
  +
$ unbound-host -C /etc/unbound/unbound.conf -v sigfail.verteiltesysteme.net
=== ログ出力 ===
 
   
  +
ここでは、{{ic|(BOGUS (security failure))}} を含む応答が必要です。
If you will want logging for ''unbound'', then create a log file which can also be in the same directory, but you can choose any location. One way is then to do as root:
 
   
  +
さらに、次のように ''drill'' を使ってリゾルバのテストをすることができます。
# touch /etc/unbound/unbound.log
 
# chown unbound:unbound /etc/unbound/unbound.log
 
   
  +
$ drill sigfail.verteiltesysteme.net
Then you can include the logging parameter when you set up the main {{ic|unbound.conf}} file as below.
 
  +
$ drill sigok.verteiltesysteme.net
   
  +
最初のコマンドの {{ic|rcode}} が {{ic|SERVFAIL}} に、2番目のコマンドの {{ic|rcode}} が {{ic|NOERROR}} になっていれば問題ありません。
=== DNSSEC 検証 ===
 
 
You will need the root server trust key anchor file. It is provided by the {{Pkg|dnssec-anchors}} package (already installed as a dependency), however, ''unbound'' needs read and write access to the file. The {{ic|unbound.service}} service accomplishes this by copying the {{ic|/etc/trusted-key.key}} file to {{ic|/etc/unbound/trusted-key.key}}. You just need to point ''unbound'' to this file:
 
{{hc|/etc/unbound/unbound.conf|
 
server:
 
...
 
trust-anchor-file: trusted-key.key
 
...
 
}}
 
 
Also make sure that if a general [[#Forwarding queries|forward]] to the Google servers had been in place, then comment them out otherwise DNS queries will fail. DNSSEC validation will be done if the DNS server being queried supports it.
 
 
{{Note|Including DNSSEC checking significantly increases DNS lookup times for initial lookups. Once an address is cached locally, then the lookup is virtually instantaneous.}}
 
 
{{Pkg|ldns}} (依存パッケージとしてインストールされます) の ''drill'' を使って DNSSEC が機能しているかテストできます:
 
 
drill sigfail.verteiltesysteme.net # should return rcode: SERVFAIL
 
drill sigok.verteiltesysteme.net # should return rcode: NOERROR
 
   
 
=== クエリの転送 ===
 
=== クエリの転送 ===
   
  +
{{Tip|転送を設定することで Unbound から [[DNSCrypt]] を使うことができます。[[DNSCrypt#Unbound]] を参照。}}
If you have a local network which you wish to have DNS queries for and there is a local DNS server that you would like to forward queries to then you should include this line:
 
  +
  +
DNS クエリを送りたいローカルネットワークに DNS サーバーが存在しクエリを転送したい場合、以下の行を記述してください:
   
 
private-address: ''local_subnet/subnet_mask''
 
private-address: ''local_subnet/subnet_mask''
105行目: 101行目:
 
private-address: 10.0.0.0/24
 
private-address: 10.0.0.0/24
   
{{note|You can use private-address to protect against DNS Rebind attacks. Therefore you may enable RFC1918 networks (10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 169.254.0.0/16 fd00::/8 fe80::/10). Unbound may enable this feature by default in future releases.}}
+
{{Note|プライベートアドレスを使うことで DNS Rebind 攻撃から身を守ることができます。RFC1918 ネットワーク (10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 169.254.0.0/16 fd00::/8 fe80::/10) を有効にすることができます。Unbound はデフォルトでは機能を有効にしません。}}
   
  +
ローカルアドレスの正引き・逆引きの両方でローカル DNS サーバーを使うには、正引きと逆引きのそれぞれで以下のような行を設定する必要があります (下の例で使用している 10.0.0.1 は DNS 機能を提供するサーバーの IP アドレスに置き換えてください):
To include a local DNS server for both forward and reverse local addresses a set of lines similar to these below is necessary with a forward and reverse lookup (choose the IP address of the server providing DNS for the local network accordingly by changing 10.0.0.1 in the lines below):
 
   
 
local-zone: "10.in-addr.arpa." transparent
 
local-zone: "10.in-addr.arpa." transparent
   
  +
上記の行は逆引きを正しく動作させるために必要です。
This line above is important to get the reverse lookup to work correctly.
 
   
 
forward-zone:
 
forward-zone:
 
name: "mynetwork.com."
 
name: "mynetwork.com."
forward-addr: 10.0.0.1 # Home DNS
+
forward-addr: 10.0.0.1
   
 
forward-zone:
 
forward-zone:
121行目: 117行目:
 
forward-addr: 10.0.0.1
 
forward-addr: 10.0.0.1
   
  +
{{Note| フォワードゾーンとスタブゾーンには違いがあります。スタブゾーンは、権限のある DNS サーバーに直接接続されている場合にのみ機能します。これは、信頼できる DNS を提供している BIND DNS サーバーからの検索では機能しますが、内部検索が別の DNS サーバーに転送される非結合サーバーへのクエリを参照している場合、ここで参照をマシンのスタブゾーンとして定義しても機能しません。この場合、フォワードゾーンを上記のように定義する必要があります。フォワードゾーンは他の DNS サーバに向けてデイジーチェーン検索を行うことができるからです。つまり、フォワードゾーンは再帰的に DNS サーバへの問い合わせを参照することができます。スタブゾーンを不適切に使用すると、問題を示すエラーメッセージが表示されないため、この区別は重要です。}}
{{Note|There is a difference between forward zones and stub zones - stub zones will only work when connected to an authoritative DNS server directly. This would work for lookups from a [[BIND]] DNS server if it is providing authoritative DNS - but if you are referring queries to an ''unbound'' server in which internal lookups are forwarded on to another DNS server, then defining the referral as a stub zone in the machine here will not work. In that case it is necessary to define a forward zone as above, since forward zones can have daisy chain lookups onward to other DNS servers. i.e. forward zones can refer queries to recursive DNS servers. This distinction is important as you do not get any error messages indicating what the problem is if you use a stub zone inappropriately.}}
 
   
  +
以下のようにすることでローカルホストの正引き・逆引きを設定できます:
You can set up the localhost forward and reverse lookups with the following lines:
 
   
 
local-zone: "localhost." static
 
local-zone: "localhost." static
134行目: 130行目:
 
local-data: "1.0.0.127.in-addr.arpa. 10800 IN PTR localhost."
 
local-data: "1.0.0.127.in-addr.arpa. 10800 IN PTR localhost."
   
  +
デフォルトの正引きゾーンで、ローカルマシンやローカルネットワークの外側のサーバーを使用するには、設定ファイルに以下を追加 (例として Google と OpenDNS の DNS サーバーを指定しています):
Then to use specific servers for default forward zones that are outside of the local machine and outside of the local network (i.e. all other queries will be forwarded to them, and then cached) add this to the configuration file (and in this example the first two addresses are the fast google DNS servers):
 
   
 
forward-zone:
 
forward-zone:
143行目: 139行目:
 
forward-addr: 208.67.220.220
 
forward-addr: 208.67.220.220
   
  +
上記の設定で ''unbound'' は外部ルックアップの正引きゾーンで Google と OpenDNS サーバーを使用します。
This will make ''unbound'' use Google and OpenDNS servers as the forward zone for external lookups.
 
   
  +
{{Note|OpenDNS はレスポンスから DNSSEC レコードを省略するため、[[#DNSSEC 検証|DNSSEC 検証]]を有効にする場合は上記の設定は使わないでください。}}
{{Note|OpenDNS strips DNSSEC records from responses. Do not use the above forward zone if you want to enable [[#DNSSEC validation]].}}
 
  +
  +
=== アクセス制御 ===
  +
  +
IP アドレスによってクエリに応答するインターフェイスを指定できます。''localhost'' で listen するには、以下を使用:
  +
  +
interface: 127.0.0.1
  +
  +
全てのインターフェイスで listen するには、以下を使用:
  +
  +
interface: 0.0.0.0
  +
  +
{{ic|access-control}} オプションを使うことでさらに細かくアクセスを設定できます:
  +
  +
access-control: ''subnet'' ''action''
  +
  +
例:
  +
  +
access-control: 192.168.1.0/24 allow
  +
  +
''action'' に指定できるのは {{ic|deny}} (メッセージを破棄), {{ic|refuse}} (エラー応答), {{ic|allow}} (再帰を許可), {{ic|allow_snoop}} (再帰と非再帰を許可) です。デフォルトでは、ローカルホスト以外の全てが拒否されます。
   
 
== 使用方法 ==
 
== 使用方法 ==
151行目: 167行目:
 
=== Unbound の起動 ===
 
=== Unbound の起動 ===
   
''unbound'' パッケージには {{ic|unbound.service}} が入っているので、[[起動]]してください。ブート時に起動させたいときは[[有効化]]します
+
{{ic|unbound.service}} [[起動]][[有効化]]してください
   
 
=== Unbound の遠隔操作 ===
 
=== Unbound の遠隔操作 ===
198行目: 214行目:
   
 
* 再設定しないで統計を出力
 
* 再設定しないで統計を出力
# unbound-control stats_noreset
+
# unbound-control stats_noreset
   
 
* キャッシュを標準出力にダンプ
 
* キャッシュを標準出力にダンプ
# unbound-control dump_cache
+
# unbound-control dump_cache
   
 
* キャッシュを消去して設定をリロード
 
* キャッシュを消去して設定をリロード
# unbound-control reload
+
# unbound-control reload
   
 
詳しくは {{ic|man 8 unbound-control}} を参照してください。
 
詳しくは {{ic|man 8 unbound-control}} を参照してください。
   
  +
== ヒントとテクニック ==
== Adding an authoritative DNS server ==
 
  +
  +
=== ブロック通知 ===
  +
[https://pgl.yoyo.org/adservers/serverlist.php?hostformat=unbound&showintro=0&startdate%5Bday%5D=&startdate%5Bmonth%5D=&startdate%5Byear%5D=&mimetype=plaintext adservers] ファイルを作成して以下の設定を Unbound に追加してください:
  +
{{hc|/etc/unbound/unbound.conf|
  +
...
  +
include: /etc/unbound/adservers
  +
}}
  +
  +
{{Note|これらのホストでいくつかの OK ステータスを返すために、あなたがコントロールするサーバへの 127.0.0.1 リダイレクションを変更して、そのサーバに空の 204 応答させることができます。 [http://www.shadowandy.net/2014/04/adblocking-nginx-serving-1-pixel-gif-204-content.htm このページ] を参照してください。}}
  +
  +
=== 権威 DNS サーバーの追加 ===
  +
  +
検証・再帰・キャッシュ DNS サーバーと権威 DNS サーバーを同じマシンで動作させたい場合、[[NSD]] のページを参照してください。全ての機能を提供する DNS サーバーを動作させるより、権威サーバーとキャッシュサーバーを分けることでセキュリティを向上させることができます。[[NSD]] のページには BIND から移行する際に役立つ情報を載せています。
  +
  +
=== WAN と DNS ===
  +
  +
listen しているサーバーの設定ファイルやインターフェイスを変更することで、ローカルネットワーク外のマシンからのクエリから LAN 内の特定のマシンにアクセスできるように設定できます。どこからでもアクセスできるようにするウェブサーバーやメールサーバーなどで有用です。
  +
  +
=== ルートヒント systemd タイマー ===
  +
  +
以下は [[#ルートヒント]] に書かれている方法で {{ic|root.hints}} を1ヶ月ごとに更新する systemd サービスとタイマーの例です:
  +
  +
{{hc|1=/etc/systemd/system/roothints.service|2=
  +
[Unit]
  +
Description=Update root hints for unbound
  +
After=network.target
  +
  +
[Service]
  +
ExecStart=/usr/bin/curl -o /etc/unbound/root.hints <nowiki>https://www.internic.net/domain/named.cache</nowiki>
  +
}}
  +
  +
{{hc|1=/etc/systemd/system/roothints.timer|2=
  +
[Unit]
  +
Description=Run root.hints monthly
  +
  +
[Timer]
  +
OnCalendar=monthly
  +
Persistent=true
  +
  +
[Install]
  +
WantedBy=timers.target}}
  +
  +
{{ic|roothints.timer}} systemd タイマーを [[起動]]・[[有効化]]してください。
  +
  +
=== DNS キャッシュを常に最新の状態に保つ ===
   
  +
unbound は、キャッシュされた DNS エントリが期限切れになる前に自動的に更新され、キャッシュを常に最新の状態に保つプリフェッチをサポートしています。{{man|5|unbound.conf}} のマニュアルページから引用、これをオンにすると、トラフィックとマシンの負荷が約 10% 増加しますが、需要のあるアイテムはキャッシュから期限切れになりません。これは、RTT が高いモバイルリンクで特に役立ちます。
For users who wish to run both a validating, recursive, caching DNS server as well as an authoritative DNS server on a single machine then it may be useful to refer to the wiki page [[en2:nsd|nsd]] which gives an example of a configuration for such a system. Having one server for authoritative DNS queries and a separate DNS server for the validating, recursive, caching DNS functions gives increased security over a single DNS server providing all of these functions. Many users have used bind as a single DNS server, and some help on migration from bind to the combination of running nsd and bind is provided in the [[en2:nsd|nsd]] wiki page.
 
   
  +
プリフェッチを有効にするには、これを {{ic|server}} セクションの下に追加します:
== WAN と DNS ==
 
   
  +
prefetch: yes
It is also possible to change the configuration files and interfaces on which the server is listening so that DNS queries from machines outside of the local network can access specific machines within the LAN. This is useful for web and mail servers which are accessible from anywhere, and the same techniques can be employed as has been achieved using bind for many years, in combination with suitable port forwarding on firewall machines to forward incoming requests to the right machine.
 
   
  +
== トラブルシューティング ==
== num-threads の問題 ==
 
   
  +
=== num-threads の問題 ===
The man page for {{ic|unbound.conf}} mentions:
 
   
  +
{{ic|unbound.conf}} の man ページより:
outgoing-range: <number>
 
Number of ports to open. This number of file descriptors can be opened per thread.
 
   
  +
outgoing-range: <number>
and some sources suggest that the {{ic|num-threads}} parameter should be set to the number of cpu cores. The sample {{ic|unbound.conf.example}} file merely has:
 
  +
Number of ports to open. This number of file descriptors can be opened per thread.
   
  +
一部のウェブサイトでは {{ic|num-threads}} は CPU コアの数に設定するように推奨しています。{{ic|unbound.conf.example}} サンプルファイルの記述:
# number of threads to create. 1 disables threading.
 
# num-threads: 1
 
   
  +
# number of threads to create. 1 disables threading.
However it is not possible to arbitrarily increase {{ic|num-threads}} above {{ic|1}} without causing ''unbound'' to start with warnings in the logs about exceeding the number of file descriptors. In reality for most users running on small networks or on a single machine it should be unnecessary to seek performance enhancement by increasing {{ic|num-threads}} above {{ic|1}}. If you do wish to do so then refer to [http://www.unbound.net/documentation/howto_optimise.html official documentation] and the following rule of thumb should work:
 
  +
# num-threads: 1
   
  +
ただし {{ic|num-threads}} を {{ic|1}} より大きな値に設定すると ''unbound'' を起動したときにログにファイル記述子の数が多すぎるという警告が吐かれます。小規模なネットワークで Unbound を使っている場合、{{ic|num-threads}} を {{ic|1}} より大きな値に設定して性能をあげようとしても無駄です。設定したい場合は [http://www.unbound.net/documentation/howto_optimise.html 公式ドキュメント] を参照してください。
:''Set {{ic|num-threads}} equal to the number of CPU cores on the system. E.g. for 4 CPUs with 2 cores each, use 8.''
 
   
Set the {{ic|outgoing-range}} to as large a value as possible, see the sections in the referred web page above on how to overcome the limit of {{ic|1024}} in total. This services more clients at a time. With 1 core, try {{ic|950}}. With 2 cores, try {{ic|450}}. With 4 cores try {{ic|200}}. The {{ic|num-queries-per-thread}} is best set at half the number of the {{ic|outgoing-range}}.
+
{{ic|outgoing-range}} はできるだけ大きな値に設定してください。上記で参照しているウェブページのセクションには {{ic|1024}} の制限を越える方法が書かれています。複数のクライアントを同時にさばくことが可能です。シングルコアなら {{ic|950}} を、デュアルコアなら {{ic|450}} を、クアッドコアなら {{ic|200}} を試して下さい。{{ic|num-queries-per-thread}} {{ic|outgoing-range}} の数字の半分に設定するのが最適です。
   
  +
{{ic|outgoing-range}} の制限により {{ic|num-queries-per-thread}} も制限されるため、 {{ic|outgoing-range}} に {{{ic|1024}} 制限がないように、 {{Pkg|libevent}} でコンパイルすることをお薦めします。負荷の高い DNS サーバ用にこの方法でコンパイルする必要がある場合は、 {{Pkg|unbound}} パッケージを使用する代わりに、ソースからプログラムをコンパイルする必要があります。
Because of the limit on {{ic|outgoing-range}} thus also limits {{ic|num-queries-per-thread}}, it is better to compile with {{Pkg|libevent}}, so that there is no {{ic|1024}} limit on {{ic|outgoing-range}}. If you need to compile this way for a heavy duty DNS server then you will need to compile the programme from source instead of using the {{Pkg|unbound}} package.
 
   
 
== 参照 ==
 
== 参照 ==
   
  +
* [https://fedoraproject.org/wiki/Changes/Default_Local_DNS_Resolver Fedora change to Unbound]
 
* [https://github.com/jodrell/unbound-block-hosts/ Block hosts that contain advertisements]
 
* [https://github.com/jodrell/unbound-block-hosts/ Block hosts that contain advertisements]

2023年11月8日 (水) 17:19時点における最新版

関連記事

Unbound は検証をおこなったり再帰・キャッシュをする DNS リゾルバです。Wikipedia によると

Unboundは、いくつかのオープンソースプロジェクトにおいて、Berkeley Internet Name Domain (BIND) をデフォルトのベースシステムのネームサーバーとして置き換えており、ほとんどのアプリケーションにおいて、より小さく、よりモダンで、より安全であると認識されています。

インストール

公式リポジトリ から unbound パッケージをインストールしてください。

さらに、DNSSEC 検証をするには expat パッケージが必要です。

設定

デフォルト設定は /etc/unbound/unbound.conf に含まれています。さらに、他のオプションが使われているサンプル設定ファイルが /etc/unbound/unbound.conf.example に存在します。以下のセクションでは様々な設定を説明します。詳しい設定は man unbound.conf を見てください。

特に指定しない場合、以下のセクションで説明しているオプションは設定ファイルの server セクションの下に記述してください:

/etc/unbound/unbound.conf
server:
  ...
  setting: value
  ...

ローカル DNS サーバー

ローカル DNS サーバーとして unbound を使いたい場合、resolv.conf でネームサーバーを ::1127.0.0.1 に設定してください。

/etc/resolv.conf
nameserver ::1
nameserver 127.0.0.1
options trust-ad

ネームサーバーの設定が変更されないように設定する必要があります。

ヒント: openresolv パッケージをインストールして /etc/resolvconf.confname_servers=127.0.0.1 行をアンコメントして resolvconf -u を実行することで /etc/resolv.conf を生成できます。

設定のテスト方法については Resolv.conf#Linux における DNS を読んでください。

resolv.conf に変更を加えた後に 127.0.0.1 が使用されていることを確認してください。

ルートヒント

アドレスがキャッシュされていないホストを問い合わせられた場合、リゾルバはサーバーツリーの一番上からルートサーバーに問い合わせて、アドレスを問い合わせることができるトップレベルドメインの場所を知る必要があります。Unbound にはデフォルトで hints が付属していますが、古くなっている可能性があるのでルートヒントファイルを使用することを推奨します。したがって、パッケージが定期的に更新されている場合、手動での介入は必要ありません。そうでない場合は、組み込みのヒントが古くなる可能性があるので、ルートヒントファイルを使用するのが良い方法です。

unboundroot.hints ファイルを指定:

root-hints: root.hints

それからルートヒントファイルを unbound の設定ディレクトリに配置してください。以下のコマンドを実行するだけで配置できます:

# curl -o /etc/unbound/root.hints https://www.internic.net/domain/named.cache

ルートサーバーのリストを最新に保つために root.hints は6ヶ月ごとに更新すると良いでしょう。手動で実行してもよいですし、Systemd/タイマーを使う方法もあります。タイマーを使う場合は#ルートヒント systemd タイマーを参照。

DNSSEC 検証

unbound は自動的にルートサーバーの信頼鍵アンカーファイルを /etc/trusted-key.key から /etc/unbound/trusted-key.key にコピーします。DNSSEC 検証を使用するには以下の文字列を追加して unbound にファイルを指定してください:

trust-anchor-file: trusted-key.key

DNS サーバーへの転送を設定した場合、上記をコメントアウトしてください。そうしないと、DNS クエリが失敗するようになります。DNS サーバーが対応している場合にのみ DNSSEC 検証が行われるようになります。

ノート: DNSSEC のチェックを有効にすると最初のルックアップ時の DNS 問い合わせ時間が長くなります。アドレスがローカルにキャッシュされたら、瞬時に解決されます。

検証のテスト

DNSSEC が機能しているかどうかをテストするには、unbound.service起動後に次の手順を実行します。

$ unbound-host -C /etc/unbound/unbound.conf -v sigok.verteiltesysteme.net

応答は、IP アドレスの横に (secure) という文字があるはずです。

$ unbound-host -C /etc/unbound/unbound.conf -v sigfail.verteiltesysteme.net

ここでは、(BOGUS (security failure)) を含む応答が必要です。

さらに、次のように drill を使ってリゾルバのテストをすることができます。

$ drill sigfail.verteiltesysteme.net
$ drill sigok.verteiltesysteme.net

最初のコマンドの rcodeSERVFAIL に、2番目のコマンドの rcodeNOERROR になっていれば問題ありません。

クエリの転送

ヒント: 転送を設定することで Unbound から DNSCrypt を使うことができます。DNSCrypt#Unbound を参照。

DNS クエリを送りたいローカルネットワークに DNS サーバーが存在しクエリを転送したい場合、以下の行を記述してください:

private-address: local_subnet/subnet_mask

例:

private-address: 10.0.0.0/24
ノート: プライベートアドレスを使うことで DNS Rebind 攻撃から身を守ることができます。RFC1918 ネットワーク (10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 169.254.0.0/16 fd00::/8 fe80::/10) を有効にすることができます。Unbound はデフォルトでは機能を有効にしません。

ローカルアドレスの正引き・逆引きの両方でローカル DNS サーバーを使うには、正引きと逆引きのそれぞれで以下のような行を設定する必要があります (下の例で使用している 10.0.0.1 は DNS 機能を提供するサーバーの IP アドレスに置き換えてください):

local-zone: "10.in-addr.arpa." transparent

上記の行は逆引きを正しく動作させるために必要です。

forward-zone:
name: "mynetwork.com."
forward-addr: 10.0.0.1
forward-zone:
name: "10.in-addr.arpa."
forward-addr: 10.0.0.1
ノート: フォワードゾーンとスタブゾーンには違いがあります。スタブゾーンは、権限のある DNS サーバーに直接接続されている場合にのみ機能します。これは、信頼できる DNS を提供している BIND DNS サーバーからの検索では機能しますが、内部検索が別の DNS サーバーに転送される非結合サーバーへのクエリを参照している場合、ここで参照をマシンのスタブゾーンとして定義しても機能しません。この場合、フォワードゾーンを上記のように定義する必要があります。フォワードゾーンは他の DNS サーバに向けてデイジーチェーン検索を行うことができるからです。つまり、フォワードゾーンは再帰的に DNS サーバへの問い合わせを参照することができます。スタブゾーンを不適切に使用すると、問題を示すエラーメッセージが表示されないため、この区別は重要です。

以下のようにすることでローカルホストの正引き・逆引きを設定できます:

local-zone: "localhost." static
local-data: "localhost. 10800 IN NS localhost."
local-data: "localhost. 10800 IN SOA localhost. nobody.invalid. 1 3600 1200 604800 10800"
local-data: "localhost. 10800 IN A 127.0.0.1"
local-zone: "127.in-addr.arpa." static
local-data: "127.in-addr.arpa. 10800 IN NS localhost."
local-data: "127.in-addr.arpa. 10800 IN SOA localhost. nobody.invalid. 2 3600 1200 604800 10800"
local-data: "1.0.0.127.in-addr.arpa. 10800 IN PTR localhost."

デフォルトの正引きゾーンで、ローカルマシンやローカルネットワークの外側のサーバーを使用するには、設定ファイルに以下を追加 (例として Google と OpenDNS の DNS サーバーを指定しています):

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

上記の設定で unbound は外部ルックアップの正引きゾーンで Google と OpenDNS サーバーを使用します。

ノート: OpenDNS はレスポンスから DNSSEC レコードを省略するため、DNSSEC 検証を有効にする場合は上記の設定は使わないでください。

アクセス制御

IP アドレスによってクエリに応答するインターフェイスを指定できます。localhost で listen するには、以下を使用:

interface: 127.0.0.1

全てのインターフェイスで listen するには、以下を使用:

interface: 0.0.0.0

access-control オプションを使うことでさらに細かくアクセスを設定できます:

access-control: subnet action

例:

access-control: 192.168.1.0/24 allow

action に指定できるのは deny (メッセージを破棄), refuse (エラー応答), allow (再帰を許可), allow_snoop (再帰と非再帰を許可) です。デフォルトでは、ローカルホスト以外の全てが拒否されます。

使用方法

Unbound の起動

unbound.service起動有効化してください。

Unbound の遠隔操作

unbound には unbound-control ユーティリティが付いており、リモートの unbound サーバーを管理することができます。pdnsdpdnsd-ctl コマンドに似ています。

unbound-control の設定

使用する前に、以下の設定が必要です:

1) まず、以下のコマンドを実行してください:

# unbound-control-setup

自己署名証明書とサーバーとクライアントの秘密鍵が生成されます。これらのファイルは /etc/unbound ディレクトリに保存されます。

2) その後、/etc/unbound/unbound.conf を編集して以下の内容を記述してください。control-enable: yes オプションは必須ですが、他のオプションは必要に応じて変更できます。

remote-control:
    # Enable remote control with unbound-control(8) here.
    # set up the keys and certificates with unbound-control-setup.
    control-enable: yes
   
    # what interfaces are listened to for remote control.
    # give 0.0.0.0 and ::0 to listen to all interfaces.
    control-interface: 127.0.0.1
   
    # port number for remote control operations.
    control-port: 8953
   
    # unbound server key file.
    server-key-file: "/etc/unbound/unbound_server.key"
   
    # unbound server certificate file.
    server-cert-file: "/etc/unbound/unbound_server.pem"
   
    # unbound-control key file.
    control-key-file: "/etc/unbound/unbound_control.key"
   
    # unbound-control certificate file.
    control-cert-file: "/etc/unbound/unbound_control.pem"

unbound-control を使う

unbound-control で使用できるコマンドの例:

  • 再設定しないで統計を出力
# unbound-control stats_noreset
  • キャッシュを標準出力にダンプ
# unbound-control dump_cache
  • キャッシュを消去して設定をリロード
# unbound-control reload

詳しくは man 8 unbound-control を参照してください。

ヒントとテクニック

ブロック通知

adservers ファイルを作成して以下の設定を Unbound に追加してください:

/etc/unbound/unbound.conf
...
include: /etc/unbound/adservers
ノート: これらのホストでいくつかの OK ステータスを返すために、あなたがコントロールするサーバへの 127.0.0.1 リダイレクションを変更して、そのサーバに空の 204 応答させることができます。 このページ を参照してください。

権威 DNS サーバーの追加

検証・再帰・キャッシュ DNS サーバーと権威 DNS サーバーを同じマシンで動作させたい場合、NSD のページを参照してください。全ての機能を提供する DNS サーバーを動作させるより、権威サーバーとキャッシュサーバーを分けることでセキュリティを向上させることができます。NSD のページには BIND から移行する際に役立つ情報を載せています。

WAN と DNS

listen しているサーバーの設定ファイルやインターフェイスを変更することで、ローカルネットワーク外のマシンからのクエリから LAN 内の特定のマシンにアクセスできるように設定できます。どこからでもアクセスできるようにするウェブサーバーやメールサーバーなどで有用です。

ルートヒント systemd タイマー

以下は #ルートヒント に書かれている方法で root.hints を1ヶ月ごとに更新する systemd サービスとタイマーの例です:

/etc/systemd/system/roothints.service
[Unit]
Description=Update root hints for unbound
After=network.target

[Service]
ExecStart=/usr/bin/curl -o /etc/unbound/root.hints https://www.internic.net/domain/named.cache
/etc/systemd/system/roothints.timer
[Unit]
Description=Run root.hints monthly

[Timer]
OnCalendar=monthly
Persistent=true     
 
[Install]
WantedBy=timers.target

roothints.timer systemd タイマーを 起動有効化してください。

DNS キャッシュを常に最新の状態に保つ

unbound は、キャッシュされた DNS エントリが期限切れになる前に自動的に更新され、キャッシュを常に最新の状態に保つプリフェッチをサポートしています。unbound.conf(5) のマニュアルページから引用、これをオンにすると、トラフィックとマシンの負荷が約 10% 増加しますが、需要のあるアイテムはキャッシュから期限切れになりません。これは、RTT が高いモバイルリンクで特に役立ちます。

プリフェッチを有効にするには、これを server セクションの下に追加します:

prefetch: yes

トラブルシューティング

num-threads の問題

unbound.conf の man ページより:

outgoing-range: <number>
        Number of ports to open. This number of file  descriptors  can  be  opened  per thread.

一部のウェブサイトでは num-threads は CPU コアの数に設定するように推奨しています。unbound.conf.example サンプルファイルの記述:

# number of threads to create. 1 disables threading.
# num-threads: 1

ただし num-threads1 より大きな値に設定すると unbound を起動したときにログにファイル記述子の数が多すぎるという警告が吐かれます。小規模なネットワークで Unbound を使っている場合、num-threads1 より大きな値に設定して性能をあげようとしても無駄です。設定したい場合は 公式ドキュメント を参照してください。

outgoing-range はできるだけ大きな値に設定してください。上記で参照しているウェブページのセクションには 1024 の制限を越える方法が書かれています。複数のクライアントを同時にさばくことが可能です。シングルコアなら 950 を、デュアルコアなら 450 を、クアッドコアなら 200 を試して下さい。num-queries-per-threadoutgoing-range の数字の半分に設定するのが最適です。

outgoing-range の制限により num-queries-per-thread も制限されるため、 outgoing-range に {1024 制限がないように、 libevent でコンパイルすることをお薦めします。負荷の高い DNS サーバ用にこの方法でコンパイルする必要がある場合は、 unbound パッケージを使用する代わりに、ソースからプログラムをコンパイルする必要があります。

参照