linux下安裝dns域名解析伺服器

小小小沐風~發表於2020-11-28

linux下安裝dns域名解析伺服器

系統:Red Hat Enterprise Linux 8.2

1、基本安裝

[root@localhost /]# dnf install bind-chroot bind bind-utils bind-libs bind-devel  -y

2、拷貝sample檔案

[root@localhost /]# cp -rf /usr/share/doc/bind/sample/* /var/named/

3、建立相關檔案

[root@localhost etc]# touch /var/named/chroot/var/named/data/cache_dump.db
[root@localhost etc]# touch /var/named/chroot/var/named/data/named_stats.txt
[root@localhost etc]# touch /var/named/chroot/var/named/data/named_mem_stats.txt
[root@localhost etc]# touch /var/named/chroot/var/named/data/named.run
[root@localhost etc]# mkdir /var/named/chroot/var/named/dynamic
[root@localhost etc]# touch /var/named/chroot/var/named/dynamic/managed-keys.bind

4、相關檔案許可權

[root@localhost etc]# chmod -R 777 /var/named/chroot/var/named/data
[root@localhost etc]# chmod -R 777 /var/named/chroot/var/named/dynamic

5、修改主配置檔案

[root@localhost etc]# vim /var/named/chroot/etc/named.conf 

options
{
        directory               "/var/named";           // "Working" directory
        dump-file               "data/cache_dump.db";
        statistics-file         "data/named_stats.txt";
        memstatistics-file      "data/named_mem_stats.txt";
        secroots-file           "data/named.secroots";
        recursing-file          "data/named.recursing";
        listen-on port 53       { any; };

        listen-on-v6 port 53    { ::1; };

  
        allow-query             { any; };
        allow-query-cache       { localhost; };
        recursion yes;

        dnssec-enable yes;

        dnssec-validation yes;

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

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

    include "/etc/crypto-policies/back-ends/bind.config";
};

zone "mufeng.com" IN {
        type master;
        file "mufeng.com";
};

zone "35.35.192.in-addr.arpa"{
        type master;
        file "192.arpa.zone";
};

6、修改區域配置檔案

[root@localhost named]# cp named.localhost ygx.com
[root@localhost named]# vim mufeng.com 

$TTL 1D
@       IN SOA  mufeng.com. admin.mufeng.com. (
                                        2020    ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
@       IN      NS      ns.mufeng.com.
        IN      A       192.35.35.1
ns      IN      A       192.35.35.1
www     IN      A       192.35.35.1

[root@localhost named]# cp mufeng.com 192.arpa.zone
[root@localhost named]# vim 192.arpa.zone 

$TTL 1D
@       IN SOA  mufeng.com. admin.mufeng.com. (
                                        2020    ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
@       IN      NS      ns.mufeng.com.
1       IN      PTR     ns.mufeng.com.
1       IN      PTR     www.mufeng.com.

[root@localhost named]# pwd
/var/named/chroot/var/named

7、防火牆以及selinux配置

[root@localhost named]# firewall-cmd  --add-port=53/tcp --permanent 
success

[root@localhost named]# firewall-cmd  --add-service=dns  --permanent 
success

[root@localhost named]# firewall-cmd  --reload 
success

[root@localhost named]# getsebool -a | grep named
named_tcp_bind_http_port --> off
named_write_master_zones --> on

[root@localhost named]# setsebool named_tcp_bind_http_port on

[root@localhost named]# getsebool -a | grep named
named_tcp_bind_http_port --> on
named_write_master_zones --> on

8、開機自動啟動bind-chroot

[root@localhost named]# /usr/libexec/setup-named-chroot.sh /var/named/chroot on
[root@localhost named]# systemctl disable named
[root@localhost named]# systemctl start named-chroot
[root@localhost named]# systemctl enable named-chroot
Created symlink /etc/systemd/system/multi-user.target.wants/named-chroot.service → /usr/lib/systemd/system/named-chroot.service.

9、驗證dns伺服器是否安裝成功

9.1 開啟bind-chroot服務

[root@localhost named]# systemctl start named-chroot

9.2 修改域名解析檔案

[root@localhost named]# vim /etc/resolv.conf 

# Generated by NetworkManager
search localdomain
nameserver 192.35.35.1

9.3 驗證是否配置成功

[root@localhost named]# nslookup www.mufeng.com
Server:		192.35.35.1
Address:	192.35.35.1#53

Name:	www.mufeng.com
Address: 192.35.35.1

[root@localhost named]# nslookup 192.35.35.1
1.35.35.192.in-addr.arpa	name = www.mufeng.com.
1.35.35.192.in-addr.arpa	name = ns.mufeng.com.

相關文章