目录
1、部署主机
- YN101-21.host.com
2、安装部署bind9
#安装bind
yum install bind -y
#查看是否安装成功
[root@yn101-21 ~]# rpm -qa bind
#输出如下
bind-9.11.4-9.P2.el7.x86_64
3、配置主配置文件
修改named.conf配置文件
vi /etc/named.conf
#文件内容:
options {
listen-on port 53 { 192.168.101.21; }; #修改为本机ip地址
listen-on-v6 port 53 { ::1; }; #删除ipv6地址
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 { any; }; #改为any,允许所有ip进行查询
forwarders { 192.168.101.1; }; #增加该行配置,上一级DNS地址,网关地址
recursion yes; #DNS采用递归的算法
dnssec-enable yes; #改为no
dnssec-validation yes; #改为no
检查配置文件,无任何输出说明配置文件格式正确
named-checkconf /etc/named.conf
4、配置区域配置文件
修改区域配置文件,将以下配置添加到配置文件中,分别配置了主机域和业务域
vi /etc/named.rfc1912.zones
#新增内容
zone "host.com" IN {
type master;
file "host.com.zone";
allow-update { 192.168.101.21; };
};
zone "yn.com" IN {
type master;
file "yn.com.zone";
allow-update { 192.168.101.21; };
};
检查配置文件,无错误信息输出说明配置正确
named-checkzone /etc/named.rfc1912.zones
5、配置区域数据文件
配置主机域数据文件,在/var/named/目录下新建host.com.zone配置文件
vi /var/named/host.com.zone
#将以下配置文件粘贴到新建文件里面,;表示注释
$ORIGIN host.com.
$TTL 600 ; 10 minutes
@ IN SOA dns.host.com. dnsadmin.host.com. (
2020021501 ; serial
10800 ; refresh (3 hours)
900 ; retry (15 minutes)
604800 ; expire (1 week)
86400 ; minimum (1 day)
)
NS dns.host.com.
$TTL 60 ; 1 minute
dns A 192.168.101.21
YN101-21 A 192.168.101.21
YN101-22 A 192.168.101.22
YN101-31 A 192.168.101.31
YN101-32 A 192.168.101.32
YN101-100 A 192.168.101.100
配置业务域数据文件,在/var/named/目录下新建yn.com.zone配置文件
vi /var/named/yn.com.zone
#将以下配置文件粘贴到新建文件里面,;表示注释
$ORIGIN yn.com.
$TTL 600 ; 10 minutes
@ IN SOA dns.yn.com. dnsadmin.yn.com. (
2020021501 ; serial
10800 ; refresh (3 hours)
900 ; retry (15 minutes)
604800 ; expire (1 week)
86400 ; minimum (1 day)
)
NS dns.yn.com.
$TTL 60 ; 1 minute
dns A 192.168.101.21
验证区域数据文件
[root@yn101-21 ~]# named-checkzone host.com /var/named/host.com.zone
zone host.com/IN: loaded serial 2020021501
OK
[root@yn101-21 ~]# named-checkzone yn.com /var/named/yn.com.zone
zone yn.com/IN: loaded serial 2020021501
OK
6、启动服务
启动bind
systemctl start named
systemctl enable named
启动报错,重点检查配置文件格式(空格,分号等),因为配置文件格式要求严格
#配置文件错误,启动报错
#systemctl status named查看报错信息
[root@yn101-21 ~]# systemctl start named
Job for named.service failed because the control process exited with error code. See "systemctl status named.service" and "journalctl -xe" for details.
查看DNS服务是否启动成功
#查看DNS服务是否启动
[root@yn101-21 ~]# netstat -luntp|grep 53
tcp 0 0 192.168.101.21:53 0.0.0.0:* LISTEN 26587/named
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 26587/named
tcp6 0 0 :::53 :::* LISTEN 26587/named
tcp6 0 0 ::1:953 :::* LISTEN 26587/named
udp 0 0 192.168.101.21:53 0.0.0.0:* 26587/named
udp6 0 0 :::53 :::* 26587/named
检查是否正常解析
[root@yn101-21 ~]# dig -t A YN101-22.host.com @192.168.101.21 +short
192.168.101.22
查看配置/etc/resolv.conf是否有search host.com,如果没有新增一行search host.com
cat /etc/resolv.conf
#Generated by NetworkManager
search host.com #新增
nameserver 192.168.101.21
修改DNS1,将所有服务器的DNS1改为192.168.101.21,分别ping YN101-22(所有服务器都能ping通)和baidu.com,如果能ping通说明配置成功。
7、window配置
修改VMnet8的DNS服务为192.168.101.21,因为项目要在浏览器中进行访问。设置完成后ping yn101-22.host.com,ping通配置成。如果ping不通,可修改本地网络的DNS测试。