This is G o o g l e's cache of http://www.debianclub.com/node/45 as retrieved on 15 Feb 2007 19:32:16 GMT.
G o o g l e's cache is the snapshot that we took of the page as we crawled the web.
The page may have changed since that time. Click here for the current page without highlighting.
This cached page may reference images which are no longer available. Click here for the cached text only.
To link to or bookmark this page, use the following url: http://www.google.com/search?hl=en&q=cache%3Ahttp%3A%2F%2Fwww.debianclub.com%2Fnode%2F45&btnG=Search


Google is neither affiliated with the authors of this page nor responsible for its content.

User login

Links

debianclub.com
debian.org
ubuntuclub.com
blognone.com

Syndicate

Syndicate content

ติดตั้ง DNS แบบง่าย

เอามาจาก
ThaiLinuxCafe - debian : ติดตั้ง dns อย่างง่าย

เรื่องของ DNS (Domain Name Server) เป็นเรื่องหลักของการใช้งานอินเทอร์เน็ต เนื้อหาซับซ้อนและทำความเข้าใจยาก สำหรับในที่นี้ เราเอาแค่ติดตั้งพอใช้งานได้ โดยเราจะติดตั้งเครื่องเซิร์ฟเวอร์เพื่อทำหน้าที่เป็น DNS สำหรับใช้งานเครือข่ายภายใน

โครงร่างคือ

  • เน็ตเวิร์กเราเป็น 192.168.1.0/24 มีโดเมนเป็น example.com
  • เครื่องที่ทำหน้าที่ name server มีชื่อว่า server1.example.com ไอพีเป็น 192.168.1.1 โดยมีชื่อเสมือนคือ ns1.example.com
  • มีเครื่องในวงเครื่องอื่น ๆ ดังนี้
    • ns2 = 192.168.1.2
    • client1 = 192.168.1.101
    • client2 = 192.168.1.102
    • client3 = 192.168.1.103

แพกเกจที่ทำหน้าที่ DNS ในเดเบียนชื่อ bind9 และแพกเกจที่เป็นโปรแกรมช่วยชื่อ dnsutils

งานปรับตั้งคือการสร้างไฟล์สำหรับให้ bind9 เรียกใช้ ดังนี้

  • โซนไฟล์ ไว้สำหรับค้นข้อมูลจากชื่อเป็นไอพี
  • รีเวิร์สไฟล์ ไว้สำหรับค้นข้อมูลย้อนกลับ คือจากไอพีเป็นชื่อ
  • คอนฟิกไฟล์ สำหรับบอก bind9 ว่าเราจะติดตั้ง DNS ในแบบไหน และประกอบด้วยไฟล์ข้อมูลอะไรบ้าง

เริ่มด้วย

ติดตั้ง DNS และโปรแกรมช่วย

# aptitude install bind9 dnsutils

ไปที่ไดเรกทอรีของการปรับตั้ง

# cd /etc/bind

เริ่มสร้างโซนไฟล์ ให้ชื่อว่า example.com.zone มีเนื้อไฟล์ดังนี้

# vi example.com.zone

$TTL    86400
@          IN      SOA    server1.example.com.    root.server1.example.com. (
                          51              ; serial (d. adams)
                          3H              ; refresh after 3 hours
                          15M             ; retry after 15 minutes
                          1W              ; expire after 7 days
                          1D )            ; minimum TTL (Time To Live) of 1 days
@          IN      NS      ns1.example.com.    ; primary NS
@          IN      NS      ns2.example.com.    ; secondary NS

ns1        IN      CNAME  server1

; append or edit host ip here
server1  IN      A      192.168.1.1
ns2      IN      A      192.168.1.2
client1  IN      A      192.168.1.101
client2  IN      A      192.168.1.102
client3  IN      A      192.168.1.103

สร้างรีเวิร์สไฟล์ ให้ชื่อว่า example.com.reverse มีเนื้อไฟล์ดังนี้

# vi example.com.reverse

$TTL    86400
@          IN      SOA    server1.example.com.    root.server1.example.com. (
                          51              ; serial (d. adams)
                          3H              ; refresh after 3 hours
                          15M             ; retry after 15 minutes
                          1W              ; expire after 7 days
                          1D )            ; minimum TTL (Time To Live) of 1 days
@          IN      NS      ns1.example.com.    ; primary NS
@          IN      NS      ns2.example.com.    ; secondary NS

; append or edit host name here
1        IN      PTR    server1.example.com.
2        IN      PTR    ns2.example.com.
101      IN      PTR    client1.example.com.
102      IN      PTR    client2.example.com.
103      IN      PTR    client3.example.com.

สร้างคอนฟิกไฟล์สำหรับโซน example.com ให้ชื่อว่า example.com.conf มีเนื้อไฟล์ดังนี้

# vi example.com.conf

zone "example.com" IN {
        type master;
        file "/etc/bind/example.com.zone";
        allow-update { none; };
};
zone "1.168.192.in-addr.arpa" IN {
        type master;
        file "/etc/bind/example.com.reverse";
        allow-update { none; };
};

เปลี่ยนสิทธิ์ให้ bind เป็นเจ้าของไฟล์

# chown bind:bind example.com.*

บอกให้ bind9 เอาไฟล์ของเราไปใช้งาน โดยการเพิ่มลงในไฟล์ named.conf.local ดังนี้

# vi named.conf.local

...
include "/etc/bind/example.com.conf";

เสร็จแล้วก็สั่งเริ่ม bind9 ใหม่

# /etc/init.d/bind9 restart

ถ้ามีข้อผิดพลาด ให้ดูที่ /etc/log/syslog

ทดสอบโดย

# nslookup server1.example.com

จะแสดงผลเป็น 192.168.1.1

Server: 192.168.1.1
Address: 192.168.1.1#53

Name: server1.example.com
Address: 192.168.1.1

ทดสอบย้อนกลับ

# nslookup 192.168.1.1

จะแสดงผลเป็น server1.example.com

Server: 192.168.1.1
Address: 192.168.1.1#53

1.1.168.192.in-addr.arpa name = server1.example.com.

หมายเหตุ

  • เลขซีเรียลตามตัวอย่างเป็น 51 แต่ส่วนใหญ่นิยมใช้วันที่ เช่น 2006030401 เป็นต้น
  • ในเนื้อไฟล์ของโซนไฟล์และริเวิร์สไฟล์ เวลาพิมพ์ระวังอยาลืมเครื่องหมายจุด ท้ายชื่อโฮสต์
  • สำหรับเครื่อง DNS ที่ทำหน้าที่เกตเวย์ออกอินเทอร์เน็ต พบว่าเมื่อแก้ไขไฟล์ /etc/resolv.conf ให้ชี้ไปที่ DNS ของไอเอสพี เครื่องเราจะทำหน้าที่เป็น slave โดยอัตโนมัติ
  • ถ้าจะเพิ่มโดเมน และเป็นเน็ตเวิร์กคนละวง ก็ใช้วิธีเดียวกันได้ โดยสร้างโซนไฟล์ รีเวิร์สไฟล์ และคอนฟิกไฟล์สำหรับโดเมนที่เพิ่ม
  • ถ้าเพิ่มโดเมน และเป็นเน็ตเวิร์กวงเดียวกัน เช่น หนึ่งไอพี มีหลายโดเมน ให้สร้างเฉพาะโซนไฟล์ ไม่ต้องสร้างรีเวิร์สไฟล์ ซึ่งก็จะทำให้เรียกดูชื่อย้อนจากไอพีไม่ได้
  • ถ้าจะเพิ่มเน็ตเวิร์กเป็นสองวง โดยเป็นโดเมนเดียวกัน ให้ดูตัวอย่างที่ Debian Administration: Two-in-one DNS server with BIND9

เนื้อหาไม่ค่อยถูกตามหลักการนะครับ เพราะมันยาก ถ้าจะให้รู้เรื่องจริง ๆ ต้องเข้าใจระบบอินเทอร์เน็ตพอสมควร ในที่นี้เอาแค่พอใช้งานได้ครับ

อ้างอิงเพิ่มเติม


จากตัวอย่

จากตัวอย่างข้างบน
ตัว
ns1.example.com. ; primary NS
ns2.example.com. ; secondary NS

ต้องเซ็ตให้เหมือนกันใช่ปล่าวครับ

NS ตามความเป็นจริง

ต้องเซ็ตตามความเป็นจริงครับ
ในที่นี้จะเห็นว่า
ns1.example.com เป็น CNAME (ชื่อเล่น...ผมเรียกเอง) ของ server1.example.com
ส่วน ns2.example.com ชี้ไปที่ 192.168.1.2

ซึ่งจะเห็นได้ว่า จริง ๆ แล้ว
ns1.example.com : 192.168.1.1
ns2.example.com : 192.168.1.2

ถ้าในระบบเราไม่มี ns2 คือเรามี DNS Server เฉพาะเครื่องที่กำลังเซ็ตอยู่คือ server1
ก็ไม่ต้องเพิ่ม ns2 เข้าไปในรายการ Record ครับ


**********************
Key ID: D4CEFD37
Fingerprint: 1ED3 27F6 48C8 5C9D 4285 F24D D64E C0AF D4CE FD37
**********************