การตั้งให้ name server ให้บริการเครือข่ายภายในและภายนอก โดยใช้โดเมนเดียวกัน มีข้อดีตรงที่เราไม่จำเป็นต้องแยกโดเมนให้จำยาก และเมื่อเวลาลูกข่ายภายในสั่งค้น การค้นก็ไม่ต้องเปลืองแพ็กเก็ตออกสู่ภายนอก เพียงแต่การปรับตั้งยุ่งนิดนึง
# aptitude install bind9
สมมุติว่า
จะต้องมีไฟล์คอนฟิกคือ example.com.conf และ example.org.conf
มีโซนไฟล์คือ internal/example.com.zone กับ internal/example.org.zone และ external/example.com.zone กับ external/example.org.zone
ตามด้วยรีเวิร์สไฟล์คือ internal/example.com.reverse กับ internal/example.org.reverse และ external/example.com.reverse กับ external/example.org.reverse
เริ่มด้วย
# cd /etc/bind
เพิ่มกฎแยก internal และ external และให้อ่านไฟล์คอนฟิกของแต่ละโดเมนเข้ามาในระบบด้วย ผ่านไฟล์ named.conf.local
# vi named.conf.local
...
acl internals {
127.0.0.0/8;
10.0.0.0/24;
192.168.1.0/24;
};
include "/etc/bind/example.com.conf";
include "/etc/bind/example.org.conf";
สร้างไฟล์คอนฟิกของ example.com
# vi example.com.conf
view "internal" {
match-clients { internals; };
zone "example.com" IN {
type master;
file "/etc/bind/internal/example.com.zone";
allow-update { none; };
};
zone "1.168.192.in-addr.arpa" IN {
type master;
file "/etc/bind/internal/example.com.reverse";
allow-update { none; };
};
};
view "external" {
match-clients { any; };
zone "example.com" IN
type master;
file "/etc/bind/external/example.com.zone";
allow-update { none; };
};
zone "113.112.111.in-addr.arpa" IN {
type master;
file "/etc/bind/external/example.com.reverse";
allow-update { none; };
};
};
สร้างไฟล์คอนฟิกของ example.org
# vi example.org.conf
view "internal" {
match-clients { internals; };
zone "example.org" IN {
type master;
file "/etc/bind/internal/example.org.zone";
allow-update { none; };
};
zone "0.0.10.in-addr.arpa" IN {
type master;
file "/etc/bind/internal/example.org.reverse";
allow-update { none; };
};
};
view "external" {
match-clients { any; };
zone "example.org" IN
type master;
file "/etc/bind/external/example.org.zone";
allow-update { none; };
};
zone "213.212.211.in-addr.arpa" IN {
type master;
file "/etc/bind/external/example.org.reverse";
allow-update { none; };
};
};
อย่าลืมสร้างไดเรกทอรี่ก่อน
# mkdir internal external
ตัวอย่างสร้างโซนไฟล์ของ internal/example.com
# vi internal/example.com.zone
$TTL 86400
@ IN SOA ns1.example.com. root.ns1.example.com. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
@ IN NS ns1.example.com. ; primary NS
@ IN NS ns2.example.com. ; secondary NS
www IN CNAME ns1
ftp IN CNAME ns1
mail IN CNAME ns1
; append or edit host file here
ns1 IN A 192.168.1.1
ns2 IN A 192.168.1.2
work1 IN A 192.168.1.11
work2 IN A 192.168.1.12
...
ตัวอย่างสร้างโซนไฟล์ของ external/example.com
# vi external/example.com.zone
$TTL 86400
@ IN SOA ns1.example.com. root.ns1.example.com. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
@ IN NS ns1.example.com. ; primary NS
@ IN NS ns2.example.com. ; secondary NS
www IN CNAME ns1
ftp IN CNAME ns1
mail IN CNAME ns1
; append or edit host file here
ns1 IN A 111.112.113.114
ตัวอย่างสร้างโซนไฟล์ของ internal/example.org
# vi internal/example.org.zone
$TTL 86400
@ IN SOA ns1.example.org. root.ns1.example.org. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
@ IN NS ns1.example.org. ; primary NS
@ IN NS ns2.example.org. ; secondary NS
www IN CNAME ns1
ftp IN CNAME ns1
mail IN CNAME ns1
; append or edit host file here
ns1 IN A 10.0.0.1
ns2 IN A 10.0.0.2
shop1 IN A 10.0.0.11
shop2 IN A 10.0.0.12
...
ตัวอย่างสร้างโซนไฟล์ของ external/example.org
# vi external/example.org.zone
$TTL 86400
@ IN SOA ns1.example.org. root.ns1.example.org. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
@ IN NS ns1.example.org. ; primary NS
@ IN NS ns2.example.org. ; secondary NS
www IN CNAME ns1
ftp IN CNAME ns1
mail IN CNAME ns1
; append or edit host file here
ns1 IN A 211.212.213.214
...
ตัวอย่างสร้างรีเวิร์สไฟล์ของ internal/example.com
# vi internal/example.com.reverse
$TTL 86400
@ IN SOA ns1.example.com. root.ns1.example.com. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
@ IN NS ns1.example.com. ; primary NS
@ IN NS ns2.example.com. ; secondary NS
;
; host in network 192.168.1.0
; append or edit host file here
1 IN PTR ns1.example.com.
2 IN PTR ns2.example.com.
11 IN PTR work1.example.com.
12 IN PTR work2.example.com.
...
ตัวอย่างสร้างรีเวิร์สไฟล์ของ external/example.com
# vi external/example.com.reverse
$TTL 86400
@ IN SOA ns1.example.com. root.ns1.example.com. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
@ IN NS ns1.example.com. ; primary NS
@ IN NS ns2.example.com. ; secondary NS
;
; host in network 111.112.113.0
; append or edit host file here
114 IN PTR ns1.example.com.
ตัวอย่างสร้างรีเวิร์สไฟล์ของ internal/example.org
# vi internal/example.org.reverse
$TTL 86400
@ IN SOA ns1.example.org. root.ns1.example.org. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
@ IN NS ns1.example.org. ; primary NS
@ IN NS ns2.example.org. ; secondary NS
;
; host in network 10.0.0.0
; append or edit host file here
1 IN PTR ns1.example.org.
2 IN PTR ns2.example.org.
11 IN PTR shop1.example.org.
12 IN PTR shop2.example.org.
...
ตัวอย่างสร้างรีเวิร์สไฟล์ของ external/example.org
# vi external/example.org.reverse
$TTL 86400
@ IN SOA ns1.example.org. root.ns1.example.org. (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
@ IN NS ns1.example.org. ; primary NS
@ IN NS ns2.example.org. ; secondary NS
;
; host in network 211.212.213.0
; append or edit host file here
214 IN PTR ns1.example.org.
เปลี่ยนสิทธิ์ทั้งหมด
# chown bind:bind * -R
เสร็จแล้ว
# /etc/init.d/bind9 restart
หมายเหตุ
ตัวเลข serial ไม่ค่อยจำเป็นเท่าไหร่ เป็นตัวเลขอะไรก็ได้ แต่ถ้าเราทำเป็น dynamic dns จะต้องเป็นตัวเลขที่เพิ่มค่าขึ้นไปเรื่อย ๆ ให้มากกว่าค่าเดิม ไม่งั้นเขาไม่ยอมอัปเดตค่าไอพีให้
อ้างอิง
Two-in-one DNS server with BIND9