配置环境:
主服务器:Master 192.168.1.61 CentOS release 6.6
从服务器:Slave 192.168.1.62 CentOS release 6.6
子域 :Cdn 192.168.1.65 CentOS release 6.6
一、主DNS服务器配置
[[email protected] ~]# yum -y install bind
主配置文件
[[email protected] ~]# vim /etc/named.conf
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; };
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;
};
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
定义正向和反向解析域
[[email protected] ~]# vim /etc/named.rfc1912.zones
在末尾添加
zone "magedu.com" IN {
type master;
file "magedu.com.zone";
allow-transfer { 192.168.1.64; };
};
zone "1.168.192.in-addr.arpa" IN {
type master;
file "1.168.192.zone";
allow-transfer { 192.168.1.64; };
};
正向解析域
[[email protected] ~]# vim /var/named/magedu.com.zone
$TTL 86400
$ORIGIN magedu.com.
@ IN SOA ns1.magedu.com. admin.magedu.com. (
20160926
1H
5M
7D
1D )
IN NS ns1
IN NS ns2
IN MX 10 mx1
IN MX 20 mx2
IN A 192.168.1.61
cdn IN NS ns.cdn
ns.cdn IN A 192.168.1.65
ns1 IN A 192.168.1.61
ns2 IN A 192.168.1.64
mx1 IN A 192.168.1.61
mx2 IN A 192.168.1.64
www IN A 192.168.1.61
www IN A 192.168.1.64
ftp IN CNAME www
反向解析域
[[email protected] ~]# vim /var/named/1.168.192.zone
$TTL 86400
$ORIGIN 1.168.192.in-addr.arpa.
@ IN SOA ns1.magedu.com. admin.magedu.com. (
20160926
1H
5M
7D
1D )
IN NS ns1.magedu.com.
IN NS ns2.magedu.com.
61 IN PTR ns1.magedu.com.
64 IN PTR ns2.magedu.com.
61 IN PTR mx1.magedu.com.
64 IN PTR mx2.magedu.com.
64 IN PTR www.magedu.com.
65 IN PTR www.magedu.com.
[[email protected] ~]# service named start
正向解析测试
[[email protected] ~]# dig @192.168.1.61 www.magedu.com
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6 <<>> @192.168.1.61 www.magedu.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54957
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;www.magedu.com. IN A
;; ANSWER SECTION:
www.magedu.com. 86400 IN A 192.168.1.61
www.magedu.com. 86400 IN A 192.168.1.64
;; AUTHORITY SECTION:
magedu.com. 86400 IN NS ns1.magedu.com.
magedu.com. 86400 IN NS ns2.magedu.com.
;; ADDITIONAL SECTION:
ns1.magedu.com. 86400 IN A 192.168.1.61
ns2.magedu.com. 86400 IN A 192.168.1.64
;; Query time: 0 msec
;; SERVER: 192.168.1.61#53(192.168.1.61)
;; WHEN: Mon Sep 26 21:15:11 2016
;; MSG SIZE rcvd: 132
反向解析测试
[[email protected] ~]# dig -x 192.168.1.64 @192.168.1.61
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6 <<>> -x 192.168.1.64 @192.168.1.61
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31974
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;64.1.168.192.in-addr.arpa. IN PTR
;; ANSWER SECTION:
64.1.168.192.in-addr.arpa. 86400 IN PTR mx2.magedu.com.
64.1.168.192.in-addr.arpa. 86400 IN PTR www.magedu.com.
64.1.168.192.in-addr.arpa. 86400 IN PTR ns2.magedu.com.
;; AUTHORITY SECTION:
1.168.192.in-addr.arpa. 86400 IN NS ns2.magedu.com.
1.168.192.in-addr.arpa. 86400 IN NS ns1.magedu.com.
;; ADDITIONAL SECTION:
ns1.magedu.com. 86400 IN A 192.168.1.61
ns2.magedu.com. 86400 IN A 192.168.1.64
;; Query time: 0 msec
;; SERVER: 192.168.1.61#53(192.168.1.61)
;; WHEN: Mon Sep 26 21:18:53 2016
;; MSG SIZE rcvd: 171
二、配置从服务器
[[email protected] ~]# yum -y install bind
[[email protected] ~]# vim /etc/named.rfc1912.zones
在末尾添加
服务启动后,会在/var/named/slaves/自动添加magedu.com.zone和1.168.192.zone文件
[[email protected] ~]# ll /var/named/slaves/
总用量 8
-rw-r--r-- 1 named named 436 9月 21 22:13 1.168.192.zone
-rw-r--r-- 1 named named 502 9月 21 22:13 magedu.com.zone
三、创建cdn子域
新增一台IP为192.168.1.65的服务器为子域
[[email protected] ~]# yum -y install bind
在父域的区域文件中添加NS和A记录
[[email protected] ~]# vim /var/named/magedu.com.zone
添加
cdn IN NS ns1.cdn.magedu.com.
ns1.cdn IN A 192.168.1.65
[[email protected] ~]# scp 192.168.1.61:/etc/named.conf /etc/
[[email protected] ~]# vim /etc/named.rfc1912.zones
zone "cdn.magedu.com" IN {
type master;
file "cdn.magedu.com.zone";
};
zone "magedu.com" IN {
type forward;
forward only;
forwarders { 192.168.1.61; };
};
[[email protected] ~]# vim /var/named/cdn.magedu.com.zone
$TTL 86400
@ IN SOA ns.cdn.magedu.com. admin.cdn.magedu.com. (
20160926
2H
5M
7D
12H )
IN NS ns.cdn.magedu.com.
IN MX 10 mx.cdn.magedu.com.
IN A 192.168.1.65
ns IN A 192.168.1.65
mx IN A 192.168.1.65
www IN A 192.168.1.65
[[email protected] ~]# service named start
测试
1)子域测试
[[email protected] ~]# dig @192.168.1.65 www.cdn.magedu.com
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6 <<>> @192.168.1.65 www.cdn.magedu.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33720
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;www.cdn.magedu.com. IN A
;; ANSWER SECTION:
www.cdn.magedu.com. 86400 IN A 192.168.1.65
;; AUTHORITY SECTION:
cdn.magedu.com. 86400 IN NS ns.cdn.magedu.com.
;; ADDITIONAL SECTION:
ns.cdn.magedu.com. 86400 IN A 192.168.1.65
;; Query time: 0 msec
;; SERVER: 192.168.1.65#53(192.168.1.65)
;; WHEN: Mon Sep 26 22:16:44 2016
;; MSG SIZE rcvd: 85
2)父域测试
[[email protected] ~]# dig -t www.magedu.com
;; Warning, ignoring invalid type www.magedu.com
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6 <<>> -t www.magedu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27354
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;. IN NS
;; ANSWER SECTION:
. 518239 IN NS b.root-servers.net.
. 518239 IN NS i.root-servers.net.
. 518239 IN NS j.root-servers.net.
. 518239 IN NS k.root-servers.net.
. 518239 IN NS l.root-servers.net.
. 518239 IN NS e.root-servers.net.
. 518239 IN NS h.root-servers.net.
. 518239 IN NS f.root-servers.net.
. 518239 IN NS c.root-servers.net.
. 518239 IN NS m.root-servers.net.
. 518239 IN NS d.root-servers.net.
. 518239 IN NS a.root-servers.net.
. 518239 IN NS g.root-servers.net.
;; Query time: 0 msec
;; SERVER: 192.168.1.65#53(192.168.1.65)
;; WHEN: Mon Sep 26 22:18:26 2016
;; MSG SIZE rcvd: 228