4
7

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 1 year has passed since last update.

【Linux】DNSサーバ構築

Posted at

・パッケージのインストール

# dnf install -y bind bind-chroot bind-utils

・named-chrootの起動と自動起動設定

# systemctl enable --now named-chroot

・namedが停止していて自動起動設定がdisableになっていることを確認

# systemctl status named
# systemctl is-enabled named

・named-chrootが起動していて自動起動設定がenableになっていることを確認

# systemctl status named-chroot
# systemctl is-enabled named-chroot

・chroot化の設定

# /usr/libexec/setup-named-chroot.sh /var/named/chroot on
vi /etc/sysconfig/named
↓
ROOTDIR=/var/named/chroot

・正引きのゾーンファイルの作成
ゾーンファイルは、上記をコピーペースをしてもなぜか書式が間違っていてnamed-chrootを起動できないことがあるため、「/var/named/named.localhost」をコピーしてそれを編集することで正確にゾーンファイルを作成することができる

/var/named/example.local
$TTL 1D
@       IN SOA  @ ns.example.local. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
                    IN      NS      ns.example.local.
example.local.      IN      A       192.168.10.107
ns                  IN      A       192.168.10.107
web                 IN      CNAME   test.local.

・逆引きのゾーンファイルの作成
ゾーンファイルは、上記をコピーペースをしてもなぜか書式が間違っていてnamed-chrootを起動できないことがあるため、「/var/named/named.loopback」をコピーしてそれを編集することで正確にゾーンファイルを作成することができる

/var/named/rev-example.local
$TTL 1D
@       IN SOA  @ ns.example.local. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        A       192.168.10.107
107     PTR     example.local.
107     PTR     ns

・named.confのバックアップ

# cp -ip /etc/named.conf /etc/named.conf.org

・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.
//

options {
        listen-on port 53 { 192.168.10.107; };
        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";
        secroots-file   "/var/named/data/named.secroots";
        recursing-file  "/var/named/data/named.recursing";
        allow-query     { any; };

        /*
         - 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;

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

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

        /* https://fedoraproject.org/wiki/Changes/CryptoPolicy */
        include "/etc/crypto-policies/back-ends/bind.config";
};

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

zone "10.168.192.in-addr.arpa" IN {
        type master;
        file "rev-example.local";
        allow-update { none; };
};

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

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

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

・サービス再起動と起動確認

systemctl restart named-chroot && systemctl status named-chroot
4
7
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
4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?