BIND9によるDNSサーバ構築
ネットワーク内のPCやサーバにアクセスする時にIPアドレスで指定すると、IPアドレスが変わった時に修正しなければならないので面倒です。
DNSサーバを立ててドメイン名*1でアクセスできるようにすれば、DNSサーバの設定を変えるだけで済むようになります。
BIND9のインストール
BIND9とはインターネットで最も利用されている(らしい)DNSサーバを構築するためのソフトです。
- 端末から以下のコマンドを入力してBIND9をインストールする
sudo apt-get install bind9
DNSサーバへの問い合わせ可否設定
「/etc/bind/named.conf.options」をエディタで開き、以下のように設定する。
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; }; // ↓ここから allow-query { 127.0.0.1; 192.168.96.0/24; }; // ↑ここまでを追記する };
- 自分自身(127.0.0.1)とローカルネットワーク(192.168.96.*)内のマシンのみ問い合わせが可能
DNSサーバの応答設定
「/etc/bind/named.conf.local」をエディタで開き、以下のように設定する。
// // Do any local configuration here // // Consider adding the 1918 zones here, if they are not used in your // organization //include "/etc/bind/zones.rfc1918"; // ↓ここから zone "ranger" { type master; file "/etc/bind/db.ranger"; }; zone "96.168.192.in-addr.arpa" { type master; file "/etc/bind/db.96.168.192"; }; // ↑ここまでを追記する
- 「ranger」というルートドメイン名かローカルネットワーク内でのリクエストにのみ応答する
正引き設定
「/etc/bind/db.ranger」を作成し、エディタで開いて以下のように設定する。
$TTL 1D @ IN SOA ranger. root.ranger. ( 2013040701 3H 1H 1W 1D) IN NS kuroneko.ranger. router IN A 192.168.96.1 kuroneko IN A 192.168.96.10
逆引き設定
「/etc/bind/db.96.168.192」を作成し、エディタで開いて以下のように設定する。
$TTL 1D @ IN SOA kuroneko.ranger. root.kuroneko.ranger. ( 2013040701 3H 1H 1W 1D ) IN NS kuroneko.ranger. IN PTR ranger. 1 IN PTR router 10 IN PTR kuroneko
BIND9の実行
- 以下のコマンドを入力してBIND9を再起動する。設定を書き間違えると再起動しない。
sudo services bind9 restart
sudo /etc/init.d/networking restart
- ネットワークの再起動はSSHのセッションが切れないので、わざわざサーバのコンソールで行う必要は無い
確認
WindowsでもLinuxでも「nslookup」というコマンドを実行後、各ドメイン名を入力して確認が可能です。設定に成功していれば以下の様な実行結果が出力されます。
> kuroneko.ranger Server: 192.168.96.10 Address: 192.168.96.*#53 Name: kuroneko.ranger Address: 192.168.96.10
参考資料
BIND9で内向きDNS構築 on Ubuntu - ペイパー・プログラマーズ・ダイアリー
- 作者: Cricket Liu,Paul Albitz,小柏伸夫
- 出版社/メーカー: オライリージャパン
- 発売日: 2008/12/08
- メディア: 大型本
- 購入: 5人 クリック: 34回
- この商品を含むブログ (16件) を見る
*1:インターネットのWebサイトのアドレスみたいな形式の識別名。