ch06 bind9
TRANSCRIPT
Linux Server Admin
BIND9 (DNS Server)
Chatchai J2012-11-26
DNS Server
● DNS Server บน Debian มหลายตว– DNSmasq สำาหรบ quick deployment
● ใชงาย, สะดวก, เรว– powerDNS
● เปนทนยม … แตผมยงไมเคยใช … ขอไมพดถง– bind9 ของ ISC
● เปนหนงใน “เสาหลก” ของ internet
● ใชงานมานานมาก และ site สวนใหญจะใช bind สำาหรบใหบรการ name service
BIND9
● Bind – version 9
● Configuration คอนขางซบซอน● มหลายองคประกอบ● มหนงสอหลายเลม ทเขยนเกยวกบ การใชงาน BIND
สำาหรบ DNS โดยเฉพาะ● ในทนจะพดเฉพาะ เทาทจำาเปน
ตดตง● Install package
$ sudo apt-get install bind9 bind9utils bind9-host
● configuration– config files /etc/bind
– zone files /var/cache/bind
● ทดสอบ$ sudo rndc status
rndc
● “remote” name daemon control
$ sudo service bind9 restart$ sudo rndc reload
$ sudo rndc refresh
– แตควรใชงานบน localhost ของ DNS Server (การรบสง key จะไม encrypt? – ไมแนใจ)
– server คอตว named เองแต run ท port 953 (default)
config file หลก (debian)
● /etc/bind/named.conf
– options – สำาหรบควบคม named server
– local – สำาหรบ zone file ของเรา– defaults-zones สำาหรบ predefined zone และ root
● ไมจำาเปนจะตองไปแกไข
include "/etc/bind/named.conf.options";include "/etc/bind/named.conf.local";include "/etc/bind/named.conf.defaultzones";
Two Roles of Name Server
● Cache Server
– ไมมขอมล zone ของตวเอง– ทำาหนาท resolve address ใหกบ client
● Authoriative Server– Primary & Secondary DNS
● เปน เจาของ ของขอมลนน
DNS Cache Server
● บรรทด nameserver ใน /etc/resolv.conf
– ตอบคำาถามแก client วา name หรอ address นนม ip address หรอ ชอ hostname เปนอะไร
– โดยทวไป จะ recursive lookup จนกระทงไดคำาตอบ แลวสงกลบให client
Primary/Secondary DNS
● เจาของขอมล– ม zone files ของตวเอง– ใชขอมลใน zone file สำาหรบตอบ query ทรบมา– โดยทวไปจะรบ query request จาก DNS Cache Server อกทนง
● Primary Server– Authorized zone files
● Secondary Server
– เอาขอมล zone มาจาก primary อกท– เปน backup server
Dual Roles
● ใช DNS Server ทำาหนาททง Cache Server และ Authoriative
Server ไดใหม– CoE dept. ใชอย
● ninedots.coe.psu.ac.th (primary for coe.psu.ac.th)● fivedots.coe.psu.ac.th (secondary for coe.psu.ac.th)
● ทงสองตวเปน DNS Cache Server สำาหรบ 172.30.0.0/16, 172.31.0.0/16
● แตไมควรทำา● ดคำาแนะนำาจาก http://www.intodns.com/
DNS Cache Config
● ใชงานสำาหรบเปน Cache Server อยางเดยว– เพมใน /etc/bind/named.conf.options
allowquery { any; }; # default
● หรอallowquery { 172.30.0.0/16; }; # limit access to CoE dept.
– ใน options { … }; สำาหรบระบวา client ใดๆบางทสามารถ query ได– ดเรอง ACL ของ bind9 จาก http://www.zytrax.com/books/dns/ch7/acl.html
DNS Cache Config (ตอ)
● สำาหรบ DNS Server ภายใน PSU Network จะตองสง query ใหกบ {ns,ns2}.psu.ac.th
– firewall ของ PSU CC filter เอาไว (แกปญหา malware)
– จะตองเพมforward only;
forwaders { 192.100.77.2; 192.100.77.5; };
– ใน options { … };
Primary DNS Config
● เพม zone config ใน/etc/bind/named.conf.local
– เชน สำาหรบ domain cheshirecat2012.net
type → master/slave/hints/forward
file → path relative กบ “directory” ใน options
(default คอ /var/cache/bind)
zone "cheshirecat2012.net" { type master; file "master/cheshirecat2012.net";};
Zone file
● ต.ย. zone สำาหรบ cheshirecat2012.net
อยใน /var/cache/bind/master/cheshirecat2012.net
$ORIGIN .$TTL 14400 ; 4 hourscheshirecat2012.net IN SOA ns.cheshirecat2012.net. root.cheshirecat2012.net. ( 2012112601 ; serial 14400 ; refresh (4 hours) 3600 ; retry (1 hour) 2419200 ; expire (4 weeks) 14400 ; minimum (4 hours) ) NS ns1.cjv6.net. NS ns.cheshirecat2012.net. MX 10 mx.cheshirecat2012.net.$ORIGIN cheshirecat2012.net.ns A 192.100.77.175mx A 192.100.77.175
Zone file (cont)
● SOA RR (Resource Record)– name ttl class rr name-server email-addr (sn ref ret ex min)
cheshirecat2012.net IN SOA ns.cheshirecat2012.net. root.cheshirecat2012.net.
● name – cheshirecat2012.net ($ORIGIN .)
● ttl – ใช $TTL ทกำาหนดไว● class – IN (internet ไมตองเปลยน)
● rr – SOA ระบ type ของ record น● name-server – ns.cheshirecat2012.net
● email-addr – [email protected] (เปลยน @ เปน .)
Zone file (cont)
● (serial refresh retry expire minimum)( 2012112601 ; serial
14400 ; refresh (4 hours)
3600 ; retry (1 hour)
2419200 ; expire (4 weeks)
14400 ; minimum (4 hours)
)
Zone file (cont)
● Other resource records
NS ns1.cjv6.net. NS ns.cheshirecat2012.net. MX 10 mx.cheshirecat2012.net.$ORIGIN cheshirecat2012.net.ns A 192.100.77.175mx A 192.100.77.175
ทดสอบ$ sudo service named restart
$ grep named /var/log/syslog
● ถาไมม error กทดสอบ query ได$ host ns.cheshirecat2012.net localhost
เพม resource record ชนดอน● TXT – description● AAAA – IPv6 Address
$ORIGIN cheshirecat2012.net.
60 IN TXT “v=spf1 a a:smtp.cheshirecat2012.net ~all”
www 60 IN AAAA 2001:db8:9009::1
smtp 60 IN A 1.2.3.4
Reverse Map Address
● ภาพจาก http://www.zytrax.com/books/dns/ch3/
Reverse Map Address
● ใชแปลงจาก address เปน name
● domain ใช “in-addr.arpa”
● Reverse for 172.30.0.0/24● zone file name “0.30.172.in-addr.arpa”● Reverse for 172.30/16● Zone file name “30.172.in-addr.arpa”●
Reverse Zone File
● ขอมลใน Zone File
– SOA เหมอนเดม– ใช PTR Record สำาหรบระบ address
; for zone 30.172.inaddr.arpa5.0 IN PTR fivedots.coe.psu.ac.th.
9.0 IN PTR ninedots.coe.psu.ac.th.; for zone 0.30.172.inaddr.arpa5 IN PTR fivedots.coe.psu.ac.th.9 IN PTR ninedots.coe.psu.ac.th.
Reverse query
$ host fivedots.coe.psu.ac.th$ host 172.30.0.5
ยงไมจบ● ตอ #2 วนพธ