搭建环境介绍
虚拟机中仅主机模式下,同时关闭虚拟机DHCP网卡服务
关闭防火墙和SElinux情况
命令如下:
关闭防火墙:chkconfig iptables off
关闭SELinux:vim /etc/sysconfig/selinux 修改配置文件的中的为SELINUX=disabled
一、安装bind服务器
安装命令:yum -y install bind 修改配置文件:vim /etc/named.conf 为以下内容:
options {
listen-on port 53 { any; }; #修改为any
listen-on-v6 port 53 { any; }; #修改为any
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; }; #修改为any
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";
};
在修改vim /etc/named.rfc1912.zones如下:
#下面为正向解析模板
zone "www.gaoda.com" IN {
#要解析的服务器的域名
type master;
file "gaoda.localhost";
#修改为域名.localhost
allow-update { none; };
};
#下面为反向解析模板
zone "88.168.192.in-addr.arpa" IN {
#www服务器的IP地址,需要注意的这里要反向写
type master;
file "gaoda.loopback";
#修改为域名。loopback
allow-update { none; };
};
接着在:/var/named/ 下创建 gaoda.localhost(正向解析配置文件))、 gaoda.loopback(反向解析配置文件)
[root@Cent0S-03 ~]# cd /var/named/
[root@Cent0S-03 named]# ls
data dynamic named.ca named.empty named.localhost named.loopback slaves
[root@Cent0S-03 named]# cp -a named.localhost gaoda.localhost
[root@Cent0S-03 named]# cp -a named.loopback gaoda.loopback
修改正向解析配置文件内容:gaoda.localhost
$TTL 1D
@ IN SOA gaoda.com. rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.gaoda.com.
dns A 192.168.88.20
www A 192.168.88.30
修改反向解析配置文件内容:gaoda.loopback
$TTL 1D
@ IN SOA gaoda.com. rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.gaoda.com.
20 PTR dns.gaoda.com.
30 PTR dns.gaoda.com.
启动DNS服务器:service named start
二、主从服务器
主服务器设置
主配置文件:vim /etc/named.conf
listen-on port 53 { 192.168.88.20; }; #主服务IP地址,也可以不设置
区域配置文件/etc/named.rfc1912.zones 修改为
zone "gaoda.com" IN {
type master;
file "gaoda.localhost";
allow-update { 192.168.88.40; }; #从服务的地址
};
修改配置数据文件/var/named//var/named/
$TTL 1D
@ IN SOA gaoda.com. rname.invalid. (
1 ; serial #修改为1。
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.gaoda.com.
dns A 192.168.88.20
www A 192.168.88.30
从服务器设置
主配置文件:vim /etc/named.conf
listen-on port 53 { 192.168.88.40; }; #从服务的IP地址
区域配置文件/etc/named.rfc1912.zones 修改为
zone "gaoda.com" IN {
type slave;
masters{ 192.168.88.20; };
file "slaves/gaoda.localhost";
allow-update { none; };
};
#从配置文件的类型需要修改为 slave,并且需要填写主服务器的地址.如下:
# type slave;
# masters { 192.168.88.20; };大括号两侧留有空格
重新启动主从NDS服务器:service named restart
[root@CentOS-04 ~]# nslookup www.gaoda.com
Server: 192.168.88.40
Address: 192.168.88.40#53
Non-authoritative answer:
Name: www.gaoda.com
Address: 192.168.88.30
三、缓存服务器
缓存服务器
安装软件:yum -y install dnsmasq
配置文件/etc/dnsmasq.conf修改或者添加以下
domain=gaoda.com #需要解析的域名
server=192.168.88.20 #主 DNS 服务器 IP
cache-size=15000 #声明缓存条数
重新启动缓存服务器:service dnsmasq restart
关闭主NDS服务器,通过客户端来验证缓存服务器来是否启动:
[root@CentOS-04 ~]# nslookup www.gaoda.com
Server: 192.168.88.40
Address: 192.168.88.40#53
Non-authoritative answer: #缓存服务器启动成功
Name: www.gaoda.com
Address: 192.168.88.30
四、DNS智能服务器
实验环境:
一台内网测试机(单网卡) 网关和NDS为DNS服务器的网段
一台网关+DNS(双网卡)
一台外网测试机(单网卡) 网关和NDS为DNS服务器的网段
一台 web 服务器(双网卡)
DNS服务器:
1、开启路由转发功能,修改配置文件 /etc/sysctl.conf 里面的为 net.ipv4.ip_forward = 1
2、修改主配置文件:/etc/named.conf
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { any; };
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; };
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";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
view lan {
match-clients { 192.168.88.0/24; };
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/lan.zones";
};
view wan {
match-clients { any; };
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/wan.zones";
};
#include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
3、复制配置文件为上一步创建的文件名称
[root@CentOS-05 etc]# cp -a named.rfc1912.zones lan.zones
[root@CentOS-05 etc]# cp -a named.rfc1912.zones wan.zones
lan.zones的修改
zone "gaoda.com" IN {
type master;
file "lan.localhost";
allow-update { none; };
};
wan.zones的修改
zone "gaoda.com" IN {
type master;
file "wan.localhost";
allow-update { none; };
};
4、在/var/named/创建 lan.localhost和wan.localhost文件
lan.localhost配置文件内容
$TTL 1D
@ IN SOA gaoda.com. rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.gaoda.com.
dns A 192.168.88.20
www A 192.168.88.30
wan.localhost配置文件内容
$TTL 1D
@ IN SOA gaoda.com. rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns.gaoda.com.
dns A 100.100.100.20
www A 100.100.100.30
5、重新启动服务:service named restart