歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> 我的dns配置過程

我的dns配置過程

日期:2017/2/27 14:15:41   编辑:更多Linux
  安裝過程如下: # apt-get install bind9 安裝完畢後,用命令whereis bind可以發現bind安裝在/etc/bind目錄下,進入/etc/bind目錄,看到目錄下有這些文件: db.0 db.127 db.255 db.empty db.local db.rev db.root named.conf named.conf.local named.conf.options rndc.key 其中的關鍵文件是named.conf,我們可以查看它的內容: // This is the primary configuration file for the BIND DNS server named. // // Please read /usr/share/doc/bind9/README.Debian.gz for information on the // strUCture of BIND configuration files in Debian, *BEFORE* you customize // this configuration file. // // If you are just adding zones, please do that in /etc/bind/named.conf.local include "/etc/bind/named.conf.options"; // prime the server with knowledge of the root servers zone "." { type hint; file "/etc/bind/db.root"; }; // be authoritative for the localhost forward and reverse zones, and for // broadcast zones as per RFC 1912 zone "localhost" { type master; file "/etc/bind/db.local"; }; zone "127.in-addr.arpa" { type master; file "/etc/bind/db.127"; }; zone "0.in-addr.arpa" { type master; file "/etc/bind/db.0"; }; zone "255.in-addr.arpa" { type master; file "/etc/bind/db.255"; }; include "/etc/bind/named.conf.local"; 我們注意到此文件include 兩個文件"/etc/bind/named.conf.options"和 "/etc/bind/named.conf.local",此外是一些DNS解析區域及其記錄文件。在此文件的注釋裡提示,如果要增加區域的話,可以編輯/etc/bind/named.conf.local。 文件/etc/bind/named.conf.options的內容如下: options { Directory "/var/cache/bind"; // 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 and later use an unprivileged // port by default. // query-source address * port 53; // If your ISP provided one or more IP addresses for stable // nameservers, you probably want to use them as forwarders. // Uncomment the following block, and insert the addresses replacing // the all-0's placeholder. // forwarders { // 0.0.0.0; // }; auth-nxdomain no; # conform to RFC1035 }; 文件/etc/bind/named.conf.local的內容如下,基本沒有內容: // // Do any local configuration here // // Consider adding the 1918 zones here, if they are not used in your


// organization //include "/etc/bind/zones.rfc1918"; 從以上內容可以看出,除DNS的本地域名外,其它部分已經正常。要增加本地域名解析只要編輯/etc/bind/named.conf.local,並增加相應記錄文件即可。本目錄下的其它文件不必更改。 這時可以作一些測試。筆者的測試環境如下:三台電腦,一台裝debian,一台裝redhat8,一台裝win98,准備設置根域名為home,相應的域名與IP對應關系如下: debian.home 192.168.10.103 win98.home 192.168.10.102 rh8.home 192.168.10.101 在安裝DNS前,各台機子的DNS設置為202.101.98.54,這是福建省的域名服務器,各台電腦間的互訪通過hosts文件解析。 在debian機子上, /etc/resolve.conf的內容如下: domain home. nameserver 202.101.98.54 /etc/hosts的內容如下: ### etherconf DEBCONF AREA. DO NOT EDIT THIS AREA OR INSERT TEXT BEFORE IT. 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts 192.168.10.103 debian.home debian ### END OF DEBCONF AREA. PLACE YOUR EDITS BELOW; THEY WILL BE PRESERVED. 192.168.10.102 win98.home win98 192.168.10.101 winme.home winme 在redhat8電腦上的配置與此類似。 在win98電腦上建立的/windows/hosts文件內容如下: 192.168.10.103 debian.home debian 192.168.10.102 win98.home win98 192.168.10.101 winme.home winme 也就是說在使用DNS前,它們用域名訪問internet或互訪都是正常。但現在我們要安裝DNS,所以必須先它們去掉,才能知道所安裝的DNS是否正常。步驟如下: 在debian機子上, 修改/etc/resolve.conf的內容如下: domain home. nameserver 192.168.10.103 /etc/hosts的內容如下: ### etherconf DEBCONF AREA. DO NOT EDIT THIS AREA OR INSERT TEXT BEFORE IT. 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts 192.168.10.103 debian.home debian ### END OF DEBCONF AREA. PLACE YOUR EDITS BELOW; THEY WILL BE PRESERVED. 在redhat8電腦上的配置與此類似。 在win98電腦上刪除/windows/hosts文件。並打開控制面板,選網絡,再選TCP/IP,在“首選DNS”裡面,輸入DNS為192.168.10.103,點擊確定,重啟電腦。 此時你會發現,三台電腦用域名互訪不行了,但訪問internet上的域名,比如www.Linuxsir.com都可以。因此接下來的步驟是增加本地域名解析,即編輯/etc/bind/named.conf.local,並增加相應記錄文件。方法我推薦使用webmin-bind。當然如果你對記錄文件格式很熟悉的話,可以手工編輯。我開始是采用手工編輯,浪費很多時間,直到我發現了webmin-bind。 #apt-get install webmin webmin-bind 安裝完成後,在游覽器的URL裡輸入https://localhost:10000/,輸入用戶名及密碼進入webmin,即可看到BIND DNS服務器,點擊進入,點擊創建主區域,在出現的新建主區域選項中的區域類型單選框選正向(名稱至地址),在域名 / 網絡編輯框中輸入home,在主服務器編輯框中輸入debian.home,在Email 地址編輯框中輸入root.debian.home,其它按默認。點擊保存。再點擊home主區域,點擊地址,增加三條地址記錄。

再次點擊創建主區域,在出現的新建主區域選項中的區域類型單選框選反向(地址至名稱),在域名 / 網絡編輯框中輸入192.168.10,在主服務器編輯框中輸入debian.home,在Email 地址編輯框中輸入root.debian.home,其它按默認。點擊保存。再點擊192.168.10主區域,點擊反向地址,增加三條地址記錄。 單擊啟動名字服務器按鈕運行 BIND 服務器, 並裝載當前配置。這樣就完成了增加本地域名解析的工作,DNS也大功告成了。可以在各台電腦上測試一下,用域名訪問internet或互訪都不成問題。 但我們需要進一步知道webmin-bind作了哪些修改。 這時的/etc/bind/named.conf的內容如下: // This is the primary configuration file for the BIND DNS server named. // // Please read /usr/share/doc/bind9/README.Debian.gz for information on the // structure of BIND configuration files in Debian, *BEFORE* you customize // this configuration file. // // If you are just adding zones, please do that in /etc/bind/named.conf.local include "/etc/bind/named.conf.options"; // prime the server with knowledge of the root servers zone "." { type hint; file "/etc/bind/db.root"; }; // be authoritative for the localhost forward and reverse zones, and for // broadcast zones as per RFC 1912 zone "localhost" { type master; file "/etc/bind/db.local"; }; zone "127.in-addr.arpa" { type master; file "/etc/bind/db.127"; }; zone "0.in-addr.arpa" { type master; file "/etc/bind/db.0"; }; zone "255.in-addr.arpa" { type master; file "/etc/bind/db.255"; }; include "/etc/bind/named.conf.local"; zone "home" { type master; file "/var/cache/bind/home.hosts"; }; zone "10.168.192.in-addr.arpa" { type master; file "/var/cache/bind/192.168.10.rev"; }; 我們可以發現只是末尾增加了兩個zone。而且在/etc/bind/目錄下的其它文件都沒有改動,我們可以從文件的修改時間看出。增加的兩個記錄文件是/var/cache/bind/home.hosts,/var/cache/bind/192.168.10.rev。 它們的內容如下: /var/cache/bind/home.hosts的內容如下: $ttl 38400 home. IN SOA debian.home. root.debian.home. ( 1039102090 10800 3600 604800 38400 ) home. IN NS debian.home. debian.home. IN A 192.168.10.103 rh8.home. IN A 192.168.10.101 win98.home. IN A 192.168.10.102 /var/cache/bind/192.168.10.rev的內容如下: $ttl 38400 10.168.192.in-addr.arpa. IN SOA debian.home. root.debian.home. ( 1039102453 10800 3600 604800 38400 ) 10.168.192.in-addr.arpa. IN NS debian.home. 101.10.168.192.in-addr.arpa. IN PTR rh8.home. 102.10.168.192.in-addr.arpa. IN PTR win98.home. 103.10.168.192.in-addr.arpa. IN PTR debian.home. 這些格式與網上很多文章介紹的有些不同,所以我才想寫出來,希望其它初學者不要象我一樣,一頭霧水好幾天。 DNS設置完了後,如果不能保證DNS機子一直開著,可以在其它機子上加上其它DNS,比如202.101.98.54。以免 本地DNS機子關機的時候,不能通過域名訪問internet。



type master; file "/var/cache/bind/192.168.10.rev"; }; 我們可以發現只是末尾增加了兩個zone。而且在/etc/bind/目錄下的其它文件都沒有改動,我們可以從文件的修改時間看出。增加的兩個記錄文件是/var/cache/bind/home.hosts,/var/cache/bind/192.168.10.rev。 它們的內容如下: /var/cache/bind/home.hosts的內容如下: $ttl 38400 home. IN SOA debian.home. root.debian.home. ( 1039102090 10800 3600 604800 38400 ) home. IN NS debian.home. debian.home. IN A 192.168.10.103 rh8.home. IN A 192.168.10.101 win98.home. IN A 192.168.10.102 /var/cache/bind/192.168.10.rev的內容如下: $ttl 38400 10.168.192.in-addr.arpa. IN SOA debian.home. root.debian.home. ( 1039102453 10800 3600 604800 38400 ) 10.168.192.in-addr.arpa. IN NS debian.home. 101.10.168.192.in-addr.arpa. IN PTR rh8.home. 102.10.168.192.in-addr.arpa. IN PTR win98.home. 103.10.168.192.in-addr.arpa. IN PTR debian.home. 這些格式與網上很多文章介紹的有些不同,所以我才想寫出來,希望其它初學者不要象我一樣,一頭霧水好幾天。 DNS設置完了後,如果不能保證DNS機子一直開著,可以在其它機子上加上其它DNS,比如202.101.98.54。以免 本地DNS機子關機的時候,不能通過域名訪問internet。



/var/cache/bind/192.168.10.rev的內容如下: $ttl 38400 10.168.192.in-addr.arpa. IN SOA debian.home. root.debian.home. ( 1039102453 10800 3600 604800 38400 ) 10.168.192.in-addr.arpa. IN NS debian.home. 101.10.168.192.in-addr.arpa. IN PTR rh8.home. 102.10.168.192.in-addr.arpa. IN PTR win98.home. 103.10.168.192.in-addr.arpa. IN PTR debian.home. 這些格式與網上很多文章介紹的有些不同,所以我才想寫出來,希望其它初學者不要象我一樣,一頭霧水好幾天。 DNS設置完了後,如果不能保證DNS機子一直開著,可以在其它機子上加上其它DNS,比如202.101.98.54。以免 本地DNS機子關機的時候,不能通過域名訪問internet。



Copyright © Linux教程網 All Rights Reserved