您好,登錄后才能下訂單哦!
在上面的功能實現之前我們先來復習一下DNS 一些配置的基本格式:
ACL:
acl string { address_match_element; address_match_element; ... };
ZONE :
#主服務器 zone string optional_class { type master ; file quoted_string; ... }; #從服務器 zone string optional_class { type slave ; masters { MASTER_ADDRESS; } file quoted_string; ... }; #轉發服務器 zone string optional_class { type forward ; forward {first|only}; forwarders { forward_address; } ... };
VIEW
# 一旦啟動view,所有的zone只能定義在view中。 view string optional_class { match-clients { address_match_element; ... }; match-destinations { address_match_element; ... }; zone string optional_class { ... };
訪問控制指令:
allow-query { address_match_element; ... }; allow-transfer { address_match_element; ... }; allow-recursion { address_match_element; ... }; allow-update { address_match_element; ... };
詳情man named.conf
環境:兩臺centos6.5
IP1:192.168.1.16 , IP2:192.168.1.20
實現方式:將IP1配置成DNS服務器,在其下配置一個以IP2為域名的DNS服務器(子域)。只需在IP1的解析庫文件里定義一個子域即可。
START:
關閉防火墻和selinux
首先配置IP1(192.168.1.16):
修改配置文件
# cat /etc/named.conf options { listen-on port 53 { 192.168.1.16; 127.0.0.1; };//or delete this line // 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 no; dnssec-validation no; /* Path to ISC DLV key */ // bindkeys-file "/etc/named.iscdlv.key"; // managed-keys-directory "/var/named/dynamic"; };
添加zone:
# tail /etc/named.rfc1912.zones zone "jiajie.com" IN { type master; file "jiajie.zone"; };
配置解析庫文件:
# vim /var/named/jiajie.zone $TTL 1D @ IN SOA ns1.jiajie.com. jjzgood.126.com. ( 20170509 1H 10M 5D 1D ) IN NS ns1 IN NS ns2 ns1 IN A 192.168.1.16 ns2 IN A 192.168.1.17 www IN A 192.168.1.17 * IN A 192.168.1.16 #在解析庫里定義一個字域 ops IN NS ns1.ops ops IN NS ns2.ops ns1.ops IN A 192.168.1.20 ns2.ops IN A 192.168.1.21
修改權限和組:
#chmod 640 /var/named/jiajie.zone # chown :named /var/named/jiajie.zone # ll /var/named/jiajie.zone -rw-r----- 1 root named 292 5月 9 16:30 /var/named/jiajie.zone
重啟服務:# service named restart
查看端口號:# ss -tlnp|grep :53
驗證:
# host -t a www.jiajie.com 192.168.1.16 Using domain server: Name: 192.168.1.16 Address: 192.168.1.16#53 Aliases: www.jiajie.com has address 192.168.1.17
3.配置子域(IP2:192.168.1.20)
修改配置文件:
# cat /etc/named.conf options { listen-on port 53 { 192.168.1.16; 127.0.0.1; };//or delete this line // 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 no; dnssec-validation no; /* Path to ISC DLV key */ // bindkeys-file "/etc/named.iscdlv.key"; // managed-keys-directory "/var/named/dynamic"; };
添加ZONE:
# tail /etc/named.rfc1912.zones zone "ops.jiajie.com" IN { type master; file "ops.jiajie.com.zone"; };
配置解析庫文件:
# vim /var/named/ops.jiajie.com.zone $TTL 1D @ IN SOA ns1.ops.jiajie.com. jjzgood.126.com. ( 20170509 1H 10M 5D 1D ) IN NS ns1 IN NS ns2 ns1 IN A 192.168.1.20 ns2 IN A 192.168.1.21 www IN A 192.168.1.20 * IN A 192.168.1.21
修改權限和組:
# chmod 640 /var/named/ops.jiajie.com.zone # chown named /var/named/ops.jiajie.com.zone
重啟服務:# service named restart
查看端口號:# ss -tlnp|grep :53
驗證:
# host -t a www.ops.jiajie.com 192.168.1.20 Using domain server: Name: 192.168.1.20 Address: 192.168.1.20#53 Aliases: www.ops.jiajie.com has address 192.168.1.20 # host -t a ftp.ops.jiajie.com 192.168.1.20 Using domain server: Name: 192.168.1.20 Address: 192.168.1.20#53 Aliases: ftp.ops.jiajie.com has address 192.168.1.21 -------------------------------------------- #注意上下兩個使用的dns服務器是不同的 --------------------------------------------- # host -t a www.ops.jiajie.com 192.168.1.16 Using domain server: Name: 192.168.1.16 Address: 192.168.1.16#53 Aliases: www.ops.jiajie.com has address 192.168.1.20 [root@test1 ~]# host -t a ftp.ops.jiajie.com 192.168.1.16 Using domain server: Name: 192.168.1.16 Address: 192.168.1.16#53 Aliases: ftp.ops.jiajie.com has address 192.168.1.21
由上可以看出如果用父域來解析子域的地址是可以的,但是如果使用子域去解析父域的是解析不出來的(如下圖)。此時我們可以在子域上設置一個轉發服務器來解決上面的尷尬狀況。
如下圖:
# host -t a ftp.jiajie.com 192.168.1.20 Using domain server: Name: 192.168.1.20 Address: 192.168.1.20#53 Aliases: Host ftp.jiajie.com not found: 3(NXDOMAIN)
注意:本實驗是基于上面的實驗進行的。
首先在IP2(192.168.1.20)服務器上增加一個轉發區域:
# tail /etc/named.rfc1912.zones zone "jiajie.com" IN { type forward; forward only; forwarders { 192.168.1.16; }; };
重新加載配置服務:# rndc reload
此時我們就可以在子域上解析父域的地址了:
# host -t A ftp.jiajie.com 192.168.1.20 Using domain server: Name: 192.168.1.20 Address: 192.168.1.20#53 Aliases: ftp.jiajie.com has address 192.168.1.16
轉發分為全局轉發和區域轉發
全局轉發:凡是非本機所負責的解析區域的,統統轉發給指定服務器。
option { forward {first|only}; forwarders { address; } };
區域轉發:只轉發對特定區域的請求到指定服務器
zone { type forward; forward {first|only}; forwarders { address; } };
本實驗是在上面兩個實驗的基礎上進行修改的。
注意
一旦啟用view,所有的zone都能定義在view中
一個bind可以定義多個view,每個view中可以定義一個或者多個zone。
多個view內可能需要對同一個區域進行解析,但使用不同的區域解析文件。
客戶端請求到達時是自上而下檢查view的。
配置:
配置IP1(192.168.1.16)
1.首先先把/etc/named.conf
中的根區域移到/etc/named.rfc1912.zones
文件中。
# vim /etc/named.conf zone "." IN { type hint; file "named.ca"; };
2.在/etc/named.conf
文件首部添加一個acl
#vim /etc/named.conf acl in_net { 192.168.1.16; 192.168.1.10; 127.0.0.0/24; };
3.添加兩個view,注意第一個view將文件中的zone都圈起來,第二個view添加在文件的底部。
#將匹配acl內的IP # vim /etc/named.rfc1912.zones view innet { match-clients { in_net; }; allow-recursion { in_net; }; zone ... ... }; }; #匹配acl以外的IP view outnet { match-clients { any; }; zone "jiajie.com" IN { type master; file "jiajie.com.out"; allow-update { none; }; }; };
4.cp /var/named/jiajie.zone /var/named/jiajie.com.out -a
5.編輯/var/named/jiajie.zone.out
# vim /var/named/jiajie.com.out $TTL 1D @ IN SOA ns1.jiajie.com. jjzgood.126.com. ( 20170509 1H 10M 5D 1D ) IN NS ns1 IN NS ns2 ns1 IN A 192.168.1.16 ns2 IN A 192.168.1.17 www IN A 2.2.2.2 * IN A 2.2.2.3
6.運行# rndc reload
7.驗證:
#基于IP1(192.168.1.16)平臺驗證 # host www.jiajie.com 192.168.1.16 Using domain server: Name: 192.168.1.16 Address: 192.168.1.16#53 Aliases: www.jiajie.com has address 192.168.1.17 #基于IP2(192.168.1.20)平臺驗證 # host www.jiajie.com 192.168.1.16 Using domain server: Name: 192.168.1.16 Address: 192.168.1.16#53 Aliases: www.jiajie.com has address 2.2.2.2
windows平臺驗證:
由上面可以看出你雖然是訪問同一個域名,但是如果你的IP地址不同,將會返回給你不同的地址,這樣就實現了智能化。
2017/5/9 22:04:59
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。