1. 目的
- 内网服务器通过设置内网DNS访问互联网
- 内网DNS服务器解析内部域名
2. 环境准备
- DNS服务器 10.0.0.88 可以正常访问互联网
- 内部服务器 10.0.0.181 设置DNS地址为10.0.0.88
3. 搭建主DNS正向解析服务器
3.1 安装bind软件和bind-unit工具
yum -y install bind bind-utils
3.2 修改配置文件
- sunmy.pro域 主DNS服务器10.0.0.181/24上实现
- sunmy.pro域 从DNS服务器10.0.0.182/24上实现
3.3 在主配置文件中设定从服务器
vim /etc/named.conf
// listen-on port 53 { 127.0.0.1; };
// allow-query { localhost; };
allow-transfer { 10.0.0.182; };
3.4定义sunmy.pro主域区域文件
- 定义名为sunmy.pro的区域
- 并且指明了区域的配置文件
vim /etc/named.rfc1912.zones
zone "sunmy.pro" IN {
type master;
file "sunmy.pro.zone";
allow-update { none; };
};
3.5 添加DNS区域数据库文件,并写入内容
[root@c7-181 ~]
data dynamic named.ca named.empty named.localhost named.loopback slaves
[root@c7-181 ~]
[root@c7-181 ~]
vim /var/named/sunmy.pro.zone
$TTL 1D
@ IN SOA master admin.sunmy.pro. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS master
NS slave
master A 10.0.0.181
slave A 10.0.0.182
www A 10.0.0.184
3.6 启动named服务并设为开机启动
chgrp named /var/named/sunmy.pro.zone
systemctl enable --now named
rndc reload
[root@c7-181 ~]
[root@c7-181 ~]
Created symlink from /etc/systemd/system/multi-user.target.wants/named.service to /usr/lib/systemd/system/named.service.
[root@c7-181 ~]
server reload successful
3.7客户端设置DNS并测试
- 局域网内任意服务器修改DNS指向10.0.0.181,测试能否解析www.sunmy.pro
[root@C6-198 ~]
[root@C6-198 ~]
Shutting down interface eth0: Device state: 3 (disconnected)
[ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Active connection state: activated
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/9
[ OK ]
[root@C6-198 ~]
nameserver 10.0.0.181
[root@C6-198 ~]
恭喜你!实验成功!<br>
最终目的是要实现在客户端10.0.0.198设置DNS为10.0.0.188的前提下<br>
客户端10.0.0.198可以访问到www.sunmy.pro WEB服务器10.0.0.184上的页面
4. 搭建从属DNS正向解析服务器
- sunmy.pro域从服务器实现主挂了从能用
C7 - 10.0.0.182
4.1 安装bind软件和bind-unit工具
yum -y install bind bind-utils
4.2 修改配置文件
- sunmy.pro域从DNS服务器在10.0.0.182/24上实现
vim /etc/named.conf
// listen-on port 53 { 127.0.0.1; };
// allow-query { localhost; };
allow-transfer { none; };
4.3 定义区域文件并指定主服务器IP
zone "sunmy.pro" IN {
type slave;
masters { 10.0.0.181; };
file "slaves/sunmy.pro.slave";
}
4.4 启动named服务并设为开机启动
systemctl start named
rndc reload
[root@c7-182 ~]
total 4
-rw-r--r-- 1 named named 310 May 6 20:27 sunmy.pro.slave
4.5 停用主服务器,测试从服务器
DEVICE=eth0
NAME=eth0
BOOTPROTO=none
ONBOOT=yes
IPADDR=10.0.0.198
PREFIX=24
GATEWAY=10.0.0.2
DNS1=10.0.0.181
DNS2=10.0.0.182
[root@c7-181 ~]
4.6 使用dig命令测试www.sunmy.pro
[root@C6-198 ~]
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.68.rc1.el6 <<>> www.sunmy.pro
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 15174
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;www.sunmy.pro. IN A
;; ANSWER SECTION:
www.sunmy.pro. 86400 IN A 10.0.0.184
;; AUTHORITY SECTION:
sunmy.pro. 86400 IN NS master.sunmy.pro.
sunmy.pro. 86400 IN NS slave.sunmy.pro.
;; ADDITIONAL SECTION:
master.sunmy.pro. 86400 IN A 10.0.0.181
slave.sunmy.pro. 86400 IN A 10.0.0.182
;; Query time: 3 msec
;; SERVER: 10.0.0.182
;; WHEN: Fri May 7 04:42:53 2021
;; MSG SIZE rcvd: 120
从服务器已生效
|