linux下8種DNS功能的實現(二)

~~~~~~~~~~接上一篇linux下8種DNS功能的實現(一)~~~~~~~~~
linux

八.DNS的子域受權
 
子在原有的域上再劃分出一個區域並指定新DNS服務器。這樣的作的好處能夠減輕主DNS的壓力,也有利於管理。
主:
[root@tx1 etc]# vim named.conf
options
{
        listen-on port 53 {any;};
        directory "/var/named";
        dump-file               "data/cache_dump.db";
        statistics-file         "data/named_stats.txt";
        memstatistics-file      "data/named_mem_stats.txt";
        allow-query     {any;};
};
zone "tx.com" IN {
      type master;
      file "tx.com.zone";
[root@tx1 named]# vim tx.com.zone 
$TTL    86400
@               IN SOA  ns.tx.com.       root (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
@               IN NS           ns.tx.com.
ns              IN A            192.168.8.70
www             IN A            192.168.8.64
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
th              IN NS            ns.th.tx.com.
ns.th           IN A             192.168.8.71
 
從:
[root@tx2 etc]# vim named.conf
options
{
        listen-on port 53 {any;};
        directory "/var/named/slaves";
        dump-file               "data/cache_dump.db";
        statistics-file         "data/named_stats.txt";
        memstatistics-file      "data/named_mem_stats.txt";
        allow-query     {any;};
};
zone "th.tx.com" IN {
      type master;
      file "th.tx.com.zone";
};
[root@tx2 etc]# cd ../var/named/slaves/
[root@tx2 slaves]# ls
[root@tx2 slaves]# vim th.tx.com.zone
$TTL    86400
@               IN SOA  ns.th.tx.com.       root (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
@               IN NS           ns.th.tx.com.
ns              IN A            192.168.8.70
www             IN A            192.168.8.64
 
客戶端測試:
在/etc/resolv.conf 指定父域dns的ip
[root@tx3 ~]# nslookup www.tx.com
Server:192.168.8.70
Address:192.168.8.70#53
Name:www.tx.com
Address: 192.168.8.64
[root@tx3 ~]# nslookup www.th.tx.com
Server:192.168.8.70
Address:192.168.8.70#53
Non-authoritative answer:
Name:www.th.tx.com
Address: 192.168.8.64
 
九.DNS視圖的配置
      視圖原理: 在主配置文件中,能夠指定多個view, 若是DNS客戶端所提交的查詢知足第一個view的條件時,就會使用第一個view來進行解析,否 則就判斷一下view,而後再進行解析。若是全部的 view都不知足條件時,BIND將返回Query refuset的消息。設置多個view的做用 在於能夠根據不一樣的DNS客戶端返回不一樣的解析結果。
視圖的名字不要用關鍵字,不要重複。存在優先級順序的
[root@tx1 etc]# vim named.conf 
options
{
        listen-on port 53 {any;};
        directory "/var/named";
        dump-file               "data/cache_dump.db";
        statistics-file         "data/named_stats.txt";
        memstatistics-file      "data/named_mem_stats.txt";
};
view cnc {
        match-clients { 192.168.8.1; };   //聲明能夠訪問的網段,這裏拿一個ip舉例
        recursion no;                  //是否容許遞歸查詢
        zone "tx.com" {
                type master;
                file "tx.com.cnc";
        };
};
view tel {
        match-clients { 192.168.8.2; };
        recursion no;
        zone "tx.com" {
                type master;
                file "tx.com.tel";
        };
};
view all {
        match-clients { any; };
        recursion no;
        zone "tx.com" {
                type master;
                file "tx.com.all";
        };
};
[root@tx1 named]# vim tx.com.cnc
$TTL    86400
@               IN SOA  ns.tx.com.       root (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
@               IN NS           ns.tx.com.
ns              IN A            192.168.8.70
www             IN A            1.1.1.1
[root@tx1 named]# vim tx.com.tel
@               IN NS           ns.tx.com.
ns              IN A            192.168.8.70
www             IN A            2.2.2.2
[root@tx1 named]# vim tx.com.all
@               IN NS           ns.tx.com.
ns              IN A            192.168.8.70
www             IN A            3.3.3.3
客戶端測試:

十.DNS的輪詢
一個FQDN對映多個IP,減輕只對一臺服務器的訪問壓力。
[root@tx1 etc]# vim named.conf 
options
{
        listen-on port 53 {any;};
        directory "/var/named";
        dump-file               "data/cache_dump.db";
        statistics-file         "data/named_stats.txt";
        memstatistics-file      "data/named_mem_stats.txt";
        allow-query     {any;};
};
zone "tx.com" {
        type master;
        file "tx.com.zone";
};
[root@tx1 named]# vim tx.com.zone 
$TTL    86400
@               IN SOA  ns.tx.com.       root (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
@               IN NS           ns.tx.com.
ns              IN A            192.168.8.70
www             IN A            192.168.8.64
www             IN A            192.168.8.65
www             IN A            192.168.8.66
 
客戶端測試

 

十一.DNS的別名
    DNS的輪詢是一個域名對應多個ip,DNS的別名就是一個ip對應多個域名,例如當一臺機器同時提供www,mail等服務時,用DNS的別名功能仍是很方便的
[root@tx1 etc]# vim named.conf
options
{
        listen-on port 53 {any;};
        directory "/var/named";
        dump-file               "data/cache_dump.db";
        statistics-file         "data/named_stats.txt";
        memstatistics-file      "data/named_mem_stats.txt";
        allow-query     {any;};
};
zone "bb.com" {
        type master;
        file "bb.com.zone";
};
zone "aa.com" {
          type master;
            file "aa.com.zone";
};
 
[root@tx1 named]# vim aa.com.zone
$TTL    86400
@               IN SOA  ns.aa.com.       root (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
@               IN NS           ns.aa.com.
ns              IN A            192.168.8.70
www             IN CNAME         www.bb.com.
[root@tx1 named]# vim bb.com.zone

 

$TTL    86400vim

@               IN SOA  ns.bb.com.       root (緩存

                                        42              ; serial (d. adams)服務器

                                        3H              ; refreshide

                                        15M             ; retry測試

                                        1W              ; expiry優化

                                        1D )            ; minimum搜索引擎

 

@               IN NS           ns.bb.com.spa

ns              IN A            192.168.8.70blog

www             IN A            192.168.8.64

 
客戶端測試

十二.DNS的泛解析
    域名泛解析是指域名解析設置一條「*.tx.com」這種格式的A記錄,並對應一個固定的IP.。那輸入t1.tx.com或t2.tx。com或者其餘 不正確的域名都能正確的訪問。但這種方式不利於SEO(搜索引擎)的優化。優勢:輸入錯的域名能夠訪問。缺點:例如DNS有一條t1.tx.com的記 錄,當你再訪問t1.tx.com 時就不是泛解析的內容了。
[root@tx1 etc]# vim named.conf
options
{
        listen-on port 53 {any;};
        directory "/var/named";
        dump-file               "data/cache_dump.db";
        statistics-file         "data/named_stats.txt";
        memstatistics-file      "data/named_mem_stats.txt";
        allow-query     {any;};
};
zone "tx.com" {
        type master;
        file "tx.com.zone";
};
[root@tx1 named]# vim tx.com.zone 
$TTL    86400
@               IN SOA  ns.tx.com.       root (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
@               IN NS           ns.tx.com.
ns              IN A            192.168.8.70
$GENERATE 1-3   t$ A            192.168.8.$
客戶端測試

十三.DNS的轉發
       forward  DNS也稱Cache-only DNS Server,只有轉發和緩存的功能,那有什麼用呢?某些公司有嚴格的上網規定,53號端口會被過濾掉,天然也就沒法解析出主機名對應的ip,因此要搭建一個DNS轉發的服務器
1.真正的DNS
[root@tx1 etc]# vim named.conf
options
{
        listen-on port 53 {any;};
        directory "/var/named";
        dump-file               "data/cache_dump.db";
        statistics-file         "data/named_stats.txt";
        memstatistics-file      "data/named_mem_stats.txt";
};
zone "tx.com" {
        type master;
        file "tx.com.zone";
};
[root@tx1 named]# vim tx.com.zone
$TTL    86400
@               IN SOA  ns.tx.com.       root (
                                        42              ; serial (d. adams)
                                        3H              ; refresh
                                        15M             ; retry
                                        1W              ; expiry
                                        1D )            ; minimum
@               IN NS           ns.tx.com.
ns              IN A            192.168.8.70
www             IN A            192.168.8.60
2. 轉發的DNS
[root@tx2 etc]# vim named.conf
acl zf {                        //容許訪問的客戶端請求
      192.168.8.1;
      192.168.8.2;
};
options
{
        listen-on port 53 {any;};
        directory "/var/named";
        dump-file               "data/cache_dump.db";
        statistics-file         "data/named_stats.txt";
        memstatistics-file      "data/named_mem_stats.txt";
        forward only;               //轉發模式
        allow-query { zf;};              //轉發acl裏面定義的ip
        forwarders  {192.168.8.70;};      //真正的DNS服務器
};
3. 客戶端測試

我的總結:終於寫完了,過程當中出現過不少錯誤,真心累啊,可是寫博客最大的好處就是可讓你弄清楚一些細節的問題,另外能給別人講明白纔是真正的懂了,並且記憶更加深入,但願對看到的人有幫助哦!!!
相關文章
相關標籤/搜索