作業ログ
BINDのインストール
BIND9をインストールする。
$ sudo apt-get install bind9 ... グループ `bind' (GID 126) を追加しています... 終了。 システムユーザ `bind' (UID 115) を追加しています... 新しいユーザ `bind' (UID 115) をグループ `bind' に追加しています... ホームディレクトリ `/var/cache/bind' は作成しませんでした. wrote key file "/etc/bind/rndc.key" # * Reloading AppArmor profiles ... ...done. * Starting domain name service... bind9 ...done.
named.conf.optionsの変更
ディストリビューションによって作法が違うけれど、Ubuntuでは/etc/bind/named.conf.* を変更する。まずは全体の設定としてnamed.conf.optionsを修正。
$ sudo vim /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; // }; auth-nxdomain no; # conform to RFC1035 listen-on-v6 { any; }; allow-query { any; }; allow-transfer { 127.0.0.1; 192.168.1.0/24; 192.168.11.0/24; }; forwarders { 8.8.8.8; 8.8.4.4; }; };
named.conf.localの編集
続いて/etc/bind/named.conf.localの編集をしてzoneの設定をする。DNS複数立てるわけじゃないので、masterのみ。
// // 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 "jp.example.com" { type master; file "/etc/bind/jp.example.com"; }; zone "1.168.192.in-addr.arpa" { type master; file "/etc/bind/1.168.192.in-addr.arpa"; }; zone "11.168.192.in-addr.arpa" { type master; file "/etc/bind/11.168.192.in-addr.arpa"; };
zoneファイルの設定
次にnamed.zone.localで設定した各zoneに関するzoneファイルの設定をする。まずは正引きの設定。
$ sudo vim /etc/bind/jp.example.com $TTL 86400 @ IN SOA jp.example.com. ns.jp.example.com.( 2005120201 ; Serial 28800 ; Refresh 14400 ; Retry 3600000 ; Expire 86400 ) ; Minimum ; jp.example.com. IN NS ns.jp.example.com. ns.jp.example.com. IN A 192.168.1.2 spam.jp.example.com. IN A 192.168.1.2 egg.jp.example.com. IN A 192.168.1.4 ham.jp.example.com. IN A 192.168.11.100
続いて逆引きの設定。
$ sudo vim /etc/bind/1.168.192.in-addr.arpa $TTL 86400 @ IN SOA jp.example.com. ns.jp.example.com.( 2004031901 ; Serial 28800 ; Refresh 14400 ; Retry 3600000 ; Expire 86400 ) ; Minimum 1.168.192.in-addr.arpa. IN NS ns.jp.example.com 2.1.168.192.in-addr.arpa. IN PTR spam.jp.example.com 4.1.168.192.in-addr.arpa. IN PTR egg.jp.example.com
192.168.11.0/24の設定も実際はしますよ。
ポートの開放
なんか設定ファイルちゃんと編集したのに動かなかったから、おかしいなと思ったら必要なPort(53/TCPと53/UDP)が開いてなかった。
$ sudo nmap -sUT localhost Starting Nmap 4.76 ( http://nmap.org ) at 2010-10-06 01:27 JST Warning: Hostname localhost resolves to 2 IPs. Using 127.0.0.1. Interesting ports on Stratos (127.0.0.1): Not shown: 997 closed ports PORT STATE SERVICE 80/tcp open http 631/tcp open ipp 5910/tcp open unknown 177/udp open|filtered xdmcp 5353/udp open|filtered zeroconf Nmap done: 1 IP address (1 host up) scanned in 0.29 seconds
Ubuntuなのでufw使って開ける。
$ sudo ufw allow 53/tcp $ sudo ufw allow 53/udp
resolv.confの設定
ちゃんと設定したDNSを参照するように修正。
$ sudo vim /etc/resolv.conf hosts bind domain jp.example.com nameserver 192.168.1.2
bind9の再起動
$ sudo /etc/init.d/bind9 restart * Stopping domain name service... bind9 ...done. * Starting domain name service... bind9 ...done.
テストする
MacからDNSサーバを参照して別のマシンを参照出来るかテストする。AirMacを切ってEthernetに今起動したDNSを追加する。(システム環境設定 > ネットワーク > Ethernet)Macの名前解決がいまいち分からないけど、先頭に追加しておかないとキチンと動作しない。
以下テストのログ。
$ ifconfig lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280 stf0: flags=0<> mtu 1280 en1: flags=8823<UP,BROADCAST,SMART,SIMPLEX,MULTICAST> mtu 1500 ether 58:b0:35:73:9c:0e media: <unknown subtype> (<unknown type>) status: inactive fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 4078 lladdr d8:30:62:ff:fe:ec:5f:ba media: autoselect <full-duplex> status: inactive en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 ether 58:b0:35:f2:3f:f4 inet6 fe80::5ab0:35ff:fef2:3ff4%en0 prefixlen 64 scopeid 0x6 inet 192.168.11.3 netmask 0xffffff00 broadcast 192.168.11.255 inet6 2001:c90:629:cd7:5ab0:35ff:fef2:3ff4 prefixlen 64 autoconf media: autoselect (1000baseT <full-duplex,flow-control>) status: active vboxnet0: flags=8842<BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 ether 0a:00:27:00:00:00 $ dig @192.168.1.2 egg.jp.example.com ; <<>> DiG 9.6.0-APPLE-P2 <<>> @192.168.1.2 egg.jp.example.com ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36304 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; QUESTION SECTION: ;egg.jp.example.com. IN A ;; ANSWER SECTION: egg.jp.example.com. 86400 IN A 192.168.1.4 ;; AUTHORITY SECTION: jp.example.com. 86400 IN NS ns.jp.example.com. ;; ADDITIONAL SECTION: ns.jp.example.com. 86400 IN A 192.168.1.2 ;; Query time: 2 msec ;; SERVER: 192.168.1.2#53(192.168.1.2) ;; WHEN: Wed Oct 6 02:20:00 2010 ;; MSG SIZE rcvd: 90 $ nslookup egg.jp.example.com Server: 192.168.1.2 Address: 192.168.1.2#53 Name: egg.jp.example.com Address: 192.168.1.4