站長部落格 - lutuni 的日誌 |
![]() ![]() |
2010/03/22
如何在Ubuntu上安裝DNS BIND
作者: lutuni (2:08 pm)
|
安裝 [編輯] 如何在Ubuntu上安裝DNS BIND 你可以直接在命令列上輸入下列指令: sudo apt-get install bind [編輯] 如何在Fedora上安裝DNS BIND 你可以直接在命令列上輸入下列指令: yum -y install bind [編輯] 如何在Debian上安裝DNS BIND 你可以直接在命令列上輸入下列指令: apt-get install bind9 [編輯] 設定 [編輯] Ubuntu的設定 config 設定檔的放置路徑如下: /etc/bind/named.conf [編輯] Fedora的設定 config 設定檔的放置路徑如下: /var/named/chroot/etc/named.conf [編輯] Debian的設定 config 設定檔的放置路徑如下: /etc/bind/named.conf [編輯] named.conf 檔案內容 named.conf 檔案主要的內容包含4個部分,分別為: 1.options 2.關於 .(root) 的內容 3.關於 localhost 的正反解 4.關於其他 domain 的正反解 一個完整的 named.conf 的檔案如下: acl internals { 192.168.10.0/24; }; options { directory "/var/named"; allow-transfer{ 192.168.11.7; internals; }; }; controls { inet 127.0.0.1 allow { localhost; } keys { rndckey; }; }; zone "." { //.(root) 的內容 type hint; file "root.servers"; }; zone "localhost"{ //localhost 的正解 type master; file "master.localhost"; }; zone "0.0.127.in-addr.arpa"{ //localhost 的反解 type master; file "localhost.rev"; }; zone "twnic.com.tw"{ //使用者domain的正解 type master; file "twnic.hosts"; }; zone "10.168.192.in-addr.arpa"{ //使用者domain的反解 type master; file "twnic.rev"; }; master.localhost檔案範例如下: $TTL 86400 ; 24 hours could have been written as 24h $ORIGIN localhost. ; line below = localhost 1D IN SOA localhost root.localhost @ 1D IN SOA @ root ( 2002022401 ; serial 3H ; refresh 15 ; retry 1w ; expire 3h ; minimum ) @ 1D IN NS @ 1D IN A 127.0.0.1 localhost.rev檔案範例如下: $TTL 86400 ; ; could use $ORIGIN 0.0.127.IN-ADDR.ARPA. @ IN SOA localhost. root.localhost. ( 1997022700 ; Serial 3h ; Refresh 15 ; Retry 1w ; Expire 3h ) ; Minimum IN NS localhost. 1 IN PTR localhost. [編輯] 如何使用 [編輯] 如何啟動 BIND Server FOR Redhat / Fedora chkconfig 指令能幫您設定在開機時啟動BIND: chkconfig named on 在開機後啟動,關閉,重新啟動BIND的指令如下: /etc/init.d/named start /etc/init.d/named stop /etc/init.d/named restart FOR Debian / Ubuntu sysv-rc-conf 指令能幫您設定在開機時啟動BIND: sysv-rc-conf bind on 在開機後啟動,關閉,重新啟動BIND的指令如下: /etc/init.d/bind start /etc/init.d/bind stop /etc/init.d/bind restart [編輯] 如何測試 DNS 是否正常運作 The Host Command host 指令接參數,用來查詢正反解並顯示出結果,用法如下 使用 host 查詢正解 host www.linuxhomenetworking.com 使用 host 查詢反解 host 65.115.71.34 The nslookup Command nslookup 指令接參數,用來查詢正反解並顯示出結果,用法如下 使用 nslookup 查詢正解 nslookup www.linuxhomenetworking.com 使用 nslookup 查詢反解 nslookup 65.115.71.34 [編輯] 如何設定 sub-domain sub-domain 的定義為: zone (domain) name = example.com domain host name = bill.example.com sub-domain name = us.example.com sub-domain host name = ftp.us.example.com 若要設定 sub-domain,其 named.conf 檔可參考下面的設定: // named.conf file fragment .... options { .... // stop everyone allow-transfer {"none";}; .... }; zone "example.com" in{ type master; file "master/master.example.com"; // explicitly allow slave allow-transfer {192.168.0.4;}; }; master.example.com 檔可參考下面的設定: ; zone fragment for 'zone name' example.com ; name servers in the same zone $TTL 2d ; zone default TT = 2 days $ORIGIN example.com. @ IN SOA ns1.example.com. hostmaster.example.com. ( 2003080800 ; serial number 2h ; refresh = 2 hours 15M ; update retry = 15 minutes 3W12h ; expiry = 3 weeks + 12 hours 2h20M ; minimum = 2 hours + 20 minutes ) ; main domain name servers IN NS ns1.example.com. IN NS ns2.example.com. ; mail servers for main domain IN MX 10 mail.example.com. ; A records for name servers above ns1 IN A 192.168.0.3 ns2 IN A 192.168.0.4 ; A record for mail servers above mail IN A 192.168.0.5 ; other domain level hosts and services bill IN A 192.168.0.6 .... ; sub-domain definitions $ORIGIN us.example.com. IN MX 10 mail ; record above could have been written as ; us.example.com. IN MX 10 mail.us.example.com. ; A record for subdomain mail server mail IN A 10.10.0.28 ; the record above could have been written as ; mail.us.example.com. A 10.10.0.28 if it's less confusing ftp IN A 10.10.0.29 ; the record above could have been written as ; ftp.us.example.com. A 10.10.0.29 if it's less confusing .... ; other subdomain definitions as required [編輯] 如何設定 forwarding DNS Forwarding DNS 主機主要做為一個中間傳遞資料的角色,將用戶端所需要查詢的資訊轉交給其它合法的 DNS 主機代為查詢,因此 forwarding DNS 本身並沒有提供主機名稱與 IP 正反解的設定檔。 要設定一台 DNS 為 forwarding ,請編輯主要設定檔 named.conf 如下: options { directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; forward only; forwarders { 192.168.0.1; }; }; include "/etc/rndc.key"; 其中各參數的意義: forward only 指示這台 DNS 只做為 forwarding DNS。 forwarders 設定把我們的查詢 forward 給哪台 DNS 來幫我們代查,可設定多台 forwarders 。 |
本篇文章引用網址
http://123.204.89.156/etype/modules/weblog/weblog-tb.php/30