1. 规划节点
部署主从节点DNS服务的节点规划
IP | 主机名 | 节点 |
192.168.100.10 | master | 主DNS服务器 |
192.168.100.20 | slave | 从DNS服务器 |
2. 基础准备
使用VMWare Workstation软件安装CentOS 7.2操作系统,镜像使用提供的 CentOS-7-x86_64-DVD-1511.iso,最小化CentOS 7.2虚拟机两台。YUM源使用本 地CetnOS 7.2系统源。
1. 配置YUM源(两个节点)
(1)YUM源备份
[root@master ~]# mv /etc/yum.repos.d/* /media/
[root@slave ~]# mv /etc/yum.repos.d/* /media/
(2)创建repo文件
[root@master ~]# mkdir /opt/centos
[root@master ~]# mount /dev/sr0 /opt/centos/
mount: /dev/sr0 is write-protected, mounting read-only
[root@master ~]# vi /etc/yum.repos.d/local.repo
[root@master ~]# cat /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1
[root@slave ~]# mkdir /opt/centos
[root@slave ~]# mount /dev/sr0 /opt/centos/
mount: /dev/sr0 is write-protected, mounting read-only
[root@slave ~]# vi /etc/yum.repos.d/local.repo
[root@slave ~]# cat /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1
(3)测试YUM源配置
[root@master ~]# yum list
(4)关闭防火墙和SELinux
[root@master ~]# setenforce 0
[root@master ~]# systemctl stop firewalld
[root@slave ~]# setenforce 0
[root@slave ~]# systemctl stop firewalld
2. 安装配置DNS软件BIND(两个 节点)
使用如下命令安装bind-chroot DNS服务 器,示例结果如图所示。
[root@master ~]# yum install bind-chroot bind-utils -y
[root@slave ~]# yum install bind-chroot bind-utils -y
通过rpm -ql bind-chroot查询所安装的文件。
进入bind-chroot目录。
拷贝bind相关文件,准备bind-chroot环境:
[root@master chroot]# cp -R /usr/share/doc/bind-9.9.4/sample/etc/* /var/named/chroot/etc/
[root@master chroot]# cp -R /usr/share/doc/bind-9.9.4/sample/var/* /var/named/chroot/var/
创建dynamic目录,将bind文件设置为可写,如图所示。
[root@master chroot]# cd var/named/
[root@master named]# chmod -R 777 /var/named/chroot/var/named/data/
[root@master named]# mkdir dynamic
[root@master named]# chmod -R 777 /var/named/chroot/var/named/dynamic/
将DNS服务named.conf文件拷贝到bind-chroot目录中。
[root@master named]# cp /etc/named.conf /var/named/chroot/etc/named.conf
cp: overwrite ‘/var/named/chroot/etc/named.conf’? y
编辑配置文件named.conf, 具体示例代码如下:
[root@master named]# cat /var/named/chroot/etc/named.conf
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//options {listen-on port 53 { any; };listen-on-v6 port 53 { ::1; };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";allow-query { any; };/*- If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.- If you are building a RECURSIVE (caching) DNS server, you need to enablerecursion.- If your recursive DNS server has a public IP address, you MUST enable accesscontrol to limit queries to your legitimate users. Failing to do so willcause your server to become part of large scale DNS amplificationattacks. Implementing BCP38 within your network would greatlyreduce such attack surface*/recursion yes;dnssec-enable yes;dnssec-validation yes;/* Path to ISC DLV key */bindkeys-file "/etc/named.iscdlv.key";managed-keys-directory "/var/named/dynamic";pid-file "/run/named/named.pid";session-keyfile "/run/named/session.key";
};logging {channel default_debug {file "data/named.run";severity dynamic;};
};zone "test.com" {type master;file "test.com.zon";
};include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
设置named.conf文件的用户权限为named,示例代码如下:
[root@master named]# chown named /var/named/chroot/etc/named.conf
创建转发域
拷贝模板文件named.localhost 到test.com.zon,示例代码如下:
[root@master named]# cp /var/named/named.localhost /var/named/chroot/var/named/test.com.zon
编辑test.com.zon文件,示例代码如下:
[root@master named]# cat test.com.zon
$TTL 1D
$ORIGIN test.com.
@ IN SOA test.com. admin.test.com. (2024002; serial1D ; refresh1H ; retry1W ; expire3H ; minimum
)IN NS ns1.test.com.
ns1 IN A 192.168.100.11
www IN A 192.168.100.10
ftp IN A 192.168.100.10
赋予test.com.zon所有权限,命令如下:
[root@master named]# chmod -R 777 test.com.zon
检查配置,如图所示。
[root@master named]# named-checkconf /var/named/chroot/etc/named.conf
[root@master named]# named-checkzone test.com test.com.zon
配置服务
设置主机时间,示例代码如下:
[root@master named]# date -s 20:58:00
关闭named服务,取消开机启动,命令如下:
[root@master named]# systemctl stop named
[root@master named]# systemctl disable named
设置bind-chroot服务开机启动,并重启。
[root@master named]# systemctl enable named-chroot
Created symlink from /etc/systemd/system/multi-user.target.wants/named-chroot.service to /usr/lib/systemd/system/named-chroot.service.
[root@master named]# systemctl restart named-chroot
查看bind-chroot服务状态,如图所示。
配置主机DNS服务器。
使用bind基本命令重载主配置文件和区域解析库文件,如图所示。
[root@master named]# rndc reload
[root@master named]# rndc reload test.com
[root@master named]# rndc notify test.com
[root@master named]# rndc reconfig
测试DNS解析是否正常,如图所示。
3. 配置主从DNS
在Master上操作,修改Master的 named.conf配置文件
在Master编辑主服务器解析库文件,添加解析记录,示例代码如下。
重新加载配置文件。
在slave上操作,修改slave服务器上的named.conf文件,示例代码如下:
设置slaves目录权限和目录的所有者为named用户,示例代码如下。
检查语法,并在master和slave重启服务。
[root@slave ~]# named-checkconf /var/named/chroot/etc/named.conf
[root@slave ~]# systemctl restart named-chroot
查看从服务器是否有文件同步进来,如图所示。
在master主机用从服务器解析,(@后面指定DNS服务器的地址,就可以不用改本机的DNS了), 解析到www2域名,表明配置成功。