24
Linux Server Admin BIND9 (DNS Server) Chatchai J 2012-11-26

Ch06 bind9

Embed Size (px)

Citation preview

Page 1: Ch06 bind9

Linux Server Admin

BIND9 (DNS Server)

Chatchai J2012-11-26

Page 2: Ch06 bind9

DNS Server

● DNS Server บน Debian มหลายตว– DNSmasq สำาหรบ quick deployment

● ใชงาย, สะดวก, เรว– powerDNS

● เปนทนยม … แตผมยงไมเคยใช … ขอไมพดถง– bind9 ของ ISC

● เปนหนงใน “เสาหลก” ของ internet

● ใชงานมานานมาก และ site สวนใหญจะใช bind สำาหรบใหบรการ name service

Page 3: Ch06 bind9

BIND9

● Bind – version 9

● Configuration คอนขางซบซอน● มหลายองคประกอบ● มหนงสอหลายเลม ทเขยนเกยวกบ การใชงาน BIND

สำาหรบ DNS โดยเฉพาะ● ในทนจะพดเฉพาะ เทาทจำาเปน

Page 4: Ch06 bind9

ตดตง● Install package

$ sudo apt-get install bind9 bind9utils bind9-host

● configuration– config files /etc/bind

– zone files /var/cache/bind

● ทดสอบ$ sudo rndc status

Page 5: Ch06 bind9

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)

Page 6: Ch06 bind9

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.default­zones";

Page 7: Ch06 bind9

Two Roles of Name Server

● Cache Server

– ไมมขอมล zone ของตวเอง– ทำาหนาท resolve address ใหกบ client

● Authoriative Server– Primary & Secondary DNS

● เปน เจาของ ของขอมลนน

Page 8: Ch06 bind9

DNS Cache Server

● บรรทด nameserver ใน /etc/resolv.conf

– ตอบคำาถามแก client วา name หรอ address นนม ip address หรอ ชอ hostname เปนอะไร

– โดยทวไป จะ recursive lookup จนกระทงไดคำาตอบ แลวสงกลบให client

Page 9: Ch06 bind9

Primary/Secondary DNS

● เจาของขอมล– ม zone files ของตวเอง– ใชขอมลใน zone file สำาหรบตอบ query ทรบมา– โดยทวไปจะรบ query request จาก DNS Cache Server อกทนง

● Primary Server– Authorized zone files

● Secondary Server

– เอาขอมล zone มาจาก primary อกท– เปน backup server

Page 10: Ch06 bind9

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/

Page 11: Ch06 bind9

DNS Cache Config

● ใชงานสำาหรบเปน Cache Server อยางเดยว– เพมใน /etc/bind/named.conf.options

allow­query { any; }; # default

● หรอallow­query { 172.30.0.0/16; }; # limit access to CoE dept.

– ใน options { … }; สำาหรบระบวา client ใดๆบางทสามารถ query ได– ดเรอง ACL ของ bind9 จาก http://www.zytrax.com/books/dns/ch7/acl.html

Page 12: Ch06 bind9

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 { … };

Page 13: Ch06 bind9

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";};

Page 14: Ch06 bind9

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

Page 15: Ch06 bind9

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] (เปลยน @ เปน .)

Page 16: Ch06 bind9

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)

)

Page 17: Ch06 bind9

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

Page 18: Ch06 bind9

ทดสอบ$ sudo service named restart

$ grep named /var/log/syslog

● ถาไมม error กทดสอบ query ได$ host ns.cheshirecat2012.net localhost

Page 19: Ch06 bind9

เพม 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

Page 20: Ch06 bind9

Reverse Map Address

● ภาพจาก http://www.zytrax.com/books/dns/ch3/

Page 21: Ch06 bind9

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”●

Page 22: Ch06 bind9

Reverse Zone File

● ขอมลใน Zone File

– SOA เหมอนเดม– ใช PTR Record สำาหรบระบ address

; for zone 30.172.in­addr.arpa5.0 IN PTR fivedots.coe.psu.ac.th.

9.0 IN PTR ninedots.coe.psu.ac.th.; for zone 0.30.172.in­addr.arpa5            IN PTR  fivedots.coe.psu.ac.th.9            IN PTR  ninedots.coe.psu.ac.th.

Page 23: Ch06 bind9

Reverse query

$ host fivedots.coe.psu.ac.th$ host 172.30.0.5

Page 24: Ch06 bind9

ยงไมจบ● ตอ #2 วนพธ