「Pdnsd」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(同期)
147行目: 147行目:
 
ネットワーク上に複数のコンピュータが存在する場合、全てのコンピュータで pdnsd を DNS サーバーとして使うことができます。ひとつの DNS キャッシュをネットワーク全体で共有することで、ルックアップの速度がもっと高速になります。他のコンピュータから使用できるようにするには、{{ic|global}} セクションの {{ic|server_ip}} をネットワークインターフェイスの名前 (例: {{ic|eth0}}) に設定してください。ファイアウォールを使っている場合、ネットワーク上のアドレスからのポート 53 への接続を許可するようにしてください。
 
ネットワーク上に複数のコンピュータが存在する場合、全てのコンピュータで pdnsd を DNS サーバーとして使うことができます。ひとつの DNS キャッシュをネットワーク全体で共有することで、ルックアップの速度がもっと高速になります。他のコンピュータから使用できるようにするには、{{ic|global}} セクションの {{ic|server_ip}} をネットワークインターフェイスの名前 (例: {{ic|eth0}}) に設定してください。ファイアウォールを使っている場合、ネットワーク上のアドレスからのポート 53 への接続を許可するようにしてください。
   
  +
これで、ネットワーク上の他のコンピューターを構成して、PDNを実行しているコンピューターをプライマリDNSサーバーとして使用できます。
Now you can configure the other computers on your network to use the computer running pdns as their primary dns server.
 
   
 
=== 名前ブロック ===
 
=== 名前ブロック ===

2020年3月4日 (水) 19:29時点における版

関連記事

pdnsd は DNS 情報をローカルでキャッシュするように設計された DNS サーバーです。正しく設定することで、ブロードバンド接続でのブラウジング速度を劇的に上げることができます。BINDdnsmasq と対照的に、再起動後もキャッシュを保持します。"p" は永続 (persistent) です。

インストール

pdnsd パッケージをインストールしてください。

設定

パッケージにはサンプル設定ファイル /usr/share/doc/pdnsd/pdnsd.conf が付属しています。カスタマイズした設定ファイルを /etc/pdnsd.conf に作成してください。

フォーマット

pdnsd.conf ファイルのフォーマットはとても単純ですが、よくある設定ファイルとは少し違うところもあります。様々なタイプのセクションから成ります。セクションのタイプの名前と波括弧 ({) でセクションの開始を示して同じく波括弧 (}) で閉じます。セクションは入れ子にできません。

各ブロックでは以下の形式でオプションを指定します:

option_name=option_value;

セミコロンが最後に付いていることに気をつけて下さい。他のフォーマットと違って、セミコロンは必須です。

コメントは #/* のどちらかで始めます。前者は行全体がコメントになり、後者は */ までずっとコメントになります。

DNS サーバー

DNS 情報を取得するために、最低でも一つの DNS のサーバーのアドレスを pdnsd に指定する必要があります。設定する箇所はブロードバンド接続なのかダイアルアップ接続なのかで変わってきます。ブロードバンドを使っている場合は最初のサーバーセクションを使って下さい。ダイアルアップ接続の場合、2番目のセクションを使って、それ以外のサーバーセクションはコメントアウトしてください。

label 
label オプションはサーバーセクションに名前を付けるのに使います。使用は任意ですが、ISP の名前を使うと良いでしょう。
ip 
デフォルトのブロードバンド設定で使われるこのオプションは pdnsd に使用する DNS サーバーのアドレスを指定します。アドレスが複数ある場合はカンマで区切って下さい。カンマの前後には空白を挟むことができます。/etc/resolv.conf からアドレスをコピーするだけでかまいません。
file 
ip の代わりに file オプションを使うことで DNS サーバーの IP のセットを指定することができます。resolv.conf と同じ形式でサーバーがリストアップされたファイルのパスを値にします。ダイアルアップ接続の設定はデフォルトで file を使います。PPP クライアントは /etc/ppp/resolv.conf に PPP サーバーから得られたアドレスを書き込むからです。ISP から取得できるデフォルトの DNS サーバーを使わない場合でなければ変更する必要はありません。
interface
uptest=if オプションで使うネットワークインターフェイス。デフォルトでは eth0 ですが、基本的に別のインターフェイスになるはずです。pdnsd サービスを起動しても DNS レコードが返ってこない場合、このオプションが間違っていないか疑って下さい。

サーバーセクションの上記以外のオプションは変えなくてもかまいません。利用可能なオプションの詳細は pdnsd マニュアル を見て下さい。

DNS サーバーと DHCP 接続

netctl をインストールしている場合、pdnsd は resolvconf でネームサーバーの IP アドレスを知ることができます (resolvconf(8) を参照)。プロファイルの自動切り替えをしている場合、動的に IP アドレスが伝えられます。

この機能を設定するには、ブロードバンドのサーバーセクションを削除してダイアルアップのサーバーセクションに以下の変更を加えて下さい:

   label = resolvconf;
   file = /etc/pdnsd-resolv.conf;

/etc/resolvconf.conf を編集して pdnsd を使うように resolvconf を設定します:

   name_servers=127.0.0.1
   pdnsd_resolv=/etc/pdnsd-resolv.conf

それから resolvconf -u を実行してネームサーバーのアドレスが載っている /etc/pdnsd-resolv.conf を更新してください (pdnsd ソケットにアクセスできないというエラーメッセージは無視してください)。手動で pdnsd を起動する前に一度更新する必要があります。

OpenDNS

pdnsd.conf ファイルには OpenDNS の設定が初めから入っています。ダイアルアップとブロードバンドセクションを削除 (またはコメントアウト) して (ファイルの上部にある全体の設定を削除してしまわないように注意してください)、OpenDNS の設定をアンコメントすることで OpenDNS を使うことができます。

ただし OpenDNS は Google で問題が発生することがあります。問題を避けるには OpenDNS の Google プロキシマシンを返答する OpenDNS の結果を拒否しなければなりません (大抵の場合 Google のリクエストが 15ms から 75ms 以上にまで遅くなります)。実際のサーバーの IP は代わりますが、(ldns に含まれている) drill www.google.com @208.67.222.222 で現在の IP を確認できます。サーバーの名前が google.navigation.opendns.com のように解決されるので、クエリがプロキシを通しているかどうか知ることができます。執筆時点では、アドレスは 208.67.216.230208.67.216.231 でした。

IP がわかったら、pdnsd.conf の OpenDNS server { …} にある既存の rejected IP を置き換えてください。プリフィックスは削除しないでください。

OpenDNS の代替として OpenNIC というサービスも存在します。

テスト

pdnsd デーモンが機能するか確認するために、起動してください。

テストする方法は Resolv.conf#Linux における DNS を参照してください。

127.0.0.1 を使ってアドレスをルックアップすると、問い合わせ時間は 1 ms 以下になるはずです。

システム設定

pdnsd サービスを有効化してください。

ネットワークを使用するサービス (network-online.target) がちゃんと DNS を使えるように、network.target の後すぐに起動します (参照: Upstream Wiki)。

For any PC with two or more NICs to have pdnsd operational for any wired and wireless connection please configure separate profile for each NIC in pdnsd.conf by specifying correct interface.

ヒントとテクニック‎

ホームブロードバンドユーザー向けのパフォーマンス設定

Many users have broadband connections where the DNS server is slow or unreliable, and would like to use pdnsd as a caching server to minimize the number of DNS queries that need to be made. After doing the setup detailed above, the following settings in the /etc/pdnsd.conf will help improve the performance in this role:

Under global settings:

neg_rrs_pol=on;
par_queries=1;

Under server settings:

proxy_only=on;
purge_cache=off;

The neg_rrs_pol=on; policy means that when a negative response comes back for a query, pdnsd server will still cache the result even if the response is not "authoritative". This is important since watching DNS queries will reveal that there are many requests for AAAA records (DNS queries for IPv6) which will never return results since many domains are not using IPv6, as well as MX records since not every domain has an MX record. Without the negative caching, these requests will be sent even after a domain name has been cached, and in this role you do not want the extra DNS requests being made. It is important to use this option in conjunction with the proxy_only=on; option to minimize the number of queries coming out of the system.

The par_queries=1; option is useful if you specify more than one DNS server in your "server" section below. It specifies an increment of how many parallel queries will be made at once. For example, if four DNS servers are listed in the "server" section, and par_queries=2; (the default), then the first 2 servers will be queried simultaneously, and if both of the first two servers fail, pdnsd will move on to the next two and query them simultaneously. The setting used above means that one DNS server at a time gets queried, so you can list two or more DNS servers in the "server" section, and the second one will only be queried if the first one fails. This helps minimize traffic, but if the first server fails you will have to wait through the timeout before the second server will be queried. Tweak this setting for your own preferences, and if you only specify one server in the "server" section then you do not need to worry about it.

The proxy_only=on; setting is mentioned below in the FAQ and is important for home broadband users since you generally are using only one or two DNS servers instead of trying to do the full-blown hierarchical name resolution that a full DNS server would do. This setting will prevent pdnsd from resolving all the way back to the "authoritative" name server, and instead accept the results of the DNS servers that were already specified in the "server" section. Once again, this reduces the number of DNS queries you need to make, improving performance.

The purge_cache=off; setting tells pdnsd not to remove cache entries even if they have outlived the DNS record's time-to-live metric. This can be very useful when your ISP's DNS server goes down and you want to be able to access name lookups for domains you frequently use despite the outage. Records will still be bumped out of the cache based on age once the cache becomes full (see pdnsd.conf(5) on how to set the size of the cache).

その他のパフォーマンス設定

TTL (Time-To-Live)

Each DNS resource record returned from a server includes a maximum time-to-live, or TTL. This tells the recipient how long to store the record and when to do a new lookup on it. Many DNS records have relatively short TTLs, such as 3600 (one hour). This means that after one hour, pdnsd will attempt a new lookup on this entry, regardless of whether it has a cached record for it available. It will improve performance to override this default TTL by setting a global minimum TTL, causing fewer lookups to be performed. The disadvantage to using a minimum TTL that is too long is that a cached record may be out of date (the IP address of the host may be changed, but your client will not know this because it will receive the cached address). However, most IP addresses do not change hourly or even daily.

Times are specified in seconds by default, or you may append an "m", "h", "d", or "w" to the time to specify minutes, hours, days, or weeks.

min_ttl in the global settings sets a minimum TTL for cached records, causing pdnsd to ignore the default TTL in the record received from the server. On a slow connection or with a slow DNS server, you may want to set this to several hours to reduce the number of lookups ( eg min_ttl=6h; ).

neg_ttl in the global settings sets a minimum TTL for non-existent domains. If a server tells pdnsd that a domain does not exist, it will not try to lookup that domain again until this amount of time has elapsed.

タイムアウト

Setting shorter timeouts means that pdnsd will give up on an entire query or a given server query more quickly, resulting in faster performance. The disadvantage to setting timeouts too short is that pdnsd might return an error on a lookup simply because the server was not given enough time to respond.

timeout in the global settings determines when pdnsd gives up on an entire query and returns an error to your browser or other client. Setting the global timeout option makes it possible to specify quite short timeout intervals in the server sections (see below). This will have the effect that pdnsd will start querying additional servers fairly quickly if the first servers are slow to respond (but will still continue to listen for responses from the first ones). (If you use query_method=tcp_udp it is recommended that you make the global timeout at least twice as large as the largest server timeout, otherwise pdnsd may not have time to try a UDP query if a TCP connection times out.)

tcp_qtimeout in the global settings determines how long a TCP query connection may be left open.

timeout in the server settings determines how long pdnsd will wait for a response from each server. Setting this to a shorter time means that pdnsd will give up on a non-responsive server more quickly and will move on to the next available server, sometimes resulting in a faster overall response time. On a fast connection, setting this to 4 or 5 seconds is not unreasonable.

デバッグ

To see what servers pdnsd is using for a particular lookup, how timeouts are working, and what default TTLs are being used by domains, turn debug on in the global settings:

debug=on;

Restart pdnsd and monitor the pdnsd.service for changes with the systemd journal:

journalctl -f _SYSTEMD_UNIT=pdnsd.service

Be sure to turn debug off for general use as leaving it on may degrade performance.

キャッシュ容量

By default, pdnsd will automatically create authoritative records for all entries in /etc/hosts. If you have a lot of entries, for example if you are using it for ad blocking, the default maximum cache size provided by /etc/pdnsd.conf may not be large enough, resulting in DNS requests not being cached for their expected amount of time.

キャッシュ容量を増やすには、設定ファイルの 'global settings' セクションの perm_cache 行を編集してください (単位は kB です)。

Alternatively, you can prevent pdnsd from preemptively sourcing your hosts file by adding the option authrec=off to the 'source' section. If, for whatever reason, setting authrec to off does not work, an easy workaround is to create a separate hosts file (eg /etc/hosts-pdnsd) with only your system information and point your 'source' section to that instead, while leaving your original hosts file intact. This way, pdnsd will reference /etc/hosts only when performing lookups. So for example:

/etc/hosts-pdnsd
#<ip-address>	<hostname.domain.org>	<hostname>
127.0.0.1	localhost.localdomain	my_hostname
::1		localhost.localdomain	localhost

共有サーバー

ネットワーク上に複数のコンピュータが存在する場合、全てのコンピュータで pdnsd を DNS サーバーとして使うことができます。ひとつの DNS キャッシュをネットワーク全体で共有することで、ルックアップの速度がもっと高速になります。他のコンピュータから使用できるようにするには、global セクションの server_ip をネットワークインターフェイスの名前 (例: eth0) に設定してください。ファイアウォールを使っている場合、ネットワーク上のアドレスからのポート 53 への接続を許可するようにしてください。

これで、ネットワーク上の他のコンピューターを構成して、PDNを実行しているコンピューターをプライマリDNSサーバーとして使用できます。

名前ブロック

pdnsd allows you to specify hosts or domains that it should never return results for. This allows you to use it as a primitive ad or content blocker, among other things. Create a new neg section in pdnsd.conf. neg sections have two main options. name is the name of the host or domain you want to block. types can be set to domain to block all hosts in the given domain. The default pdnsd.conf gives an example that blocks all ads from doubleclick.net.

pdnsd-ctl

pdnsd-ctl(8) man ページより:

pdnsd-ctl は永続的なキャッシュを使う DNS プロキシサーバーである pdnsd を制御します。pdnsd-ctl を使う前に (pdnsd のコマンドラインや設定ファイルでオプションを指定して) ステータス制御ソケットを有効にする必要があるので注意してください。

以下のようなコマンドが使えます。

キャッシュを表示:

# pdnsd-ctl dump

キャッシュを消去:

# pdnsd-ctl empty-cache

DNSCrypt

pdnsd は DNSCrypt と一緒に使うことができます。DNSCrypt はドメイン名のルックアップを暗号化します。必要になったときに pdnsd は DNSCrypt を呼び出します。設定例は DNSCrypt#pdnsd にあります。

トラブルシューティング

result of uptest for 192.168.x.x: failed

You can successfully ping your ISP's dynamic DNS server, even though the log shows the following:

$ journalctl -f _SYSTEMD_UNIT=pdnsd.service
result of uptest for 192.168.x.x: failed

Check the interface configured in /etc/pdnsd.conf global section exists:

interface = any;

or the one in the server section:

interface=enp2s0;

The correct name can be found by running: ifconfig.

FAQ

Q) あんまり速くありません。なぜ? 
A) ローカル DNS キャッシュを使うことによる速度の向上はサーバーに接続するまでにかかる時間によります。スループット (いわゆる速度) に影響はありません。複数のサーバーから小さなダウンロードを行う、ウェブの閲覧などで違いは最も明白になります。接続速度が遅い、特にダイアルアップ接続などでは、スループットがボトルネックになるため、目で見てわかるほどの違いは生まれません。
Q) 前より遅くなっているんですが? 
A) おそらく pdnsd.conf のサーバーセクションのどれかで proxy_only オプションがオフになっています。デフォルトで、pdnsd は出来る限り正確なレスポンスを得るために複数の DNS サーバーに頻繁にリクエストを行います。proxy_only オプションはこの機能を無効化します。ISP によって提供されている DNS サーバーを使っている場合はオンにしたほうが良いでしょう。