server$ sudo apt install bind9
使用中のDNSサーバの確認
クライアントに設定されているDNSサーバはnmcli
コマンドで確認できる。
$ nmcli device show | grep DNS
IP4.DNS[1]: 8.8.8.8
IP4.DNS[2]: 8.8.4.4
IP4.DNS[3]: 1.1.1.1
用語
コンテンツサーバ(権威サーバ)
あるゾーン(DNSにおける名前の管理単位)に関する名前解決要求(非再帰問い合わせ)を受け取り、自身が管理するゾーンならば名前解決結果を、委任情報を持つゾーンならば委任先の権威サーバ情報を応答する。
ルートゾーン(FQDN: .
)を管理するルートサーバは、TLD(例えば jp.
)の権威サーバへの委任情報を持つ。
ゾーン情報において、NSレコードにより指定される。
キャッシュサーバ(フルサービスリゾルバ)
クライアントから名前解決要求(再帰問い合わせ)を受け取り、 コンテンツサーバへ反復的に名前解決要求(反復問い合わせ)を送ることで任意のドメイン名の名前解決を行う。
例えばhoge.example.jp.
というドメインの名前解決要求を受け取ったとき、
ルートサーバ.
への非再帰問い合わせによりjp.
権威サーバへの委任情報を取得する。
jp.
権威サーバへの非再帰問い合わせによりexample.jp.
権威サーバへの委任情報を取得する。
example.jp.
権威サーバへの非再帰問い合わせによりhoge.example.jp.
のIPアドレスを取得する、のような流れで反復的に問い合わせを行うことでhoge.example.jp.
の名前解決を行う。
ISPの提供するDNSサーバや会社などの組織内DNSサーバ、GoogleやCloudflareなどが提供するパブリックDNSがある。
回送
プロキシのように、受け取った名前解決要求を他のDNSサーバに送り、 応答を返す。
/etc/bind/named.conf.options
自身が管理していない情報(ゾーン、委任情報)に関する問い合わせについて、 他のDNSサーバ(フルサービスリゾルバ)に問い合わせを回送するように設定する。
- 「再帰問い合わせ」と「非再帰問い合わせ」の違いを教えてください:DNS Tips - @IT
- BIND DNSサーバー構築 | CentOSサーバー構築入門
- フォワード(回送) : お父さんのためのDNS講座
デフォルト設定ファイル
options {
directory "/var/cache/bind";
// If there is a firewall between you and nameservers you want
// to talk to, you may need to fix the firewall to allow multiple
// ports to talk. See http://www.kb.cert.org/vuls/id/800113
// If your ISP provided one or more IP addresses for stable
// nameservers, you probably want to use them as forwarders.
// Uncomment the following block, and insert the addresses replacing
// the all-0's placeholder.
// forwarders {
// 0.0.0.0;
// };
//========================================================================
// If BIND logs error messages about the root key being expired,
// you will need to update your keys. See https://www.isc.org/bind-keys
//========================================================================
dnssec-validation auto;
auth-nxdomain no; # conform to RFC1035
listen-on-v6 { any; };
};
変更点
forwarders {
8.8.8.8;
8.8.4.4;
1.1.1.1;
};
確認
server$ systemctl restart bind9.service
client$ dig @192.168.x.x aoirint.com
...
;; ANSWER SECTION:
aoirint.com. 3600 IN A 185.199.108.153
aoirint.com. 3600 IN A 185.199.111.153
aoirint.com. 3600 IN A 185.199.109.153
aoirint.com. 3600 IN A 185.199.110.153
...
/etc/bind/named.conf.local
DNSサーバの管理するゾーンの名前と対応する設定ファイル(ゾーンファイル)を設定する。
//
// Do any local configuration here
//
zone "example.com" IN {
type master;
file "example.com.zone";
};
// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
/var/cache/bind/example.com.zone
ゾーン情報を設定する。
$ORIGIN example.com.
$TTL 3600
@ IN SOA dns.example.com. root.example.com. (
2021060900 ; Serial
3600 ; Refresh
900 ; Retry
604800 ; Expire
86400 ; Minimum
)
IN NS dns.example.com.
dns IN A 192.168.xx.xx
@ IN A 192.168.xx.xx
local IN A 192.168.xx.xx
dev IN A 192.168.xx.xx
server$ systemctl restart bind9.service
client$ dig @192.168.x.x example.com
...
;; ANSWER SECTION:
example.com. 3600 IN A 192.168.xx.xx
...
client$ dig @192.168.x.x local.example.com
...
;; ANSWER SECTION:
local.example.com. 3600 IN A 192.168.xx.xx
...
client$ dig @192.168.x.x dev.example.com
...
;; ANSWER SECTION:
dev.example.com. 3600 IN A 192.168.xx.xx
...