在上面的功能實(shí)現(xiàn)之前我們先來復(fù)習(xí)一下DNS 一些配置的基本格式:
十多年的匯川網(wǎng)站建設(shè)經(jīng)驗(yàn),針對設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。全網(wǎng)整合營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整匯川建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“匯川網(wǎng)站設(shè)計(jì)”,“匯川網(wǎng)站推廣”以來,每個客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
ACL:
acl string { address_match_element; address_match_element; ... };
ZONE :
#主服務(wù)器 zone string optional_class { type master ; file quoted_string; ... }; #從服務(wù)器 zone string optional_class { type slave ; masters { MASTER_ADDRESS; } file quoted_string; ... }; #轉(zhuǎn)發(fā)服務(wù)器 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
環(huán)境:兩臺centos6.5
IP1:192.168.1.16 , IP2:192.168.1.20
實(shí)現(xiàn)方式:將IP1配置成DNS服務(wù)器,在其下配置一個以IP2為域名的DNS服務(wù)器(子域)。只需在IP1的解析庫文件里定義一個子域即可。
START:
關(guān)閉防火墻和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
修改權(quán)限和組:
#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
重啟服務(wù):# service named restart
查看端口號:# ss -tlnp|grep :53
驗(yàn)證:
# 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
修改權(quán)限和組:
# chmod 640 /var/named/ops.jiajie.com.zone # chown named /var/named/ops.jiajie.com.zone
重啟服務(wù):# service named restart
查看端口號:# ss -tlnp|grep :53
驗(yàn)證:
# 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服務(wù)器是不同的 --------------------------------------------- # 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
由上可以看出如果用父域來解析子域的地址是可以的,但是如果使用子域去解析父域的是解析不出來的(如下圖)。此時我們可以在子域上設(shè)置一個轉(zhuǎn)發(fā)服務(wù)器來解決上面的尷尬狀況。
如下圖:
# 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)
注意:本實(shí)驗(yàn)是基于上面的實(shí)驗(yàn)進(jìn)行的。
首先在IP2(192.168.1.20)服務(wù)器上增加一個轉(zhuǎn)發(fā)區(qū)域:
# tail /etc/named.rfc1912.zones zone "jiajie.com" IN { type forward; forward only; forwarders { 192.168.1.16; }; };
重新加載配置服務(wù):# 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
轉(zhuǎn)發(fā)分為全局轉(zhuǎn)發(fā)和區(qū)域轉(zhuǎn)發(fā)
全局轉(zhuǎn)發(fā):凡是非本機(jī)所負(fù)責(zé)的解析區(qū)域的,統(tǒng)統(tǒng)轉(zhuǎn)發(fā)給指定服務(wù)器。
option { forward {first|only}; forwarders { address; } };
區(qū)域轉(zhuǎn)發(fā):只轉(zhuǎn)發(fā)對特定區(qū)域的請求到指定服務(wù)器
zone { type forward; forward {first|only}; forwarders { address; } };
本實(shí)驗(yàn)是在上面兩個實(shí)驗(yàn)的基礎(chǔ)上進(jìn)行修改的。
注意
一旦啟用view,所有的zone都能定義在view中
一個bind可以定義多個view,每個view中可以定義一個或者多個zone。
多個view內(nèi)可能需要對同一個區(qū)域進(jìn)行解析,但使用不同的區(qū)域解析文件。
客戶端請求到達(dá)時是自上而下檢查view的。
配置:
配置IP1(192.168.1.16)
1.首先先把/etc/named.conf
中的根區(qū)域移到/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內(nèi)的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.運(yùn)行# rndc reload
7.驗(yàn)證:
#基于IP1(192.168.1.16)平臺驗(yàn)證 # 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)平臺驗(yàn)證 # 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平臺驗(yàn)證:
由上面可以看出你雖然是訪問同一個域名,但是如果你的IP地址不同,將會返回給你不同的地址,這樣就實(shí)現(xiàn)了智能化。
2017/5/9 22:04:59