本文介绍RedHat 6简单配置DNS服务器,主要包括主从同步与正反向解析。
一、测试环境
主DNS服务器:DNS01:192.168.10.1
从DNS服务器:DNS02:192.168.10.2
操作系统:Red Hat Enterprise Linux Server release 6.5
二、安装配置主DNS服务器
1、在dns01安装所需的包,其中bind包提供域名服务的主要程序及相关文件。bind-chroot包提供一个伪根目录,使得bind被限制在这个牢笼中运行,保护真正的根目录以增强安全性,安装后伪根目录为/var/named/chroot目录。bind-utils包则是提供一些工具,如dig、host、nslookup、nsupdate等。
[[email protected] ~]# yum install -y bind bind-chroot bind-utils
[[email protected] ~]# rpm -qa bind bind-chroot bind-utils
2、拷贝bind的模板文件
[[email protected] ~]# cp -rv /usr/share/doc/bind-9.8.2/sample/etc/* /var/named/chroot/etc/
[[email protected] ~]# cp -rv /usr/share/doc/bind-9.8.2/sample/var/* /var/named/chroot/var/
3、修改named配置文件,为了简单易懂,在这里我们只写上基础的参数,实现最基本的DNS功能。
[[email protected] ~]# vi /var/named/chroot/etc/named.conf
options { // Put files that named is allowed to write in the data/ directory: directory "/var/named"; // "Working" directory listen-on port 53 { any; }; allow-query { any; }; allow-query-cache { any; }; allow-transfer {192.168.10.2; }; //允许传送的从服务器地址 notify yes; also-notify {192.168.10.2; }; //DNS记录发生更新时通知从服务器 }; zone "jiangjianlong.cn"{ //正向解析区域 type master; file "jiangjianlong.cn.zone"; }; zone "10.168.192.in-addr.arpa"{ //反向解析区域 type master; file "10.168.192.ptr"; };
4、修改正向解析区域配置文件,以named.localhost为模板复制一份进行修改即可.
[[email protected] ~]# cd /var/named/chroot/var/named/
[[email protected] named]# cp named.localhost jiangjianlong.cn.zone
[[email protected] named]# vi jiangjianlong.cn.zone
$TTL 1D @ IN SOA @ rname.invalid. ( 1 ; serial 1M ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS @ A 127.0.0.1 AAAA ::1 www IN A 192.168.10.11 web IN CNAME www dns01 IN A 192.168.10.1 dns02 IN A 192.168.10.2
5、配置反向解析区域配置文件,以named.loopback为模板复制一份进行修改即可
[[email protected] named]# cp named.loopback 10.168.192.ptr
[[email protected] named]# vi 10.168.192.ptr
$TTL 1D @ IN SOA @ rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS @ A 127.0.0.1 AAAA ::1 PTR localhost. 1 IN PTR dns01.jiangjianlong.cn. 2 IN PTR dns02.jiangjianlong.cn. 11 IN PTR www.jiangjianlong.cn.
6、修改named目录的属主和属组为named
[[email protected] var]# chown -R named:named /var/named/chroot/var/named/
[[email protected] var]# ll /var/named/chroot/var/named/
total 40
-rw-r--r-- 1 named named 287 Apr 27 15:31 10.168.192.ptr
drwxr-xr-x 2 named named 4096 Apr 16 17:34 data
-rw-r--r-- 1 named named 264 Apr 27 15:40 jiangjianlong.cn.zone
-rw-r--r-- 1 named named 56 Apr 16 17:34 my.external.zone.db
-rw-r--r-- 1 named named 56 Apr 16 17:34 my.internal.zone.db
-rw-r--r-- 1 named named 1892 Apr 16 17:34 named.ca
-rw-r--r-- 1 named named 152 Apr 16 17:34 named.empty
-rw-r--r-- 1 named named 152 Apr 16 17:34 named.localhost
-rw-r--r-- 1 named named 168 Apr 16 17:34 named.loopback
drwxr-xr-x 2 named named 4096 Apr 16 17:34 slaves
7、检查配置文件是否无误
[[email protected] named]# named-checkzone jiangjianlong.cn jiangjianlong.cn.zone
zone jiangjianlong.cn/IN: loaded serial 1
OK
[[email protected] named]# named-checkzone jiangjianlong.cn 10.168.192.ptr
zone jiangjianlong.cn/IN: loaded serial 0
OK
[[email protected] named]# named-checkconf /var/named/chroot/etc/named.conf
[[email protected] named]#
8、启动named服务
[[email protected] named]# service named start
9、设置named服务开机启动
[[email protected] named]# chkconfg named on
10、在DNS01本机使用host命令测试正反向解析,均正常解析
11、在DNS01本机使用dig命令测试正反向解析,均正常解析
12、在DNS01本机使用nslookup命令测试正反向解析,均正常解析
13、使用windows计算机配置DNS服务器为DNS01的IP,使用nslookup命令测试正反向解析,均正常解析。
三、安装配置从DNS服务器
1、在dns02安装所需的包,跟在dns01上安装的一样。
[[email protected] ~]# yum install -y bind bind-chroot bind-utils
[[email protected] ~]# rpm -qa bind bind-chroot bind-utils
2、编辑named配置文件。
[[email protected] ~]# vi /var/named/chroot/etc/named.conf
options { // Put files that named is allowed to write in the data/ directory: directory "/var/named"; // "Working" directory listen-on port 53 { any; }; allow-query { any; }; allow-query-cache { any; }; }; zone "jiangjianlong.cn"{ //正向解析区域 type slave; masters {192.168.10.1; }; file "slaves/jiangjianlong.cn.zone"; }; zone "10.168.192.in-addr.arpa"{ //反向解析区域 type slave; masters {192.168.10.1; }; file "slaves/10.168.192.ptr"; };
3、修改/var/named/chroot/var/named/的所有者为named用户。
[[email protected] ~]# chown -R named /var/named/chroot/var/named/
4、启动named服务,可以发现/var/named/chroot/var/named/下自动从主服务器同步了配置文件过来。
[[email protected] var]# ll named/slaves/
total 8
-rw-r--r-- 1 named named 469 Apr 27 16:48 10.168.192.ptr
-rw-r--r-- 1 named named 366 Apr 27 16:01 jiangjianlong.cn.zone
5、别忘了设置named服务开机自动启动。
6、在dns02上使用host命令、dig命令、nslookup命令测试正反向解析,均能正常解析。
7、使用windows计算机配置DNS服务器为DNS02的IP,并使用nslookup测试正反向解析,也能正常解析。