這當然又是老闆給的課題,要把 DNS Server 放到 VM 上,因為沒有在 Ubuntu 上安裝過 DNS Server,當然要記錄一下囉!
參考:SmallKen's Blog、Community Ubuntu Documentation、Raining Packets、Ubuntu Forums
這次用的作業系統為:Ubuntu 10.10 Server,Bind 版本為:9.7.1.dfsg.P2-2ubuntu0.2。
一開始,一定是安裝 bind9 套件囉!執行下列的指令來進行安裝:
$ sudo apt-get install bind9 |
BIND9 在 Ubuntu 預設的設定檔位置是在:
/etc/bind
接下來就是編輯 named.conf 設定檔,因為是要轉到 VM 上,所以就偷懶去舊主機上複製貼上囉!不過發現 named.conf 會 include 幾個檔案:
/etc/bind/named.conf.options(全域 options 的設定放在此)
/etc/bind/named.conf.local
/etc/bind/named.default-zones(像一些制式的 zone 就放在這裡!若 named.conf 內有重複,會出現錯誤訊息,服務也會起不來)
就可以知道 Ubuntu 把 BIND 的設定檔分成好幾個,這樣就不會讓 named.conf 太長啦!
編輯 /etc/bind/named.options,加入下列幾行:
options { // If there is a firewall between you and nameservers you want // If your ISP provided one or more IP addresses for stable // forwarders { forwarders { |
加下列兩行,主要是為了給 Cacti 分析 BIND 用的:
zone-statistics yes;
statistics-file "/var/cache/bind/named.stats";
而加入下列這行,主要是不讓記錄檔出現錯誤訊息,還有些動作要做,後面會提:
managed-keys-directory "/etc/bind";
若要減輕 BIND 的載重,可以將非所轄網域查詢轉到其它 DNS Server 上,設定如下:
forwarders {
168.95.1.1; 139.175.10.20; 203.133.1.6;
};
不允許全域轉送(Master 跟 Slave 之間的資料傳送),加入下列這一行:
allow-transfer { none; };
完成後便可以存檔離開。
依照 /etc/bind/named.conf 中所需的 zone file,就從舊主機上直接複製囉!哈!
啟動 BIND 後就可以查詢記錄囉!
不過,在 /var/log/syslog 上會看到錯誤的訊息,雖然無傷大雅,但還是希望不要出現:
managed-keys-zone ./IN: loading from master file managed-keys.bind failed: file not found managed-keys-zone ./IN: loaded serial 0 |
1.在 /etc/bind/named.conf.options 加上 managed-keys-directory "/etc/bind";。
2.在 /etc/bind 上建立檔案 managed-keys.bind。
$ sudo touch /etc/bind/managed-keys.bind |
在重新啟的 BIND 之後,就不會出現找不到檔案的錯誤訊息了。
接下來想要對 BIND 記錄檔作分類,我是建了一個設定檔,/etc/bind/named.conf.logging,在 /etc/bind/named.conf 中 include 進來。
編輯 /etc/bind/named.conf.logging,加入下列:
logging { channel default_log { file "/var/log/named/dns-default.log" versions 10 size 1m; severity info; }; channel lamer_log { file "/var/log/named/dns-lamer.log" versions 3 size 1m; severity info; print-severity yes; print-time yes; print-category yes; }; channel query_log { file "/var/log/named/dns-query.log" versions 10 size 200m; print-time yes; severity info; }; channel security_log { file "/var/log/named/dns-security.log" versions 3 size 1m; severity info; print-severity yes; print-time yes; print-category yes; }; category lame-servers { lamer_log; }; category security { security_log; }; category queries { query_log; }; category default { default_log; }; }; |
在做記錄檔分類這件事,可花了我好大的工夫去查問題,因為我預設放記錄檔的位置是在 /var/log 底下,但一啟動服務,記錄檔便會出現錯誤訊息,而記錄還是寫在 /var/log/syslog 中。
logging channel 'default_log' file '/var/log/dns-default.log': permission denied |
想說檔案都已經給所有人有寫的權限了,怎麼還是會發生這個問題呢?後來上網找了之後,才知道 apparmor 就是有啟動 SELinux 啦!是 Linux Kernel 2.6.36 有加入 AppArmor Security 這個這個新功能啦!
按照文章去檢視 /etc/apparmor.d/usr.sbin.named 這個檔案內容,才知道預設 /var/log/named 才有讀寫的權限。不改設定的話,就將記錄檔改放在 /var/log/named 底下囉!
# some people like to put logs in /var/log/named/ instead of having # syslog do the heavy lifting. /var/log/named/** rw, /var/log/named/ rw, |
所以,要建立 /var/log/named 目錄及給予相關的權限:
$ sudo mkdir /var/log/named $ sudo chown bind /var/log/named |
重新啟動 BIND,果然一試就成功啦!
20110321