Tommy 碎碎念

Tommy Wu's blog

« 上一篇 | 下一篇 »

BIND master/slave DNS 與 view 的搭配
post by tommy @ 03 十一月, 2006 11:05
由於 BIND 提供了一個方便的 view 功能, 可以讓我們在同一台機器上頭, 依據來查詢的 ip 的不同, 而回應不同的結果. 所以, 我們可以方便的把對內的 DNS 與對外的 DNS 都整合到同一台機器上頭處理. 如果是內部網路的機器來查詢時, 就回覆內部的 IP, 如果是外部的網路來查詢時, 就回覆外部的 IP. 管理員可以將內部與外部的 DNS, 整合到同一台機器管理 (當然, 還是要管理內部與外部不同的設定檔). 這在只有一個 DNS 主機時, 問題並不大, 但是, 如果我們有多台 DNS 主機時, 如何同步這些主機的設定, 就需要有一些技巧了.

以我家這個小網域為例子來看, 在只有一台 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 設定了.

Del.icio.us Furl HEMiDEMi Technorati MyShare
迴響
暱稱:
標題:
個人網頁:
電子郵件:
authimage

迴響

  

Bad Behavior 已經阻擋了 96 個過去 7 天試圖闖關的垃圾迴響與引用。
Power by LifeType. Template design by JamesHuang. Valid XHTML and CSS