安装
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 mastermaster 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后测试
反向解析
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: 146root@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 #查看区域数据库文件是否生成
dig -t axfr luohw.org
主从同步原理
使用别名
[root@rocky8 named]# cat luohw.org.zone
$TTL 1D
@ IN SOA master admin.luohw.org (20231030 1M 10M 1D 6H)NS mastermaster A 192.168.1.252
db A 192.168.1.188
node1 A 2.2.2.2
mm A 192.168.1.253
lo A 192.168.1.22
@ MX 10 mail1
@ MX 20 mail2
websrv A 192.168.1.20
lo A 192.168.1.22
www CNAME websrv * A 192.168.1.25 #泛域名
@ A 192.168.1.22#访问其他没有解析网站默认跳到这个