こんにちは、けちょです。
前回に引き続き、RaspberryPiにDNSを構築したいと思います。
全体像
インストール
それでは、実際にインストールを進めて行きます。
$ sudo apt-get install bind9
$ sudo apt-get install dnsutils
ufwの設定
$ sudo apt-get install ufw
ufwの設定を確認します。
$ sudo ufw status Status: inactive
インストール直後は、inactiveです。
以下のポートを開放します。
ssh :22
DNS:53(TCP/UDP)
$ sudo ufw allow 22/tcp Rules updated Rules updated (v6) $ sudo ufw allow 53/tcp Rules updated Rules updated (v6) $ sudo ufw allow 53/udp Rules updated Rules updated (v6)
ufwを有効にします。
$ sudo ufw enable Command may disrupt existing ssh connections. Proceed with operation (y|n)? y Firewall is active and enabled on system startup
ssh接続が途切れる可能性がある旨の警告が出ます。
22番ポート(変更している場合は、変更後のポート)を開放していることを確認し、 ” y ” を入力→エンターしてください。
設定を確認してみます。
$ sudo ufw status verbose Status: active Logging: on (low) Default: deny (incoming), allow (outgoing), disabled (routed) New profiles: skip To Action From -- ------ ---- 22/tcp ALLOW IN Anywhere 53/tcp ALLOW IN Anywhere 53/udp ALLOW IN Anywhere 22/tcp (v6) ALLOW IN Anywhere (v6) 53/tcp (v6) ALLOW IN Anywhere (v6) 53/udp (v6) ALLOW IN Anywhere (v6)
適切に設定できていますね。
bindの設定ファイル調整
バックアップを取得し、 named.conf.options ファイルを変更していきます。
$ sudo cp named.conf.options named.conf.options-bak
$ cat /etc/bind/named.conf.options
acl localnet {
127.0.0.1;
192.168.10.0/24;
};
options {
directory "/etc/bind";
allow-query { localnet; };
allow-transfer { none; };
// 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 { 192.168.10.1; };
forward only;
//========================================================================
// 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-enable no;
dnssec-validation no;
auth-nxdomain no; # conform to RFC1035
listen-on-v6 { any; };
};
同様に、named.conf.local も変更します。
$ sudo cp named.conf.local named.conf.local-bak
$ cat 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 "home.local" IN {
type master;
file "home.local.zone";
check-names ignore;
};
zone "10.168.192.in-addr.arpa" IN {
type master;
file "192.168.10.rev";
};
正引き、逆引きファイルは以下の用に設定しました。
$ cat /etc/bind/home.local.zone
$TTL 86400
@ IN SOA home.local. root.localhost. (
2019041402 ; serial
3H ; refresh
15M ; retry
1W ; expiry
1H ) ; minimum
@ IN NS raspi
raspi IN A 192.168.10.2
tinker IN A 192.168.10.3
pana IN A 192.168.10.10
proxy IN CNAME tinker
$ cat 192.168.10.rev
$TTL 86400
@ IN SOA home.local. root.localhost. (
2019040902 ; serial
3H ; refresh
15M ; retry
1W ; expiry
1H ) ; minimum
IN NS home.local.
2 IN PTR raspi.home.local.
3 IN PTR proxy.home.local.
3 IN PTR tinker.home.local.
10 IN PTR pana.home.local.
$ sudo cp named.conf named.conf-bak $ cat named.conf // This is the primary configuration file for the BIND DNS server named. // // Please read /usr/share/doc/bind9/README.Debian.gz for information on the // structure of BIND configuration files in Debian, *BEFORE* you customize // this configuration file. // // If you are just adding zones, please do that in /etc/bind/named.conf.local include "/etc/bind/named.conf.options"; include "/etc/bind/named.conf.local"; #include "/etc/bind/named.conf.default-zones";
dhcpcd.conf のDNSサーバ参照先を、自分自身のIPアドレスに変更します。
$ cat /etc/dhcpcd.conf ~ interface eth0 static ip_address=192.168.10.2/24 static routers=192.168.10.1 #static domain_name_servers=8.8.8.8 static domain_name_servers=127.0.0.1 static domain_name=home.local ~
文法のチェックをします。
named-checkconf /etc/bind/named.conf
OKであれば、なにも出力されません。
サービスを再起動します。
$ sudo service bind9 restart
確認
$ dig home.local ; <<>> DiG 9.10.3-P4-Raspbian <<>> home.local ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17667 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;home.local. IN A ;; AUTHORITY SECTION: home.local. 3600 IN SOA home.local. root.localhost. 2019041402 10800 900 604800 3600 ;; Query time: 0 msec ;; SERVER: 127.0.0.1#53(127.0.0.1) ;; WHEN: Tue Jun 04 21:00:34 JST 2019 ;; MSG SIZE rcvd: 89
$ dig -x 192.168.10.10 ; <<>> DiG 9.10.3-P4-Raspbian <<>> -x 192.168.10.10 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 23138 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;10.10.168.192.in-addr.arpa. IN PTR ;; ANSWER SECTION: 10.10.168.192.in-addr.arpa. 86400 IN PTR pana.home.local. ;; AUTHORITY SECTION: 10.168.192.in-addr.arpa. 86400 IN NS home.local. ;; Query time: 0 msec ;; SERVER: 127.0.0.1#53(127.0.0.1) ;; WHEN: Tue Jun 04 21:02:40 JST 2019 ;; MSG SIZE rcvd: 98
きちんと引けていますね。




コメント