Bind 安裝與配置

來源:互聯網
上載者:User
一.、Bind 簡介。
Bind是一款開放源碼的DNS伺服器軟體,Bind由美國加州大學Berkeley分校開發和維護的,全名為Berkeley Internet Name Domain它是目前世界上使用最為廣泛的DNS伺服器軟體,支援各種unix平台和windows平台。本文將介紹它在Red hat Linux 9中最基本的安裝和配置。
二.、軟體的相關資源。
官方網站:http://www.bind.com/
源碼軟體包:Bind 是開源的軟體,可以去其官方網站下載。http://www.isc.org/index.pl/sw/bind/ ,目前最新版本為bind-9.3.1。
協助文檔:http://www.isc.org/index.pl/sw/bind/ 有該軟體比較全面的協助文檔。
FAQ:http://www.isc.org/index.pl/sw/bind/ 回答了該軟體的常見問題。
設定檔範例:http://www.bind.com/bind.html 一些比較標準的設定檔範例。
三.、軟體的安裝。
1.安裝
由其官方網站中下載其源碼軟體包bind-9.3.1. tar.gz。接下來我將對安裝過程的一些重要步驟,給出其解釋:
[root@localhost root]#tar xzvf bind-9.3.1. tar.gz
[root@localhost root]#cd bind-9.3.1
[root@localhost bind-9.3.1]#./configure
[root@localhost bind-9.3.1]#make
[root@localhost bind-9.3.1]#make install
tar xzvf bind-9.3.1.tar.gz 解壓縮軟體包。
./configure 針對機器作安裝的檢查和設定,大部分的工作是由機器自動完成的,但是使用者可以通過一些參數來完成一定的設定,其常用選項有:
./configure --help 察看參數設定協助。
--prefix= 指定軟體安裝目錄(預設/usr/local/)。
--enable-ipv6 支援ipv6。
可以設定的參數很多,可以通過 -help察看需要的,一般情況下,預設設定就可以了。
預設情況下,安裝過程是不會建立設定檔和一些預設的網域名稱解析的,不過並不妨礙,可以從下載一些標準的設定檔(http://www.bind.com/bind.html),也可以使用本文所提供的範例檔案。
預設情況下,安裝的deamon為/usr/local/sbin/named
預設的主設定檔,/etc/named.conf(須手動建立)。
2.啟動:
[root@localhost root]# /usr/local/sbin/named -g
/usr/local/sbin/named預設情況是一個後台deamon ,-g選項表示前台運行,並將調試資訊列印到標準輸出,這在我們安裝調試階段是非常有協助的。
如果建立了設定檔和網域名稱解析檔案(關於怎樣建立將在下面的部分講到),ps aux 應該可以查到named 的進程,或netstat -an 也可以看到53連接埠的服務已經起來了。(DNS預設連接埠為53)
如果要設定開機自啟動DNS server,只需在/etc/rc.d/rc.local中加入一行
/usr/local/sbin/named
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/usr/local/sbin/named
四.軟體的配置。
1.主設定檔
預設安裝主設定檔的位置為
/etc/named.conf
下面逐步分析一個比較基礎的設定檔:(註:named設定檔採用和c語言相同的注釋符號)。
(1) log options
/*
 * log option
 */
logging {
    channel default_syslog { syslog local2; severity error; };
    channel audit_log { file "/var/log/named.log"; severity error; print-time yes; };
    category default { default_syslog; };
    category general { default_syslog; };
    category security { audit_log; default_syslog; };
    category config { default_syslog; };
    category resolver { audit_log; };
    category xfer-in { audit_log; };
    category xfer-out { audit_log; };
    category notify { audit_log; };
    category client { audit_log; };
    category network { audit_log; };
    category update { audit_log; };
    category queries { audit_log; };
    category lame-servers { audit_log; };
};
這一部分是日誌的設定,其中最主要的是
file "/var/log/named.log" 這一句指定了記錄檔的位置,要正常啟動named,必須要保證這一檔案是存在的,並且named 進程對它有讀寫權限。
(2) options
options {
    directory "/etc/namedb";
    listen-on-v6 { any; };
// If you've got a DNS server around at your upstream provider, enter
// its IP address here, and enable the line below.  This will make you
// benefit from its cache, thus reduce overall DNS traffic in the Internet.
    forwarders {
        your.upper.DNS.address;
    };
    /*
     * If there is a firewall between you and nameservers you want
     * to talk to, you might need to uncomment the query-source
     * directive below.  Previous versions of BIND always asked
     * questions using port 53, but BIND 8.1 uses an unprivileged
     * port by default.
     */
    // query-source address * port 53;
    /*
     * If running in a sandbox, you may have to specify a different
     * location for the dumpfile.
     */
    dump-file "/etc/named_dump.db";
};
這一部分是一些基本的配置項:
directory "/etc/namedb"; 指定網域名稱解析等檔案的存放目錄(須手動建立);
listen-on-v6 { any; }; 支援ipv6的請求;
forwarders {
your.upper.DNS.address;
}; 指定前向DNS,當本機無法解析的網域名稱,就會被轉寄至前向DNS進行解析。
dump-file "/etc/named_dump.db"; 指定named_dump.db檔案的位置。
(3) 線索域和迴環域
// Setting up secondaries is way easier and the rough picture for this
// is explained below.
//
// If you enable a local name server, don't forget to enter 127.0.0.1
// into your /etc/resolv.conf so this server will be queried first.
// Also, make sure to enable it in /etc/rc.conf.
zone "." {
    type hint;
    file "named.root";
};
zone "0.0.127.IN-ADDR.ARPA" {
    type master;
    file "localhost.rev";
};
指定線索域和本地迴環域,這一部分使用一些標準的例子就可以。
file "named.root"; 指定該域的解析檔案,其目錄為options中directory "/etc/namedb";指定的。在本例中為/etc/namdb。
(4)自訂網域
zone "test.com" {
    type    master;
    file    "zone.test ";
};
zone "0.168.192.in-addr.arpa" {
    type    master;
    file    "zone. test.rev";
};
zone "4.0.0.f.0.5.2.0.1.0.0.2.IP6.ARPA" {    
    type master;
    allow-transfer { any;};
        allow-query { any; };        
    file "ipv6.rev";
};
zone "lowerlevelzone.test.com" {
    type    slave;
        masters {
        192.168.1.1;
    };
};
這一部分是設定檔中我們需要重點關心的部分:
zone "test.com" {
type master;
file "zone.test ";
}; 設定test.com域;
type master 指明該域主要由本機解析;
file "zone.test "指定其解析檔案為zong.test,目錄為options中設定的目錄本例中為/etc/named。
zone "0.168.192.in-addr.arpa" {
type master;
file "zone. test.rev";
}; 指定ipv4地址逆向解析
type master 指明該域主要由本機解析;
file "zone.test.rev "指定其解析檔案為zong.test.rev,目錄為options中設定的目錄本例中為/etc/named。
zone "4.0.0.f.0.5.2.0.1.0.0.2.IP6.ARPA" {
type master;
allow-transfer { any;};
allow-query { any; };
file "ipv6.rev";
};指定ipv4地址逆向解析
type master 指明該域主要由本機解析;
file " ipv6.rev "指定其解析檔案為ipv6.rev,目錄為options中設定的目錄本例中為/etc/named。
zone "lowerlevelzone.test.com" {
type slave;
masters {
192.168.1.1;
};
}; 設定lowerlevelzone.test.com域;
type slave 指明該域主要由低一級的網域名稱伺服器解析;
masters {
192.168.1.1;
}; 指定低一級的網域名稱伺服器ip地址。
到此我們就初步建立了一個標準的named 的主設定檔,接下來建立對應的網域名稱解析或逆向解析檔案。
2.網域名稱解析和IP地址逆向解析檔案:
(1) 網域名稱解析:
/etc/namedb/zone.test

;    From: @(#)localhost.rev    5.1 (Berkeley) 6/30/90
; $FreeBSD: src/etc/namedb/PROTO.localhost.rev,v 1.6 2000/01/10 15:31:40 peter Exp $
;
; This file is automatically edited by the `make-localhost' script in
; the /etc/namedb directory.
;
@    IN    SOA    ns.test.com. root.test.com.(
                2005030116; Serial
                3600    ; Refresh
                900    ; Retry
                3600000    ; Expire
                3600 )    ; Minimum
    IN    NS    ns.test.com
;
ns        IN    A    192.168.0.1
www6    IN    AAAA    2001:250:f004::10
www    IN    A    192.168.0.2
本檔案前半部分是一些預設的參數設定,只需把網域名稱改成對應得你要設定的域就行,其餘的不用過分深究,如果讀者有興趣可以查閱相關的手冊文檔。
(注意,
IN NS ns.test.com;
這一條必須有,來指定本域的網域名稱伺服器 ;
網域名稱必須以"."結尾。)
本檔案的第二部分(倒數三行),指定了該域上的主機:
ns IN A 192.168.0.1
ns 為主機名稱,A 代表地址類型為IPV4地址,192.168.0.1 是實際ip地址,這一條記錄的含義是ns.test.com 的ip地址為 192.168.0.1
www6 IN AAAA 2001:250:f004::10
www6 為主機名稱,AAAA代表地址類型為IPV6地址,2001:250:f004::10 是其IPV6地址,這條記錄的含義是www6.test.com 的ip地址是2001:250:f004::10 。
(2)IP地址逆向解析:
ipv4 逆向解析:
/etc/namedb/zone.test.rev
;    From: @(#)localhost.rev    5.1 (Berkeley) 6/30/90
; $FreeBSD: src/etc/namedb/PROTO.localhost.rev,v 1.6 2000/01/10 15:31:40 peter Exp $
;
; This file is automatically edited by the `make-localhost' script in
; the /etc/namedb directory.
;
@    IN    SOA    ns.test.com. root.test.com.(
                2005030116; Serial
                3600    ; Refresh
                900    ; Retry
                3600000    ; Expire
                3600 )    ; Minimum
    IN    NS    ns.test.com
;
1    IN    PTR        ns.test.com.
2    IN    PTR        www.test.com.
ipv6 逆向解析:
/etc/namedb/zone.test.rev
;    From: @(#)localhost.rev    5.1 (Berkeley) 6/30/90
; $FreeBSD: src/etc/namedb/PROTO.localhost.rev,v 1.6 2000/01/10 15:31:40 peter Exp $
;
; This file is automatically edited by the `make-localhost' script in
; the /etc/namedb directory.
;
@    IN    SOA    ns.test.com. root.test.com.(
                2005030116; Serial
                3600    ; Refresh
                900    ; Retry
                3600000    ; Expire
                3600 )    ; Minimum
    IN    NS    ns.test.com
;
10.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0        IN    www6.test.com.
這裡
10.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0 IN www6.test.com.
與主設定檔/etc/named.conf中的
zone "4.0.0.f.0.5.2.0.1.0.0.2.IP6.ARPA"
"10.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0" + "4.0.0.f.0.5.2.0.1.0.0.2" 剛好組成點分的32位16進位逆序ipv6地址。
實際上,ip地址逆向解析由於缺乏統一的管理和相關的標準,這項服務的使用比較混亂,可以考慮不啟動該服務。所以在這裡只給出兩個例子,就不過多解釋了。
五.安裝使用的一些經驗:
1.帶調試資訊的啟動
named -g
/usr/local/sbin/named預設情況是一個後台deamon ,-g選項表示前台運行,並將調試資訊列印到標準輸出,這在我們安裝調試階段是非常有協助的。
2.用戶端命令nslookup簡介
windows ,linux 平台均支援此調試命令。
鍵入nslookup即進入與伺服器互動狀態,這時鍵入網域名稱或ip地址就可以向伺服器正向或逆向查詢。
>www.test.com 正向網域名稱解析
>192.168.0.1 逆向IP解析
>set type=AAAA 設定查詢地址類型為IPv6地址類型。
>set type=A 設定查詢地址類型為IPv4地址類型。
>exit 退出。
參考資料:
[1]:http://www.bind.com/
[2]:http://www.isc.org/index.pl?/sw/bind/
[3]:ipv6.bupt.edu.cn   

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.