角色 | IP |
---|---|
客户端 | 192.168.20.131 |
DNS服务器 | 192.168.20.132 |
web服务器 | 192.168.20.133 |
[root@localhost ~]# yum -y install httpd
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
95 ServerName www.test.com
# 取消注释 并设置域名为www.test.com
[root@localhost ~]# systemctl start httpd
安装
[root@localhost ~]# yum -y install bind
配置修改
[root@localhost ~]# vim /etc/named.conf
13 listen-on port 53 { any; }; #监听的端口和主机
21 allow-query { any; };#允许谁对DNS进行域名查询
35 //dnssec-enable yes; #用//注释
36 //dnssec-validation yes;#用//注释
60 //include "/etc/named.root.key"; #不需要再加载/etc/named.root.key 此行注释
dnssec可以为DNS数据提供来源验证,为数据提供完整性验证,为查询提供否定存在验证
配置文件中出现include 表示配置要在include的地方加载 include指定的文件内容
正向解析和反向解析的设置
[root@localhost ~]# vim /etc/named.rfc1912.zones
#文件末尾追加以下内容
zone "test.com" IN {
type master;
file "test.com.zone";
allow-update { none; };
};
zone "20.168.192.in-addr.arpa" IN {
type master;
file "fanxiang.arpa";
allow-update { none; };
};
编辑正向解析和反向解析的文件
[root@localhost ~]# cd /var/named/
[root@localhost named]# cp -p named.localhost test.com.zone
[root@localhost named]# vim test.com.zone
$TTL 1D
@ IN SOA test.com. admin.test.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
AAAA ::1
www IN A 192.168.20.133
ftp IN A 192.168.20.133
news IN A 192.168.20.133
参数释义
@ 代表当前解析的域
SOA 表示起始授权记录
test.com. 解析的域
admin.test.com. 管理员邮箱地址
serials 当主服务器的解析库发生变化 此序列号会+1
refresh 从服务器向master请求同步解析记录的时间间隔
retry 如果请求同步解析记录失败 再次尝试的时间间隔
expire 当从服务器联系不上主服务器的时候 多久会停止服务
minimum 不存在的记录缓存的时间是多长
[root@localhost named]# cp -p test.com.zone fanxiang.arpa
[root@localhost named]# vim fanxiang.arpa
$TTL 1D
@ IN SOA test.com. admin.test.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 127.0.0.1
AAAA ::1
133 IN PTR www.test.com
133 IN PTR ftp.test.com
133 IN PTR news.test.com
检测语法并启动服务
[root@localhost named]# named-checkconf /etc/named.conf
[root@localhost named]# named-checkconf /etc/named.rfc1912.zones
[root@localhost named]# named-checkzone test.com test.com.zone
zone test.com/IN: loaded serial 0
OK
[root@localhost named]# named-checkzone test.com fanxiang.arpa
zone test.com/IN: loaded serial 0
OK
[root@localhost named]# systemctl start named
为客户端设置DNS服务器
[root@localhost ~]# vim /etc/resolv.conf
nameserver 192.168.20.132
# nameserver不能少 空格 后边写上DNS服务器ip
客户端检测域名解析是否正常
[root@localhost ~]# yum -y install bind-utils
[root@localhost ~]# nslookup www.test.com
Server: 192.168.20.132
Address: 192.168.20.132#53
Name: www.test.com
Address: 192.168.20.133
客户端也可以直接访问www.test.com这个域名
firefox http://www.test.com
由于主机数量的限制 我们将从服务器搭建在web服务器上
修改DNS主服务器(192.168.20.132)的设置 并重启服务
[root@localhost named]# vim /etc/named.rfc1912.zones
zone "test.com" IN {
type master;
file "test.com.zone";
allow-transfer { 192.168.20.133; }; #加上这行
allow-update { none; };
};
zone "20.168.192.in-addr.arpa" IN {
type master;
file "fanxiang.arpa";
allow-transfer { 192.168.20.133; };#加上这行
allow-update { none; };
};
[root@localhost named]# named-checkconf /etc/named.rfc1912.zones
[root@localhost named]# systemctl restart named
安装、配置、启动DNS从服务器
[root@localhost ~]# yum -y install bind
[root@localhost ~]# vim /etc/named.conf
13 listen-on port 53 { any; }; #监听的端口和主机
21 allow-query { any; };#允许谁对DNS进行域名查询
35 //dnssec-enable yes; #用//注释
36 //dnssec-validation yes;#用//注释
60 //include "/etc/named.root.key"; #不需要再加载/etc/named.root.key 此行注释
[root@localhost ~]# vim /etc/named.rfc1912.zones #文件末尾 追加内容 如下
zone "test.com" IN {
type slave;
masters { 192.168.20.132; };
file "slaves/test.com.zone";
};
zone "20.168.192.in-addr.arpa" IN {
type slave;
masters { 192.168.20.132; };
file "slaves/fanxiang.arpa";
};
[root@localhost ~]# named-checkconf /etc/named.conf
[root@localhost ~]# named-checkconf /etc/named.rfc1912.zones
[root@localhost ~]# systemctl start named
为客户端设置DNS从服务器ip
[root@localhost ~]# vim /etc/resolv.conf
nameserver 192.168.20.133
[root@localhost ~]# nslookup www.test.com
Server: 192.168.20.133
Address: 192.168.20.133#53
Name: www.test.com
Address: 192.168.20.133
从上述结果可以看出 现在提供域名解析的服务器时133 说明DNS从服务器工作正常