建立DNS主從服務器

一.建立一個DNS域名服務器:(設置域名爲zzuwhx.com,服務器主機網卡地址192.168.0.1)
1.)安裝DNS服務器必要的rpm安裝包(bind,bind-utils,bind-libs)
   yum list all | grep "^bind"
   yum install bind
   yum install bind-utils
   yum install bind-libs
2.)配置DNS服務器的主配置文件/etc/named.conf
  options {
         directory "/var/named";
  };
  zone "." IN {
        type hint;
        file "named.ca";
  };
  zone "localhost" IN {
       type master;
       file "localhost.zone";
  };
  zone "0.0.127.in-addr.arpa" IN {
        type master;
        file "named.local";
  };
  zone "zzuwhx.com" IN {
        type master;
        file "zzuwhx.com.zone";
        allow-transfer { 192.168.0.49; 192.168.0.1; };
        allow-query { 192.168.0.49; 192.168.0.1; };
  };
  zone "0.168.192.in-addr.arpa" IN {
        type master;
        file "192.168.0.zone";
        allow-transfer { 192.168.0.49; 192.168.0.1; };
        allow-query { 192.168.0.49; 192.168.0.1; };
  };
3.)配置DNS服務器的數據文件/var/named/named.ca;鏈接外網時可直接用命令`dig -t NS . > /var/named/named.ca`或在/var/named/named.ca添加:
  a.root-servers.net.     178562  IN      A       198.41.0.4
  a.root-servers.net.     480559  IN      AAAA    2001:503:ba3e::2:30
  b.root-servers.net.     269418  IN      A       192.228.79.201
  c.root-servers.net.     276759  IN      A       192.33.4.12
  d.root-servers.net.     269451  IN      A       128.8.10.90
  e.root-servers.net.     278224  IN      A       192.203.230.10
  f.root-servers.net.     273127  IN      A       192.5.5.241
  f.root-servers.net.     539590  IN      AAAA    2001:500:2f::f
  g.root-servers.net.     276924  IN      A       192.112.36.4
  h.root-servers.net.     276769  IN      A       128.63.2.53
  h.root-servers.net.     480559  IN      AAAA    2001:500:1::803f:235
  i.root-servers.net.     269381  IN      A       192.36.148.17
  i.root-servers.net.     480559  IN      AAAA    2001:7fe::53
  j.root-servers.net.     269594  IN      A       192.58.128.30
4.)配置DNS服務器的數據文件/var/named/localhost.zone
  $TTL 86400
  @  86400 IN SOA localhost. root.localhost. (
                  2010080301
                  1H
                  10M
                  7D
                  1D )
                  IN  NS   localhost.
  localhost.  IN  A    127.0.0.1
5.)配置DNS服務器的數據文件/var/named/named.local
  $TTL 86400
  @  86400 IN SOA localhost. root.localhost. (
                  2010080301
                  1H
                  10M
                  7D
                  1D )
               IN  NS   localhost.
  1           IN  PTR  localhost.
6.)配置DNS服務器的數據文件/var/named/zzuwhx.com.zone
  $TTL 86400
  $ORIGIN zzuwhx.com.
  @ 86400 IN SOA ns.zzuwhx.com. dnsadmin.zzuwhx.com. (
                    2010080302
                    1H
                    10M
                    7D
                    1D )
     IN   NS   ns
     IN   NS   ns2
     IN   MX  10 mail
     IN   MX  20 pop3
  ns        IN   A   192.168.0.1
  ns2      IN   A   192.168.0.49
  mail     IN   A   192.168.0.151
  pop3   IN   A   192.168.0.152
  www   IN   A   192.168.0.153
  web     IN   CNAME  www
7.)配置DNS服務器的數據文件/var/named/192.168.0.zone
$TTL 86400
  @ 86400 IN SOA ns.zzuwhx.com. dnsadmin.zzuwhx.com. (
                    2010080302
                    1H
                    10M
                    7D
                    1D )
          IN   NS   ns.zzuwhx.com.
          IN   NS   ns2.zzuwhx.com.
  1      IN   PTR  ns.zzuwhx.com.
  49    IN   PTR  ns2.zzuwhx.com.
  151  IN   PTR  mail.zzuwhx.com.
  152  IN   PTR  pop3.zzuwhx.com.
  153  IN   PTR  www.zzuwhx.com.
8.)使用`service named configtest`命令檢查語法是否正確,定義/etc/resolv.conf的nameserver爲本服務器地址
9.)爲主配置文件/etc/named.conf和目錄/var/named/內的數據文件賦予其用戶組爲named
   chgrp named  /etc/named.conf
   chgrp named  /var/named/named.*
   chgrp named  /var/named/localhost.zone
   chgrp named  /var/named/zzuwhx.example.com
   chgrp named  /var/named/192.168.0.zone
10.)啓動DNS服務,使用命令`service named start`;若要在之後開機時啓動此服務,則要使用`chkconfig named on`命令;DNS服務啓後可以使用host,dig,nslookup命令來測試DNS服務器

二.建立一個輔助的從DNS服務服務器(從DNS服務器地址192.168.0.49)
1.)安裝DNS服務器的軟件包(同"一"的步驟1)
2.)配置DNS的主配置文件/etc/named.conf
  options {
        directory "/var/named";
  };
  zone "." IN {
        type hint;
        file "named.ca";
  };
  zone "localhost" IN {
         type master;
         file "localhost.zone";
  };
  zone "0.0.127.in-addr.arpa" IN {
         type master;
         file "named.local";
  };
  zone "zzuwhx.com" IN {
          type slave;
          file "slaves/zzuwhx.com.zone";
          masters { 192.168.0.1; };
          allow-transfer { none; };
  };

  zone "0.168.192.in-addr.arpa" IN {
          type slave;
          file "slaves/192.168.0.zone";
          masters { 192.168.0.1; };
          allow-transfer { none; };
  };

3.)配置DNS的數據文件/var/named/named.ca , /var/named/localhost.zone , /var/named/named.local(同"一"的步驟3,4,5)
4.)使用`service named configtest`命令檢查語法是否正確,定義/etc/resolv.conf的nameserver爲本服務器地址
5.)爲主配置文件/etc/named.conf和目錄/var/named/內的數據文件賦予其用戶組爲named
   chgrp named  /etc/named.conf
   chgrp named  /var/named/named.*
   chgrp named  /var/named/localhost.zone
6.)啓動從DNS服務器,使用命令`service named start`;若要在之後開機時可啓動此服務,則要使用`chkconfig named on`命令;再重啓主DNS服務器,看從DNS服務器的/var/named/slaves/目錄下因區域傳送獲得了兩個文件zzuwhx.com.zone和192.168.0.zone
7.)用cat命令看此兩文件zzuwhx.com.zone和192.168.0.zone:
  #zzuwhx.com.zone
  $ORIGIN .
  $TTL 86400 ; 1 day
  zzuwhx.com  IN SOA ns.zzuwhx.com. dnsadmin.zzuwhx.com. (
      2010080302 ; serial
      3600       ; refresh (1 hour)
       600        ; retry (10 minutes)
     604800     ; expire (1 week)
     86400      ; minimum (1 day)
      )
   NS ns.zzuwhx.com.
   NS ns2.zzuwhx.com.
   MX 10 mail.zzuwhx.com.
   MX 20 pop3.zzuwhx.com.
  $ORIGIN zzuwhx.com.
  mail    A 192.168.0.151
  ns       A 192.168.0.1
  ns2     A 192.168.0.49
  pop3  A 192.168.0.152
  web   CNAME www
  www  A 192.168.0.153
##################################################################################
  #192.168.0.zone
  $ORIGIN .
  $TTL 86400 ; 1 day
  0.168.192.in-addr.arpa IN SOA ns.zzuwhx.com. dnsadmin.zzuwhx.com. (
    2010080302 ; serial
    3600       ; refresh (1 hour)
    600        ; retry (10 minutes)
    604800     ; expire (1 week)
    86400      ; minimum (1 day)
    )
   NS ns.zzuwhx.com.
         NS ns2.zzuwhx.com.
  $ORIGIN 0.168.192.in-addr.arpa.
  1       PTR ns.zzuwhx.com.
  151   PTR mail.zzuwhx.com.
  152   PTR pop3.zzuwhx.com.
  153   PTR  www.zzuwhx.com.   49   PTR ns2.zzuwhx.com.
相關文章
相關標籤/搜索