1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DNSサーバ(bind)を仮想マシンとして作成/#2:bindのインストール

Last updated at Posted at 2019-05-03

bindをインストールし、named.confを設定する

/etc/named.conf

option

bind全体に影響する設定項目。

option:設定値 説明
listen-on port 53 { 192.168.0.0/16; 127.0.0.1; }; listenするポート、アドレス
directory "/var/named"; ディレクトリ起点
allow-query { 192.168.0.0/16; 127.0.0.1; }; 問合せを許可するアドレス
recursion yes; 再帰問合せを許可
allow-recursion { 192.168.0.0/16; 127.0.0.1; }; 再帰問合せを許可するアドレス
forwarders { 8.8.8.8; }; フォワード先、自己解決できない(ゾーン情報を持っていない)場合の問合せ先

logging

ログ出力設定。新しいchannel[query_log]を定義し、この内容でログ出力する。デフォルトはseverity[dynamic]で出力過多なので使用しない。

named.confのサンプル(抜粋)

named.conf
options {
	listen-on port 53 { 192.168.0.0/16; 127.0.0.1; };
	directory 	"/var/named";
	allow-query     { 192.168.0.0/16; 127.0.0.1; };

	recursion yes;
	allow-recursion { 192.168.0.0/16; 127.0.0.1; };

	forwarders { 8.8.8.8; };
};

logging {
// 追加
        channel "queries_log" {
                file "data/queries.log" versions 10 size 100M;
                severity info;
                print-time yes;
        };
        category queries { "queries_log"; };
};

zone "." IN {
	type hint;
	file "named.ca";
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

// "hrsk"のゾーン宣言を追加
include "/etc/named/named.conf.hrsk";

ゾーン宣言と定義

ファイル名規約

ファイル内容 ファイル名
ゾーン宣言
named.confにincludeされる
/etc/named/named.conf.ゾーン名
ゾーン定義(正引き) /etc/named/zones.ゾーン名
ゾーン定義(逆引き) /etc/named/re.アドレス

/etc/named/named.conf.ゾーン名

設定値 説明
zone "hrsk" ゾーン名[.hrsk]を定義
type master; マスタ・スレーブのマスタ。権威サーバ
file "...."; ゾーン(ドメイン)定義
allow-query { xxxx; }; このゾーンへの問合せを許可するアドレス
allow-update { xxxx; }; Dynamic DNSは使わないので、none。セキュリティ面からも拒否が望ましい
named.conf.hrsk
// 正引き
// .hrsk
zone "hrsk" {
  type master;
  file "/etc/named/zones.hrsk";
  allow-query { 192.168.0.0/16; };
  allow-update { none; };
};

// 逆引き
// 192.168.0.
zone "0.168.192.in-addr.arpa" {
  type master;
  file "/etc/named/re.192.168.0";
  allow-query { 192.168.0.0/16; };
  allow-update { none; };
};
//
// 192.168.1.
zone "1.168.192.in-addr.arpa" {
  type master;
  file "/etc/named/re.192.168.1";
  allow-query { 192.168.0.0/16; };
  allow-update { none; };
};

/etc/named/zones.ゾーン名

zones.hrsk
TTL    3600       ; 60s*60m
; SOA [Authorized-Nameserver] [Admin-mail-address]
@ IN  SOA ns.hrsk. postmaster.hrsk. (
     2019050101   ; Serial
           1800   ; Refresh 60s*30m
            900   ; Retry   60s*15m
          86400   ; Expire  60s*60m*24h*1d
           1200   ; Minimum 60s*20m
) 
; NS-record : Name Servers
@        IN  NS  ns.hrsk.
; MX-record : Mail Servers
@        IN  MX  10  mail.hrsk.
; Hosts
ns       IN  A   192.168.0.xxx
mail     IN  A   192.168.0.yyy
;;
host1 	 IN  A   192.168.0.111
host2 	 IN  A   192.168.0.222

/etc/named/re.アドレス

re.192.168.0
$TTL    3600      ; 60s*60m
; SOA [Authorized-Nameserver] [Admin-mail-address] 
@  IN  SOA ns.hrsk. postmaster.mail.hrsk. (
     2019050101   ; Serial
           1800   ; Refresh   60s*30m
            900   ; Retry     60s*15m
          86400   ; Expire    60s*60m*24h*1d
           1200   ; Neg.Cashi 60s*20m
) 
; NX-record
@             IN  NS  ns.hrsk.
@             IN  MX  10  mail.hrsk.
; Hosts
xxx           IN  PTR ns.hrsk.
yyy           IN  PTR mail.hrsk.
111           IN  PTR host1.hrsk.
222           IN  PTR host2.hrsk.

firewalldの解放とbindの起動

bindの設定確認

named-checkconf 
named-checkzone ZONE-NAME ZONE-FILE

ex named-checkzone hrsk zones.hrsk
ex named-checkzone 0.168.192.in-addr.arpa re.192.168.0

firewallの解放

cat /usr/lib/firewalld/services/dns.xml

/usr/lib/firewalld/services/dns.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>DNS</short>
  <description>The Domain Name System (DNS) is used to provide and request host and domain names. Enable this option, if you plan to provide a domain name service (e.g. with bind).</description>
  <port protocol="tcp" port="53"/>
  <port protocol="udp" port="53"/>
</service>

dnsをfirewalldにサービス登録

firewall-cmd --permanent --add-service=dns 
firewall-cmd --reload
firewall-cmd --list-all 

bindの再起動

systemctl restart named

参考:bindの自動起動登録

systemctl enable named
systemctl start  named
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?