コンテンツ配信用のネームサーバNSDを構築
nsdはコンテンツ配信に特化したネームサーバーです。有名なネームサーバの実装にはbindがありますが nsdにはキャッシュサーバの機能は無くあくまでコンテンツ配信用のサーバです。 キャッシュサーバのみの実装にはunboundなどがあります。
インストール
FreeBSDではpkgコマンドで簡単にバイナリパッケージのインストールが行えます。
# pkg install nsd
起動設定
/etc/rc.conf nsd_enable=yes
自己署名証明書の作成
サーバとクライアントの両方に自己署名証明書とプライベート鍵を要求します。 スクリプト nsd-control-setup はデフォルトの実行ディレクトリ、あるいは-dで指定した別のディレクトリにそれらを生成します。
$ cd /usr/local/etc/nsd $ sudo nsd-control-setup
起動
$ sudo /usr/local/etc/rc.d/nsd start
nsdの設定要件
- 取得した独自ドメインの正引き設定
- セカンダリネームサーバの情報を設定
- IPアドレスの逆引き設定
nsdサーバの設定ファイル
ip-address:とoutgoing-interface:にサーバ本体のグローバルIPを指定する 2つのゾーンについてディレクティブを追加する
- example.org -- example.orgの正引き部分
- 19.216.202.in-addr.arpa -- 逆引き設定部分
notify及びprovide-xfrにはセカンダリネームサーバのIPアドレスを指定して notifyの送信先と接続許可先を指定します
設定ファイル
/usr/local/etc/nsd/nsd.conf
# include: "file" # include that file's text over here. server: server-count: 1 ip-address: 202.216.19.** verbosity: 3 hide-version: yes identity: "dns" do-ip4: yes do-ip6: no port: 53 username: bind chroot: "/usr/local/etc/nsd" zonesdir: "/usr/local/etc/nsd/zones" zonelistfile: "zone.list" database: "/usr/local/etc/nsd/nsd.db" logfile: "/usr/local/etc/nsd/nsd.log" pidfile: "/usr/local/etc/nsd/nsd.pid" xfrdfile: "/usr/local/etc/nsd/xfrd.state" xfrdir: "/usr/local/etc/nsd/tmp" difffile: "/usr/local/etc/nsd/ixfr.db" # Remote control config section. remote-control: control-enable: yes control-interface: 127.0.0.1 control-port: 8952 server-key-file: "/usr/local/etc/nsd/nsd_server.key" server-cert-file: "/usr/local/etc/nsd/nsd_server.pem" control-key-file: "/usr/local/etc/nsd/nsd_control.key" control-cert-file: "/usr/local/etc/nsd/nsd_control.pem" pattern: name: "myzones" zonefile: "zones/%s" zone: name: example.org notify: xx.xx.xx.xx NOKEY notify: yy.yy.yy.yy NOKEY notify-retry: 5 provide-xfr: xx.xx.xx.xx NOKEY provide-xfr: yy.yy.yy.yy NOKEY outgoing-interface: 202.216.19.** zonefile: example.org.zone zone: name: 19.216.202.in-addr.arpa zonefile: 19.216.202.in-addr.arpa.zone
正引きゾーン
正引き設定のゾーンファイルをzonesディレクトリに作成する 独自ドメインexample.orgの設定参考例 この設定例ではセカンダリネームサーバに2つのexample.comサーバを指定しています。
$ cat zones/example.org.zone $TTL 3600 @ IN SOA ns.example.org. root.example.org. ( 2015121108 ;Serial Number 10800 ;Refresh every 12 hours 3600 ;Retry after 2 hours 604800 ;Expire after 2 weeks 86400 ) ;Default TTL is 7 days IN NS ns.example.org. IN NS ns1.example.com. IN NS ns3.example.com. @ IN MX 10 ns.example.org. example.org. IN TXT "v=spf1 +ip4:202.216.19.**/32 ~all" ns IN A 202.216.19.** www IN CNAME ns
逆引きゾーン
逆引き設定のゾーンファイルをzonesディレクトリに作成する 独自ドメインexample.orgの逆引き設定をします。ファイル名が19.216.202....となっていますが これは当該サーバのIPアドレスを逆順に並べたものです実際のIPは202.216.19.**となります。
$ cat zones/19.216.202.in-addr.arpa.zone $ORIGIN 19.216.202.in-addr.arpa. $TTL 3600 @ IN SOA ns.example.org. root.example.org.( 2015121201 ; serial number 10800 ; Refresh 3600 ; Retry 604800 ; Expire 86400 ; Min TTL ) ; name servers IN NS ns.example.org. ; PTRs 41 IN PTR ns.example.org.
ゾーン情報更新の通知
nsd.confとゾーンファイルの設定が完了したらnsdデーモンに設定変更内容を読み込ませる nsd.log ファイルに以下のように追加したゾーンファイルのエラーが無くでdbに書き込まれたことがLOGファイルから読み取れる
$ sudo nsd-control reconfig [1449906648] nsd[90382]: info: new control connection from 127.0.0.1 [1449906648] nsd[90382]: info: remote control connection authenticated [1449906648] nsd[90382]: info: control cmd: reconfig [1449906648] nsd[90382]: info: zone added to config: 19.216.202.in-addr.arpa [1449906648] nsd[90382]: info: remote control operation completed [1449906648] nsd[95396]: info: zone 19.216.202.in-addr.arpa read with no errors [1449906648] nsd[95396]: info: zone 19.216.202.in-addr.arpa written to db
サーバのテスト
正引きテスト
自分のサーバ宛に名前解決のリクエストしています 以下のようにANSWER SECTION:が返ってくれば設定OKです
$ drill example.org @202.216.19.** SOA ;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 49380 ;; flags: qr aa rd ; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 1 ;; QUESTION SECTION: ;; example.org. IN SOA ;; ANSWER SECTION: example.org. 3600 IN SOA ns.example.org. root.example.org. 2015121108 10800 3600 604800 86400 ;; AUTHORITY SECTION: example.org. 3600 IN NS ns.example.org. example.org. 3600 IN NS ns1.example.com. example.org. 3600 IN NS ns3.example.com. ;; ADDITIONAL SECTION: ns.example.org. 3600 IN A 202.216.19.** ;; Query time: 2 msec ;; SERVER: 202.216.19.** ;; WHEN: Sat Dec 12 21:47:07 2015 ;; MSG SIZE rcvd: 154
逆引きテスト
自分のサーバ宛に名前解決のリクエストしています 以下のようにANSWER SECTION:が返ってくれば設定OKです
$ drill -x 202.216.19.** @202.216.19.** ;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 19959 ;; flags: qr aa rd ; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 0 ;; QUESTION SECTION: ;; 41.19.216.202.in-addr.arpa. IN PTR ;; ANSWER SECTION: 41.19.216.202.in-addr.arpa. 3600 IN PTR ns.example.org. ;; AUTHORITY SECTION: 19.216.202.in-addr.arpa. 3600 IN NS ns.example.org. ;; ADDITIONAL SECTION: ;; Query time: 4 msec ;; SERVER: 202.216.19.** ;; WHEN: Sat Dec 12 16:51:09 2015 ;; MSG SIZE rcvd: 86
最後にすること
自分のネームサーバの設定が完了したらドメインを取得したレジストラにドメインとネームサーバIPを紐付けするようにします。 また逆引き設定も利用しているプロバイダに逆引き権限委譲の申請が必要になります。 ※これは逆引き権限委譲をしてくれるプロバイダである必要があります。 逆引き権限委譲してくれるプロバイダはそう多くはありません。かもめインターネットやインターリンクでが有名ですかね。。。
セカンダリネームサーバ引受先にも自分のプライマリネームサーバの設定をすればOKです。 設定後あるていど時間が立つことでネームサーバ参照先の情報が浸透してきてどこのネームサーバに問い合わせても自分のゾーン上が分かるようになるはずです。