標籤:style blog http color os 使用 strong 檔案 ar
本文首發於爛泥行天下。
要在centos配置DNS伺服器,要先安裝DNS軟體BIND。當然我們也可以安裝其他的DNS軟體,比如國內的開源DNS軟體DNSPod。
在此我們以通過DNS軟體BIND為例,進行實驗。
本次實驗:OS centos6.5 64bit
安裝DNS軟體,使用如下命令:
yum -y install bind bind-chroot bind-utils
650) this.width=650;" title="clip_image001" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image001" src="http://img1.51cto.com/attachment/201408/27/526870_1409105988flb1.png" width="664" height="247" />
650) this.width=650;" title="clip_image002" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image002" src="http://img1.51cto.com/attachment/201408/27/526870_1409105988sgnY.png" width="642" height="189" />
BIND設定檔儲存在兩個主要位置:
/etc/named.conf 這個是BIND服務主設定檔
/var/named/ 這個是用來存放DNS的zone檔案
如果安裝了bind-chroot,BIND會被封裝到一個偽根目錄內,原來設定檔的位置會變為:
/var/named/etc/named.conf和/var/named/var/named/
chroot是通過將相關檔案封裝在一個偽根目錄內,來達到安全防護的目的。一旦該程式被攻破,將只能訪問偽根目錄內的內容,而不是真實的根目錄。
bind剛剛安裝完畢後,設定檔內容是空的。我們可以通過bind的協助文檔來進行配置,因為bind配置的參數比較多,強烈建議在協助文檔的基礎通過bind提供的模版上進行配置。查看bind的配置,如下:
rpm –ql bind |tac
650) this.width=650;" title="clip_image003" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image003" src="http://img1.51cto.com/attachment/201408/27/526870_1409105988N6wS.png" width="621" height="282" />
分別複製/usr/share/doc/bind-9.8.2/sample/var/和/usr/share/doc/bind-9.8.2/sample/etc/目錄下的檔案,到/var/named/chroot/var/和/var/named/chroot/etc/目錄下,如下:
cp -rv /usr/share/doc/bind-9.8.2/sample/var/* /var/named/chroot/var/
650) this.width=650;" title="clip_image004" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image004" src="http://img1.51cto.com/attachment/201408/27/526870_14091059897eTV.png" width="1023" height="203" />
cp -rv /usr/share/doc/bind-9.8.2/sample/etc/* /var/named/chroot/etc/
650) this.width=650;" title="clip_image005" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image005" src="http://img1.51cto.com/attachment/201408/27/526870_1409105989028i.png" width="775" height="98" />
配置模版複製完畢後,我們先來修改bind的主設定檔/var/named/chroot/etc/named.conf,如下:
vi /var/named/chroot/etc/named.conf
650) this.width=650;" title="clip_image006" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image006" src="http://img1.51cto.com/attachment/201408/27/526870_1409105990xhhR.png" width="578" height="536" />
我們會發現該設定檔中,有很多選項。在此為了實驗的簡單性,我們刪除其他暫時不需要的,只保留bind最基本的功能。如下:
650) this.width=650;" title="clip_image007" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image007" src="http://img1.51cto.com/attachment/201408/27/526870_14091059904K4o.png" width="589" height="459" />
此檔案我們只保留了,bind的工作目錄/var/named/,然後指定bind監聽的連接埠及IP地址。
以上我們配置了bind的設定檔,如果只是按照上邊的操作,我們的dns還沒有不能正常工作。因為沒有建立相關的域,下面我們來建立一個主網域服務器。
首先要在bind的設定檔中,添加一個主域的定義。如下:
650) this.width=650;" title="clip_image008" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image008" src="http://img1.51cto.com/attachment/201408/27/526870_14091059900baG.png" width="580" height="531" />
zone "ilanni.com"{
type master;
file "ilanni.com.zone";
};
zone "ilanni.com" 定義ilanni.com域
type master;定義該域為主網域服務
file "ilanni.com.zone"定義域的zone檔案,該檔案在/var/named/chroot/var/named/目錄下。
現在我們來建立ilanni.com域的zone檔案,預設情況下bind是沒有產生該檔案的,需要我們手工添加,但是在前邊我們提到過由於bind的設定檔比較複雜,所以我們建議還是使用bind為我們提供的模版檔案named.localhost。如下:
650) this.width=650;" title="clip_image009" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image009" src="http://img1.51cto.com/attachment/201408/27/526870_1409105991jCML.png" width="479" height="409" />
複製named.localhost檔案並重新命名為ilanni.com.zone,如下:
cp named.localhost ilanni.com.zone
650) this.width=650;" title="clip_image010" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image010" src="http://img1.51cto.com/attachment/201408/27/526870_14091059912M9S.png" width="478" height="65" />
現在開始編輯ilanni.com.zone檔案,並在其中加入相關的位址解析。如下:
vi ilanni.com.zone
650) this.width=650;" title="clip_image011" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image011" src="http://img1.51cto.com/attachment/201408/27/526870_1409105991rHSc.png" width="458" height="253" />
我們只需要在該檔案的最後添加新的資源記錄即可,一個資源記錄一般是由四部分組成。第一部分是主機名稱,第二部分是類型,第三分部是分類,其中A代表IPv4地址,第四部分代表IP地址。
注意在此我們添加了三條資源記錄,第一條是有關郵件的資源記錄,郵件資源記錄一定要寫在其他資源記錄的前邊,並且郵件資源記錄是已網域名稱的形式出現,並且網域名稱後邊最後還有一個點。
這樣我們的ilanni.com.zone檔案就已經配置完畢後,下面我們在檢查下/var/named/chroot/var/named目錄下,所有檔案的屬性,一定要具有可讀屬性。如下:
650) this.width=650;" title="clip_image012" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image012" src="http://img1.51cto.com/attachment/201408/27/526870_1409105992o76j.png" width="447" height="237" />
以上全部配置完畢後,我們就可以來啟動bind。使用以下命令:
/etc/init.d/named start
如果bind已經啟動,我們也可以通過/etc/init.d/named reload命令重新載入設定檔。如下:
650) this.width=650;" title="clip_image013" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image013" src="http://img1.51cto.com/attachment/201408/27/526870_14091059920fur.png" width="535" height="183" />
由於這台機器本身已經搭建DHCP伺服器,所以我們現在來修改用戶端在通過DHCP服務擷取到的DNS地址,如下:
650) this.width=650;" title="clip_image014" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image014" src="http://img1.51cto.com/attachment/201408/27/526870_1409105993VD7Y.png" width="402" height="333" />
其中10.5.5.1是原生IP地址。
現在我們來看看用戶端擷取到的IP地址,如下:
650) this.width=650;" title="clip_image015" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image015" src="http://img1.51cto.com/attachment/201408/27/526870_14091059933MwZ.png" width="709" height="390" />
先使用nslookup命令進行測試,如下:
650) this.width=650;" title="clip_image016" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image016" src="http://img1.51cto.com/attachment/201408/27/526870_14091059933zrQ.png" width="456" height="261" />
現在使用host命令測試www.ilanni.com和ftp.ilanni.com的IP地址,如下:
host www.ilanni.com
host ftp.ilanni.com
650) this.width=650;" title="clip_image017" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image017" src="http://img1.51cto.com/attachment/201408/27/526870_1409105994zLV1.png" width="396" height="127" />
通過,我們可以很明顯的看到目前www.ilanni.com和ftp.ilanni.com已經發解析出來,這個和我們再BIND上的配置是相同的。
現在再使用dig命令測試郵件伺服器的IP地址,如下:
dig –t MX ilanni.com
650) this.width=650;" title="clip_image018" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image018" src="http://img1.51cto.com/attachment/201408/27/526870_1409105994uvbQ.png" width="670" height="409" />
通過,我們可以很明顯的看到郵件伺服器已經正確解析到10.5.5.3這台伺服器上。
也可以通過dig命令測試www及ftp的解析情況,如下:
dig -t A www.ilanni.com
650) this.width=650;" title="clip_image019" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image019" src="http://img1.51cto.com/attachment/201408/27/526870_1409105995aTeY.png" width="730" height="467" />
dig -t A ftp.ilanni.com
650) this.width=650;" title="clip_image020" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image020" src="http://img1.51cto.com/attachment/201408/27/526870_14091059953mbY.png" width="726" height="413" />
現在我們再通過最實際的效果來訪問下10.5.5.3上已經搭建的web伺服器,如下:
650) this.width=650;" title="clip_image021" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;margin:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image021" src="http://img1.51cto.com/attachment/201408/27/526870_1409105996rcjV.png" width="1098" height="402" />
650) this.width=650;" title="clip_image022" style="border-right-width:0px;background-image:none;border-bottom-width:0px;padding-top:0px;padding-left:0px;padding-right:0px;border-top-width:0px;" border="0" alt="clip_image022" src="http://img1.51cto.com/attachment/201408/27/526870_1409105996DEnG.png" width="707" height="573" />
到此有關centos的DNS安裝及簡易配置已經全部結束。
本文出自 “爛泥行天下” 部落格,請務必保留此出處http://ilanni.blog.51cto.com/526870/1545510
爛泥:centos安裝及配置DNS伺服器