1. 程式人生 > >Linux伺服器---安裝bind

Linux伺服器---安裝bind

安裝bind
1、安裝bind軟體,需要安裝3 個bind、bind-chroot、bind-util
      [[email protected] pub]#  yum install -y bind bind-chroot bind-utils
      Installed:
        bind.i686 32:9.8.2-0.17.rc1.el6_4.6                                                                                      

      Complete! 

2、修改配置檔案“/etc/named.conf”,追加“forward”
      [[email protected] pub]#  gedit /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;
      dnssec-lookaside auto;

      /* Path to ISC DLV key */
      bindkeys-file "/etc/named.iscdlv.key";

      managed-keys-directory "/var/named/dynamic";
      forward only;
      forwarders{
       8.8.8.8;
      }
      };

3、設定防火牆,這裡需要用到53埠。需要開啟tcp和udp的53埠,記得重啟防火牆 
      [[email protected] pub]#  gedit /etc/sysconfig/iptables
      -A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
       -A INPUT -m state --state NEW -m tcp -p tcp --dport 53 -j ACCEPT
      -A INPUT -m state --state NEW -m udp -p udp --dport 53 -j ACCEPT


      [[email protected] phpMyAdmin]#  service iptables restart
      iptables:將鏈設定為政策 ACCEPT:filter nat                [確定]
      iptables:清除防火牆規則:                                 [確定]
      iptables:正在解除安裝模組:                                   [確定]
      iptables:應用防火牆規則:                                 [確定]
      iptables:載入額外模組:nf_conntrack_ftp                   [確定]
      [[email protected] phpMyAdmin]# 

4、啟動服務
      [[email protected] pub]#  service named start
      啟動 named:                                               [確定]
      [[email protected] pub]# 

5、測試,命令格式“dig 網站 @ip”,這裡用迴環地址來測試,看是否能請求成功
      [[email protected] pub]#  dig www.baidu.com @127.0.0.1
      ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>> www.baidu.com @127.0.0.1
      ;; global options: +cmd
      ;; Got answer:
      ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51491
      ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0
      ;; QUESTION SECTION:
      ;www.baidu.com. IN A
      ;; ANSWER SECTION:
       www.baidu.com. 1191 IN CNAME www.a.shifen.com.
      www.a.shifen.com. 299 IN A 14.215.177.38      //這個就是請求到的結果
      www.a.shifen.com. 299 IN A 14.215.177.39

      ;; Query time: 3053 msec
      ;; SERVER: 127.0.0.1#53(127.0.0.1)
      ;; WHEN: Tue Aug 14 19:02:59 2018
      ;; MSG SIZE  rcvd: 90


6、更改配置檔案named.conf,讓所有機器都可以使用該服務。
1)將配置檔案中的迴環地址改為any,意味著允許任何人使用
      [[email protected] pub]#  gedit /etc/named.conf
      options {
      listen-on port 53 {any; };
      # 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 yes;
      dnssec-validation yes;
      dnssec-lookaside auto;

      /* Path to ISC DLV key */
      bindkeys-file "/etc/named.iscdlv.key";

      managed-keys-directory "/var/named/dynamic";
      forward only;
      forwarders{
             8.8.8.8;
      }
      };
2)找一個其他ip地址來測試
      [[email protected] pub]#  service named restart   //重啟服務
      停止 named:                                               [確定]
      啟動 named:                                               [確定]

      [[email protected] pub]# dig www.baidu.com @192.168.0.113
      ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.17.rc1.el6_4.6 <<>> www.baidu.com @192.168.0.113
      ;; global options: +cmd
      ;; Got answer:
      ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37134
      ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

      ;; QUESTION SECTION:
      ;www.baidu.com. IN A

      ;; ANSWER SECTION:
       www.baidu.com. 871 IN CNAME www.a.shifen.com.
      www.a.shifen.com. 299 IN A 14.215.177.39
      www.a.shifen.com. 299 IN A 14.215.177.38


      ;; Query time: 474 msec
      ;; SERVER: 192.168.0.113#53(192.168.0.113)
      ;; WHEN: Tue Aug 14 19:06:19 2018
      ;; MSG SIZE  rcvd: 90