CentOSにDNSサーバを立てる!BINDの設定方法!

スポンサーリンク
050-VBA

へっぽこヘタレシステム管理者の管理人です。

今回は、CentOSにWordPressを立てるに引き続き・・・

DNSサーバ立ててみましたので忘備録として掲載しておきます。

CentOSにBINDをインストール

まずは、CentOSにDNSサーバ【BIND】をインストールします。

yum -y install bind
yum -y install bind-utils

後から手こずりましたが・・・

管理人の環境ではどうにもエラーが出るため、一度アンインストールしてから、再度インストールしたら動きました・・・

謎です???

どうしてもダメな場合は試してみてください。

アンインストールする時は次のとおりです。

yum -y remove bind
yum -y remove bind-utils

【named.conf】を設定する

winscp等で・・・【named.conf】ファイルを設定してください。

/etc/named.conf

//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// See the BIND Administrator's Reference Manual (ARM) for details about the
// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html

options {
	//listen-on port 53 { 127.0.0.1; };	/コメントアウト
	listen-on port 53 { 192.168.178.129; };	//追加
	listen-on-v6 port 53 { ::1; };
	directory 	"/var/named";
	dump-file 	"/var/named/data/cache_dump.db";
	statistics-file "/var/named/data/named_stats.txt";
	memstatistics-file "/var/named/data/named_mem_stats.txt";
	recursing-file  "/var/named/data/named.recursing";
	secroots-file   "/var/named/data/named.secroots";
	//allow-query     { localhost; };	//コメントアウト
	allow-query     { 192.168.178.0/24; };	//追加

	forwarders{ 192.168.100.1; };	//追加


	/* 
	 - If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
	 - If you are building a RECURSIVE (caching) DNS server, you need to enable 
	   recursion. 
	 - If your recursive DNS server has a public IP address, you MUST enable access 
	   control to limit queries to your legitimate users. Failing to do so will
	   cause your server to become part of large scale DNS amplification 
	   attacks. Implementing BCP38 within your network would greatly
	   reduce such attack surface 
	*/
	recursion yes;

	dnssec-enable yes;
	dnssec-validation yes;

	/* Path to ISC DLV key */
	bindkeys-file "/etc/named.root.key";

	managed-keys-directory "/var/named/dynamic";

	pid-file "/run/named/named.pid";
	session-keyfile "/run/named/session.key";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

//追加・ここから

zone "hogehoge.test.local" IN {
        type master;
        file "hogehoge.test.local";
        allow-update { none; };
};

zone "178.168.192.in-addr.arpa" IN {
        type master;
        file "hogehoge.test.local.rev";
        allow-update { none; };
};

//追加・ここまで


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

正引・逆引ファイルを作る

次に、正引・逆引ファイルを作ります。

作るフォルダは・・・

/var/named/

です。

正引ファイル【/var/named/hogehoge.test.local】

ドメインは【hogehoge.test.local】です。

IPアドレスは、自分のIPとしています。

$TTL      86400
@         IN       SOA     server1.hogehoge.test.local.  root.hogehoge.test.local.(
                                        2020020501 ; Serial
                                        28800      ; Refresh
                                        14400      ; Retry
                                        3600000    ; Expire
                                        86400 )    ; Minimum
            IN NS server1.hogehoge.test.local.
server1   IN A 192.168.178.129

逆引ファイル【/var/named/hogehoge.test.local.rev】

$TTL      86400
@         IN       SOA     server1.hogehoge.test.local.  root.hogehoge.test.local.(
                                        2020020501 ; Serial
                                        28800      ; Refresh
                                        14400      ; Retry
                                        3600000    ; Expire
                                        86400 )    ; Minimum
     IN NS server1.hogehoge.test.local.
129   IN PTR server1.hogehoge.test.local.

【resolv.conf】を設定する

最後に【resolv.conf】を設定します。

# Generated by NetworkManager
nameserver 192.168.178.129
domain hogehoge.test.local
スポンサーリンク

ファイアウオールのポートを空ける

次にFWのポートを空けます。

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

DNSを再起動

最後にDNSを起動します。

systemctl start named
systemctl enable named
スポンサーリンク

エラーが出ない事を確認します。

設定が問題なくエラーが出る場合は、一度アンインストールして、再度インストールすると直る場合があります。

systemctl status named

テスト

最後にテストをします。

named-checkconf

ブログランキングにご協力ください!
ブログランキング・にほんブログ村へ

エラーが出なければよい

named-checkzone hogehoge.test.local /var/named/hogehoge.test.local

シリアル番号が返ればOK

named-checkzone hogehoge.test.local.rev /var/named/hogehoge.test.local.rev

シリアル番号が返ればOK

nslookup 192.168.178.129

アドレスが返ればOK

129.178.168.192.in-addr.arpa name = server1.hogehoge.test.local.

nslookup server1

アドレスが返ればOK

Address: 192.168.178.129

【named.conf】にforwadersを書いておく

【named.conf】の【options】内に【forwaders】の設定を入れておくとDNSをフォワードしてくれます。

forwarders{ 192.168.100.1; };	//追加

試して、ヤフーさんを叩いてみると・・・

しっかりとアドレスが返ってきます。

nslookup yahoo.co.jp
Server:         192.168.178.129
Address:        192.168.178.129#53

Non-authoritative answer:
Name:   yahoo.co.jp
Address: 182.22.16.251

ブログ開設に必要なドメイン取得、サーバーレンタル、ASPの登録等は、こちらのサイトから!

コメント

タイトルとURLをコピーしました