SlideShare a Scribd company logo
1 of 24
Download to read offline
Linux Server Admin



 BIND9 (DNS Server)

     Chatchai J
     2012-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

        include "/etc/bind/named.conf.options";
        include "/etc/bind/named.conf.local";
        include "/etc/bind/named.conf.default­zones";
    –   options – สำาหรับควบคุม named server

    –   local – สำาหรับ zone file ของเรา

    –   defaults-zones สำาหรับ predefined zone และ root
        ●   ไม่จำาเป็ นจะต้องไปแก้ไข
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
            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
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

            zone "cheshirecat2012.net" {
                    type master;
                    file "master/cheshirecat2012.net";
            };

        type → master/slave/hints/forward
        file → path relative กับ “directory” ใน options

               (default คือ /var/cache/bind)
Zone file
●   ต.ย. zone สำาหรับ cheshirecat2012.net

$ORIGIN .
$TTL 14400      ; 4 hours
cheshirecat2012.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.175
mx                      A       192.100.77.175




    อยู่ใน /var/cache/bind/master/cheshirecat2012.net
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 – root@cheshirecat2012.net (เปลี่ยน @ เป็ น .)
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.175
    mx                      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.in­addr.arpa
        5.0    IN PTR fivedots.coe.psu.ac.th.
        9.0    IN PTR ninedots.coe.psu.ac.th.
        ; for zone 0.30.172.in­addr.arpa
        5            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 วันพุธ

More Related Content

What's hot (16)

Ch08 mail-systems
Ch08 mail-systemsCh08 mail-systems
Ch08 mail-systems
 
Bug#691613: apt: [intl:th] update thai program translation
Bug#691613: apt: [intl:th] update thai program translationBug#691613: apt: [intl:th] update thai program translation
Bug#691613: apt: [intl:th] update thai program translation
 
Cent os
Cent osCent os
Cent os
 
Database Tuning for e-Learning
Database Tuning for e-LearningDatabase Tuning for e-Learning
Database Tuning for e-Learning
 
คำสั่ง ลินุกซ์ (Linux)
คำสั่ง ลินุกซ์ (Linux)คำสั่ง ลินุกซ์ (Linux)
คำสั่ง ลินุกซ์ (Linux)
 
Tiptlog 2
Tiptlog 2Tiptlog 2
Tiptlog 2
 
การตรวจเช็คฐานข้อมูล Oracle v1 draft
การตรวจเช็คฐานข้อมูล Oracle v1 draftการตรวจเช็คฐานข้อมูล Oracle v1 draft
การตรวจเช็คฐานข้อมูล Oracle v1 draft
 
Ch09 mail-systems-part2
Ch09 mail-systems-part2Ch09 mail-systems-part2
Ch09 mail-systems-part2
 
Set up rubytech fgs 2924 r กับ tacacs
Set up rubytech fgs 2924 r กับ tacacsSet up rubytech fgs 2924 r กับ tacacs
Set up rubytech fgs 2924 r กับ tacacs
 
Unix
UnixUnix
Unix
 
Hotspotubuntu8
Hotspotubuntu8Hotspotubuntu8
Hotspotubuntu8
 
Coovaubuntu904
Coovaubuntu904Coovaubuntu904
Coovaubuntu904
 
Server2Go เว็บพกพาตัวจริง
Server2Go เว็บพกพาตัวจริงServer2Go เว็บพกพาตัวจริง
Server2Go เว็บพกพาตัวจริง
 
Cent OS-book
Cent OS-bookCent OS-book
Cent OS-book
 
Virtualbox networking
Virtualbox networkingVirtualbox networking
Virtualbox networking
 
NETWORK SERVICEOPENSSH + NTP + SQUID
NETWORK SERVICEOPENSSH + NTP + SQUIDNETWORK SERVICEOPENSSH + NTP + SQUID
NETWORK SERVICEOPENSSH + NTP + SQUID
 

Viewers also liked

Viewers also liked (13)

Ch02 administrators-tasks
Ch02 administrators-tasksCh02 administrators-tasks
Ch02 administrators-tasks
 
Ch10 web servers
Ch10 web serversCh10 web servers
Ch10 web servers
 
Ch15 elastic hosts-svradmin
Ch15 elastic hosts-svradminCh15 elastic hosts-svradmin
Ch15 elastic hosts-svradmin
 
Ch11 web-app
Ch11 web-appCh11 web-app
Ch11 web-app
 
Ch03 domain-registration
Ch03 domain-registrationCh03 domain-registration
Ch03 domain-registration
 
Ch01 administrators-tasks
Ch01 administrators-tasksCh01 administrators-tasks
Ch01 administrators-tasks
 
Ch04 linux-hosting-vps
Ch04 linux-hosting-vpsCh04 linux-hosting-vps
Ch04 linux-hosting-vps
 
In perfect harmony_ e-mail works in-sync with other channels - Print Article ...
In perfect harmony_ e-mail works in-sync with other channels - Print Article ...In perfect harmony_ e-mail works in-sync with other channels - Print Article ...
In perfect harmony_ e-mail works in-sync with other channels - Print Article ...
 
Ch12 web-app-part2
Ch12 web-app-part2Ch12 web-app-part2
Ch12 web-app-part2
 
How Email Works
How Email WorksHow Email Works
How Email Works
 
Important tips on Router and SMTP mail routing
Important tips on Router and SMTP mail routingImportant tips on Router and SMTP mail routing
Important tips on Router and SMTP mail routing
 
linux device driver
linux device driverlinux device driver
linux device driver
 
Deep C
Deep CDeep C
Deep C
 

Similar to Ch06 bind9 (7)

Linux diskless
Linux disklessLinux diskless
Linux diskless
 
คู่มือการติดตั้ง Cent os
คู่มือการติดตั้ง  Cent osคู่มือการติดตั้ง  Cent os
คู่มือการติดตั้ง Cent os
 
VBoxManage tutorial
VBoxManage tutorialVBoxManage tutorial
VBoxManage tutorial
 
DNS
DNSDNS
DNS
 
Docker 1st time
Docker 1st timeDocker 1st time
Docker 1st time
 
ข้อมูลเกี่ยวกับ DHCP Server.pdf
ข้อมูลเกี่ยวกับ DHCP Server.pdfข้อมูลเกี่ยวกับ DHCP Server.pdf
ข้อมูลเกี่ยวกับ DHCP Server.pdf
 
Docker 101 for developer
Docker 101 for developerDocker 101 for developer
Docker 101 for developer
 

Ch06 bind9

  • 1. Linux Server Admin BIND9 (DNS Server) Chatchai J 2012-11-26
  • 2. DNS Server ● DNS Server บน Debian มีหลายตัว – DNSmasq สำาหรับ quick deployment ● ใช้งาย, สะดวก, เร็ว ่ – powerDNS ● เป็ นที่นิยม … แต่ผมยังไม่เคยใช้ … ขอไม่พูดถึง – bind9 ของ ISC ● เป็ นหนึ่งใน “เสาหลัก” ของ internet ● ใช้งานมานานมาก และ site ส่วนใหญ่จะใช้ bind สำาหรับให้บริการ name service
  • 3. BIND9 ● Bind – version 9 ● Configuration ค่อนข้างซับซ้อน ● มีหลายองค์ประกอบ ● มีหนังสือหลายเล่ม ทีเขียนเกี่ยวกับ การใช้งาน BIND ่ สำาหรับ DNS โดยเฉพาะ ● ในทีนี้จะพูดเฉพาะ เท่าที่จำาเป็ น ่
  • 4. ติดตั้ง ● Install package $ sudo apt-get install bind9 bind9utils bind9-host ● configuration – config files /etc/bind – zone files /var/cache/bind ● ทดสอบ $ sudo rndc status
  • 5. 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)
  • 6. config file หลัก (debian) ● /etc/bind/named.conf include "/etc/bind/named.conf.options"; include "/etc/bind/named.conf.local"; include "/etc/bind/named.conf.default­zones"; – options – สำาหรับควบคุม named server – local – สำาหรับ zone file ของเรา – defaults-zones สำาหรับ predefined zone และ root ● ไม่จำาเป็ นจะต้องไปแก้ไข
  • 7. Two Roles of Name Server ● Cache Server – ไม่มีขอมูล zone ของตัวเอง ้ – ทำาหน้าที่ resolve address ให้กับ client ● Authoriative Server – Primary & Secondary DNS ● เป็ น เจ้าของ ของข้อมูลนั้น
  • 8. DNS Cache Server ● บรรทัด nameserver ใน /etc/resolv.conf – ตอบคำาถามแก่ client ว่า name หรือ address นั้นมี ip address หรือ ชื่อ hostname เป็ นอะไร – โดยทั่วไป จะ recursive lookup จนกระทั่งได้คำา ตอบ แล้วส่งกลับให้ client
  • 9. Primary/Secondary DNS ● เจ้าของข้อมูล – มี zone files ของตัวเอง – ใช้ข้อมูลใน zone file สำาหรับตอบ query ที่รับมา – โดยทั่วไปจะรับ query request จาก DNS Cache Server อีกทีนึง ● Primary Server – Authorized zone files ● Secondary Server – เอาข้อมูล zone มาจาก primary อีกที – เป็ น backup server
  • 10. 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/
  • 11. 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
  • 12. 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 { … };
  • 13. Primary DNS Config ● เพิ่ม zone config ใน /etc/bind/named.conf.local – เช่น สำาหรับ domain cheshirecat2012.net zone "cheshirecat2012.net" {         type master;         file "master/cheshirecat2012.net"; }; type → master/slave/hints/forward file → path relative กับ “directory” ใน options (default คือ /var/cache/bind)
  • 14. Zone file ● ต.ย. zone สำาหรับ cheshirecat2012.net $ORIGIN . $TTL 14400      ; 4 hours cheshirecat2012.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.175 mx                      A       192.100.77.175 อยู่ใน /var/cache/bind/master/cheshirecat2012.net
  • 15. 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 – root@cheshirecat2012.net (เปลี่ยน @ เป็ น .)
  • 16. 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) )
  • 17. 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.175 mx                      A       192.100.77.175
  • 18. ทดสอบ $ sudo service named restart $ grep named /var/log/syslog ● ถ้าไม่มี error ก็ทดสอบ query ได้ $ host ns.cheshirecat2012.net localhost
  • 19. เพิ่ม 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
  • 20. Reverse Map Address ● ภาพจาก http://www.zytrax.com/books/dns/ch3/
  • 21. 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” ●
  • 22. Reverse Zone File ● ข้อมูลใน Zone File – SOA เหมือนเดิม – ใช้ PTR Record สำาหรับระบุ address ; for zone 30.172.in­addr.arpa 5.0 IN PTR fivedots.coe.psu.ac.th. 9.0 IN PTR ninedots.coe.psu.ac.th. ; for zone 0.30.172.in­addr.arpa 5            IN PTR  fivedots.coe.psu.ac.th. 9            IN PTR  ninedots.coe.psu.ac.th.
  • 23. Reverse query $ host fivedots.coe.psu.ac.th $ host 172.30.0.5
  • 24. ยังไม่จบ ● ต่อ #2 วันพุธ