以我家這個小網域為例子來看, 在只有一台 DNS 主機 (192.168.0.1) 時, 使用 view 的功能, 分別對內部的 ip 提供內部的 DNS, 而對外部的 ip 提供外部的 DNS. 在 bind 上頭的設定是:
// master dns
view "internal" {
// This should match our internal networks.
match-clients {
127.0.0.1/24;
192.168.0.0/24;
};
// Provide recursive service to internal clients only.
recursion yes;
zone "teatime.com.tw" {
type master;
file "/etc/bind/db.teatime.com.tw-int";
};
};
view "external" {
// Match ant client
match-clients {
any;
};
// Refuse recursive service to external clients.
recursion no;
zone "teatime.com.tw" {
type master;
file "/etc/bind/db.teatime.com.tw";
};
};
這個設定檔, 會依據來源的 IP 來決定使用那個設定檔回應. 且對外可以關閉 recursion 查詢, 只開放內部的 IP 使用 recursion 的功能.
如果這時, 我們要新增另一台 slave DNS (192.168.0.12) 時, 依照沒有 view 時的想法, 然後套上 view 之後, 應該很簡單的用下頭的設定檔來處理:
// slave
view "internal" {
// This should match our internal networks.
match-clients {
127.0.0.1/24;
192.168.0.0/24;
};
// Provide recursive service to internal clients only.
recursion yes;
// add entries for other zones below here
zone "teatime.com.tw" {
type slave;
masters { 192.168.0.1; };
file "/etc/bind/db.teatime.com.tw-int";
};
};
view "external" {
// Match ant client
match-clients {
any;
};
// Refuse recursive service to external clients.
recursion no;
// add entries for other zones below here
zone "teatime.com.tw" {
type slave;
masters { 192.168.0.1; };
file "/etc/bind/db.teatime.com.tw";
};
};
這時, 問題就出現了. 當這台 slave DNS, 往 master DNS 查詢資料時, 由於這台機器的 IP 是 192.168.0.12, 屬於內部的 192.168.0.0/24 裡頭, 所以... 內部的 DNS 資料並不會有問題, 可以得到正確的內部資料, 可是... 對於外部的 slave DNS 來說, 去 master DNS 查詢時, 也被視為內部的 IP, 當然也只得到內部的 DNS 資料. 並不會得到外部的 DNS 資料.
所以, 為了避免這個問題, 我們可以讓 master DNS 與 slave DNS 都各新增一個 IP, 然後利用這個 IP 來避免取得內部的 DNS 資料, 真正能取得外部的 DNS 資料.
我們可以新增 192.168.100.1 給 master DNS, 然後新增 192.168.100.12 給 slave DNS, 然後把 master DNS 的設定改成:
view "internal" {
// This should match our internal networks.
match-clients {
!192.168.100.0/24;
127.0.0.1/24;
192.168.0.0/24;
};
// Provide recursive service to internal clients only.
recursion yes;
zone "teatime.com.tw" {
type master;
file "/etc/bind/db.teatime.com.tw-int";
};
};
view "external" {
// Match ant client
match-clients {
any;
};
// Refuse recursive service to external clients.
recursion no;
zone "teatime.com.tw" {
type master;
file "/etc/bind/db.teatime.com.tw";
};
};
把 192.168.100.0/24 排除在 internal 的 view 範圍內 (好像沒必要, 因為本來就不在那個 internal 的範圍內).
然後把 slave DNS 的設定改成:
// slave
view "internal" {
// This should match our internal networks.
match-clients {
127.0.0.1/24;
192.168.0.0/24;
};
// Provide recursive service to internal clients only.
recursion yes;
// add entries for other zones below here
zone "teatime.com.tw" {
type slave;
masters { 192.168.0.1; };
transfer-source 192.168.0.12;
file "/etc/bind/db.teatime.com.tw-int";
};
};
view "external" {
// Match ant client
match-clients {
any;
};
// Refuse recursive service to external clients.
recursion no;
// add entries for other zones below here
zone "teatime.com.tw" {
type slave;
masters { 192.168.100.1; };
transfer-source 192.168.100.12;
file "/etc/bind/db.teatime.com.tw";
};
};
在 internal 的設定上頭, 利用 transfer-source 指定使用 192.168.0.12 的 ip 去查詢 192.168.0.1 的 DNS, 以便於得到內部的 DNS 資料. 而在 external 的設定中, 利用 transfer-source 指定使用 192.168.100.12 的 ip, 去查詢 192.168.100.1 的 DNS, 以便於取得外部的 DNS 資料.
如此設定後, 就可以讓這兩台主機, 能夠同時同步內部與外部的 DNS 設定了.
转载自:Tommy 碎碎念 原文链接:http://blog.teatime.com.tw/1/post/147