dns服务

安装
apt install bind9 bind9-utils

监听53端口
udp53做解析用的

tcp53端口
创建配置文件
[root@rocky8 ~]# cd /var/named/

[root@rocky8 named]# touch luohw.org.zone
[root@rocky8 named]# chmod 640 luohw.org.zone
[root@rocky8 named]# chgrp named luohw.org.zone

修改配置文件
vim /etc/named.conf
#注释掉下面两行
// listen-on port 53 { 127.0.0.1; };
// allow-query { localhost; };

添加配置文件
[root@rocky8 named]# vi luohw.org.zone 
$TTL 1D
@       IN     SOA    master   admin.luohw.org (20231019 3H 10M 1D 6H)
luohw.org.      NS      master

master          A       192.168.1.252
db              A       192.168.1.188
node1           A       2.2.2.2
mm              A       192.168.1.253




主配置文件/etc/named.conf

我在include文件中添加

添加配置
vi /etc/named.rfc1912.zones 
zone   "luohw.org" {
        type master;
        file "luohw.org.zone";
};



语法检查

客户端测试
添加配置指定dns服务器
nameserver 192.168.1.252
测试
root@ubuntu20:/etc/bind# host node1.luohw.org
node1.luohw.org has address 2.2.2.2

在windows修改dns后测试

dns服务_第1张图片

反向解析

vi  /etc/named.rfc1912.zones 
zone "0.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.1.zone";
        allow-update { none; };
};

[root@rocky8 ~]# cd /var/named/

[root@rocky8 named]# cat  192.168.1.zone 
$TTL 1D
@	IN     SOA    master   admin.luohw.org (20231019 3H 10M 1D 6H)
		NS	master
18 		PTR	www.luohw.org.
28		PTR	db.luohw.org.
master		A	192.168.1.252

测试
在192.168.1.253测试


添加
cat  /etc/resolv.conf
nameserver 192.168.1.252


解析dns
root@ubuntu20:~# dig -x 192.168.0.18

; <<>> DiG 9.16.1-Ubuntu <<>> -x 192.168.0.18
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63993
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: 5881bad52ff912121357fb5065318ab943f252f9cbbd5169 (good)
;; QUESTION SECTION:
;18.0.168.192.in-addr.arpa.	IN	PTR

;; ANSWER SECTION:
18.0.168.192.in-addr.arpa. 86400 IN	PTR	www.luohw.org.

;; AUTHORITY SECTION:
0.168.192.in-addr.arpa.	86400	IN	NS	master.0.168.192.in-addr.arpa.

;; ADDITIONAL SECTION:
master.0.168.192.in-addr.arpa. 86400 IN	A	192.168.1.252

;; Query time: 4 msec
;; SERVER: 192.168.1.252#53(192.168.1.252)
;; WHEN: Sat Oct 21 10:24:17 CST 2023
;; MSG SIZE  rcvd: 146

root@ubuntu20:~# host 192.168.0.18
18.0.168.192.in-addr.arpa domain name pointer www.luohw.org.

配置从服务器

yum install bind -y
vim /etc/named.conf
// listen-on port 53 { 127.0.0.1; };
// allow-query     { localhost; };
#不允许其它主机进行区域传输
   allow-transfer { none;};
vim /etc/named.rfc1912.zones
zone "magedu.org" {
   type slave;
   masters { 主服务器IP;};                                                       
         
   file "slaves/magedu.org.slave";
};



systemctl start named          #第一次启动服务
rndc reload                    #不是第一次启动服务
ls /var/named/slaves/magedu.org.slave #查看区域数据库文件是否生成

你可能感兴趣的:(dns)