模拟搭建互联网名称解析服务架构


模拟搭建互联网名称解析服务架构_第1张图片
1> 192.168.0.1: web1
echo -e web1.liuguiyong.com\n\hello web1\ > /var/www/html/index.html
service httpd start
curl 192.168.0.1
web1.liuguiyong.com

hello web1



2> 192.168.0.2: web2
echo -e web2.liuguiyong.com\n\hello web1\ > /var/www/html/index.html
service httpd start
curl 192.168.0.2
web2.liuguiyong.com

hello web2



3> 192.168.0.3: dns1,配置liuguiyong.com域的主DNS服务器
# vim /etc/named.conf
options {
//  listen-on port 53 { 127.0.0.1; };  //注释掉
    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     { localhost; };  //注释掉
    allow-transfer { 192.168.0.4; };  //只允许192.168.0.4的主机,也就是从DNS来拉取区域解析数据库
    recursion yes;
    dnssec-enable yes;
    dnssec-validation yes;
    bindkeys-file "/etc/named.iscdlv.key";
    managed-keys-directory "/var/named/dynamic";
};

# vim /etc/named.rfc1912.zone
zone "liuguiyong.com" IN {
type master;
file "liuguiyong.com.zone";
};

# vim /var/named/liuguiyong.com.zone
$TTL 1D 
@ IN SOA dns1.liuguiyong.com. admin.liuguiyong.com. ( 1 1D 1H 1W 3H )
NS dns1
NS dns2
dns1 A 192.168.0.3
dns2 A 192.168.0.4

webs A 192.168.0.1
webs A 192.168.0.2
www CNAME webs

# chgrp named /var/named/liuguiyong.com.zone
# chmod 640 /var/named/liuguiyong.com.zone
# named-checkconf
# named-checkzone "liuguiyong.com" /var/named/liuguiyong.com.zone
# service named start
# dig www.liuguiyong.com @192.168.0.3
;; ANSWER SECTION
www.liuguiyong.com. 86400 IN CNAME     webs.liuguiyong.com.
webs.liuguiyong.com. 86400 IN A webs.liuguiyong.com.
webs.liuguiyong.com. 86400 IN A webs.liuguiyong.com.

4> 192.168.0.4: dns2,配置liuguiyong.com域的从DNS服务器
# vim /etc/named.conf
options {
//  listen-on port 53 { 127.0.0.1; };  //注释掉
    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     { localhost; };  //注释掉
    allow-transfer { none; };  //不对任何主机做区域传送
    recursion yes;
    dnssec-enable yes;
    dnssec-validation yes;
    bindkeys-file "/etc/named.iscdlv.key";
    managed-keys-directory "/var/named/dynamic";
};

# vim /etc/named.rfc1912.zones
zone "liuguiyong.com" {
type slave;  # 类型为从服务器
master { 192.168.0.3;};  # 指向谁时我的主服务器
file "slaves/liuguiyong.com.zone.slave";  # 解析数据库存放位置 
};

# named-checkconf
# service named start
# ls -l  /var/named/slaves/  # 查看一下有没有数据库文件,有则说明同步成功
--rw-r--r--. 1 named named 417 May 19 22:09 liuguiyong.com.zone.slave

5> 192.168.0.5: com.配置子域委派
# vim /etc/named.conf
options {
//  listen-on port 53 { 127.0.0.1; };
    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     { localhost; };
    recursion yes;
    dnssec-enable yes;
    dnssec-validation yes;
    bindkeys-file "/etc/named.iscdlv.key";
    managed-keys-directory "/var/named/dynamic";
};

# vim /etc/named.rfc1912.zones
zone "com." IN {
type master;
file "com.zone";
};

# vim /var/named/com.zone
$TTL 1D
@ IN SOA dns1.com. admin.com. ( 1 1D 1H 1W 3H )
NS dns1
liuguiyong NS dns2.com.  # 子域委派给192.168.0.3和192.168.0.4
dns1 A 192.168.0.5
dns2 A 192.168.0.3
dns2 A  192.168.0.4

# chgrp named /var/named/com.zone
# chmod 640 /var/named/com.zone
# named-checkconf
# service named start
# dig www.liuguiyong.com @192.168.0.5
www.liuguiyong.com.        86387   IN      CNAME   webs.liuguiyong.com.
webs.liuguiyong.com.       86387   IN      A       192.168.0.1
webs.liuguiyong.com.       86387   IN      A       192.168.0.2
;; AUTHORITY SECTION:
liuguiyong.com.           86400   IN      NS      dns2.com.
;; ADDITIONAL SECTION:
dns2.com.               86400   IN      A       192.168.0.4
dns2.com.               86400   IN      A       192.168.0.3
;; SERVER: 192.168.0.5#53(192.168.0.5)

6> 192.168.0.6 : 根域配置
# vim /etc/named.conf
options {
//  listen-on port 53 { 127.0.0.1; };
    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     { localhost; };
    recursion yes;
    dnssec-enable no;
    dnssec-validation no;
    bindkeys-file "/etc/named.iscdlv.key";
    managed-keys-directory "/var/named/dynamic";
};

# vim /etc/named.rfc1912.zones
zone "." {
type master;
file "root.zone";
};


# vim /var/named/root.zone
$TTL 1D
@ IN SOA dns1. admin. ( 1 1D 2H 3D 1H )
NS  dns1
com NS  dns2
dns1 A 192.168.0.6
dns2 A 192.168.0.5

# chgrp named /var/named/root.zone
# chmod 640 /var/named/root.zone
# service named start
# dig www.liuguiyong.com @127.0.0.1
www.liuguiyong.com.        86177   IN      CNAME   webs.liuguiyong.com.
webs.liuguiyong.com.       86177   IN      A       192.168.0.1
webs.liuguiyong.com.       86177   IN      A       192.168.0.2

7> 192.168.0.7:缓存DNS服务器配置
# vim /etc/named.conf
# vim /etc/named.conf
options {
//  listen-on port 53 { 127.0.0.1; };
    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     { localhost; };
    recursion yes;
    dnssec-enable no;
    dnssec-validation no;
    bindkeys-file "/etc/named.iscdlv.key";
    managed-keys-directory "/var/named/dynamic";
};

zone "." IN {
type hint;
file "named.ca";
}

# vim /var/named/named.ca
.                  3600000      NS    A.ROOT-SERVERS.NET.
A.ROOT-SERVERS.NET.      3600000      A     192.168.0.6  //将根服务器指向我们自己搭建的根DNS服务器

# service named start

8> 192.168.0.8
# vim /etc/resolv.conf
nameserver 192.168.0.7  //将自己的DNS服务器指向缓存服务器


# dig www.liuguiyong.com //出现以下信息则说明成功
;; ANSWER SECTION:
www.liuguiyong.com.        86319   IN      CNAME   webs.liuguiyong.com.
webs.liuguiyong.com.       86319   IN      A       192.168.0.1
webs.liuguiyong.com.       86319   IN      A       192.168.0.2
;; SERVER: 192.168.0.7#53(192.168.0.7)
​ 
到此为止,我们可以访问以下www.liuguiyong.com,看看是否可以正常解析:

# curl www.liuguiyong.com 
web2.liuguiyong.comn

hello web2


# curl www.liuguiyong.com 
web1.liuguiyong.comn

hello web1


# curl www.liuguiyong.com 
web2.liuguiyong.comn

hello web2


# curl www.liuguiyong.com 
web1.liuguiyong.comn

hello web1



​从测试结果看来,不仅可以正常解析,还实现了DNS负载均衡的功能。
  # curl www.liuguiyong.top        

你可能感兴趣的:(模拟搭建互联网名称解析服务架构)