Introduction to DNS

From CMU ITSC Network
Revision as of 15:37, 4 December 2018 by Supawit (talk | contribs)

DNS : Domain Name System เป็นระบบแปลง IP Address เป็นชื่อโดเมนที่คนสามารถเข้าใจได้ แล้วคนก็สามารถใช้ชื่อนั้นเพื่อเข้าถึง IP Address ได้โดยการใช้ DNS Query ไปยัง DNS Server โดยระบุ hostname แล้ว DNS Server จะทำการตอบ IP Address ของ hostname นั้นแล้วระบบจะทำการเชื่อมต่อไปยัง IP Address นั้น

DNS Resolver จะทำงานในส่วนนี้เพื่อหา IP Address ของ hostname ที่ถูกถามโดนจะตอบจาก cache ของตัวเองก่อน ถ้าไม่มีข้อมูลอยู่ใน cache DNS Resolver จะไปถา DNS Server ตัวอื่นมาให้

ประเภทของ DNS Query

การหาคำตอบของ DNS จะมีสามประเภทคือ

Recursive Query

เป็นการ Query ในลักษณะที่ DNS Client ส่ง hostname ไปถาม DNS Resolver แล้ว Resolver จะต้องทำการตอบ โดยเริ่มต้นที่ไปถาม DNS Root Server จนกว่าจะพบ Authoritative Name Server ของ domain นั้น ๆ
Dns-recursive-query.png

Interative Query

เป็นการ Qeury โดยที่ DNS Resolver จะตอบการอ้างอิงไปยัง DNS Server ตัวที่จะตอบคำามได้แล้วให้ Client ถามไปที่ ROOT หรือ Authoritative Name Server ของ domain นั้น ๆ
Dns-interative-query.png

Non-Recursive Query

เป็นการถาม Query แล้ว Resolver ตอบจาก cache ของ Resolver เอง หรือการถาม hostname ไปยัง Authoritative Name Server ของ hostname นั้นโดยตรง

ประเภทของ DNS Server

โดยทั่วไป DNS Server จะมีอยู่ 3 ประเภท

DNS Resolver

เป็น DNS Server ที่ในการ Query hostname เป็น IP Address โดยการทำ Recursive Query เช่น 8.8.8.8 หรือของมช.ที่ให้บริการคือ 10.8.8.8

DNS Root Server

เป็น Server ที่เก็บข้อมูลของ Top Level Domain Name Server ไว้ทั้งหมดเป็นจุดเริ่มต้นของการ Query DNS ซึ่งมีอยู่ 13 ตัวกระจายอยู่ทั่วโลกตาม รายการ DNS Root Server

Authoritative DNS Server

เป็น DNS Server ที่เก็บ Record ต่าง ๆ ของ Domain นั้น ๆ มีหน้าที่ตอบข้อมูลที่อัพเดทที่สุด เป็นจุดสุดท้ายของการ Query DNS

ประเภทของ DNS Record

DNS Record ของ DNS นั้นมีหลายประเภทที่ใช้งานทั่วไปได้แก่

A

Address Mapping record : เก็บ IPv4 ของ hostname

AAAA

IP Version 6 Address : เก็บ IPv6 ของ hostname

CNAME

Canonical Name : เก็บ Alias ของ hostname

MX

Mail exchanger : เก็บ hostname ของ SMTP Mail Server ของ domain นั้น ๆ ใช้ในการเลือกเส้นทางรับส่งอีเมล

NS

Name Server : ระบุ hostname ของ Authoritative DNS Server ของ domain นั้น ๆ

PTR

Reverse-lookup Pointer : ระบุ hostname เมื่อผู้ถามระบุ IP Address ใช้ใน Reverse DNS lookup

TXT

Text Record : ระบุข้อความต่าง ๆ ของ domain ส่วนใหญ่ใช้ในการตรวจสอบความเป็นเจ้าของ domain หรือการประกาศ policy บางอย่างเกียวกับ domain

SRV

Service Location : ระบุข้อมูลบริการและ protocol ต่าง ๆ ภายใน domain

SOA

Start of Authority : ระบบ Authoritative DNS Server ของ domain, email สำหรับติดต่อเจ้าของโดเมนแล้วค่าต่าง ๆ ของ domain zone อ่านเพิ่มเติม

แนะนำ dig เครื่องมือสำหรับ DNS lookup

บน Linux จะมีอยู่แล้ว บน windows สามารถ download ได้ที่ https://www.isc.org/downloads/ เลือก bind for windows และตอนติดตั้งให้เลือกแค่ utilities ไม่ต้องติดตั้ง Service bind

  • lookup domain ปกติ
$ dig www.cmu.ac.th

; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> www.cmu.ac.th
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33420
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.cmu.ac.th.                 IN      A

;; ANSWER SECTION:
www.cmu.ac.th.          10      IN      A       202.28.249.26

;; Query time: 0 msec
;; SERVER: 10.8.8.8#53(10.8.8.8)
;; WHEN: Thu Oct 18 16:07:33 DST 2018
;; MSG SIZE  rcvd: 58
  • lookup ระบุ server ที่ต้องการ
dig @8.8.8.8 www.cmu.ac.th

; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> @8.8.8.8 www.cmu.ac.th
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29837
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;www.cmu.ac.th.                 IN      A

;; ANSWER SECTION:
www.cmu.ac.th.          2347    IN      A       202.28.249.26

;; Query time: 40 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Oct 18 16:09:18 DST 2018
;; MSG SIZE  rcvd: 58
  • lookup ระบุ record เช่น NS,MX,AAAA
$ dig ns cmu.ac.th

; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> ns cmu.ac.th
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42432
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;cmu.ac.th.                     IN      NS

;; ANSWER SECTION:
cmu.ac.th.              3600    IN      NS      ns.cmu.ac.th.
cmu.ac.th.              3600    IN      NS      ns-azure.cmu.ac.th.
cmu.ac.th.              3600    IN      NS      clarinet.asianet.co.th.

;; Query time: 3 msec
;; SERVER: 10.8.8.8#53(10.8.8.8)
;; WHEN: Thu Oct 18 16:11:28 DST 2018
;; MSG SIZE  rcvd: 112

$ dig mx cmu.ac.th

; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> mx cmu.ac.th
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41627
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;cmu.ac.th.                     IN      MX

;; ANSWER SECTION:
cmu.ac.th.              3600    IN      MX      0 cmu-ac-th.mail.protection.outlook.com.

;; Query time: 2 msec
;; SERVER: 10.8.8.8#53(10.8.8.8)
;; WHEN: Thu Oct 18 16:11:47 DST 2018
;; MSG SIZE  rcvd: 91

$ dig aaaa cmu.ac.th

; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> aaaa cmu.ac.th
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6400
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;cmu.ac.th.                     IN      AAAA

;; ANSWER SECTION:
cmu.ac.th.              3600    IN      AAAA    2001:3c8:5007::98:26

;; Query time: 2 msec
;; SERVER: 10.8.8.8#53(10.8.8.8)
;; WHEN: Thu Oct 18 16:12:05 DST 2018
;; MSG SIZE  rcvd: 66
  • lookup ดูเส้นทางการ Query (Iterative Query)
$ dig @1.0.0.1 www.cmu.ac.th +trace +nodnssec

; <<>> DiG 9.11.3-1ubuntu1.1-Ubuntu <<>> @1.0.0.1 www.cmu.ac.th +trace +nodnssec
; (1 server found)
;; global options: +cmd
.                       334     IN      NS      j.root-servers.net.
.                       334     IN      NS      k.root-servers.net.
.                       334     IN      NS      l.root-servers.net.
.                       334     IN      NS      m.root-servers.net.
.                       334     IN      NS      a.root-servers.net.
.                       334     IN      NS      b.root-servers.net.
.                       334     IN      NS      c.root-servers.net.
.                       334     IN      NS      d.root-servers.net.
.                       334     IN      NS      e.root-servers.net.
.                       334     IN      NS      f.root-servers.net.
.                       334     IN      NS      g.root-servers.net.
.                       334     IN      NS      h.root-servers.net.
.                       334     IN      NS      i.root-servers.net.
;; Received 431 bytes from 1.0.0.1#53(1.0.0.1) in 16 ms

th.                     172800  IN      NS      a.thains.co.th.
th.                     172800  IN      NS      b.thains.co.th.
th.                     172800  IN      NS      c.thains.co.th.
th.                     172800  IN      NS      p.thains.co.th.
th.                     172800  IN      NS      ns.thnic.net.
th.                     172800  IN      NS      ams.sns-pb.isc.org.
th.                     172800  IN      NS      sfba.sns-pb.isc.org.
;; Received 473 bytes from 198.97.190.53#53(h.root-servers.net) in 290 ms

cmu.ac.th.              7200    IN      NS      ns.cmu.ac.th.
cmu.ac.th.              7200    IN      NS      ns-azure.cmu.ac.th.
cmu.ac.th.              7200    IN      NS      clarinet.asianet.co.th.
;; Received 196 bytes from 194.0.1.28#53(c.thains.co.th) in 14 ms

www.cmu.ac.th.          3600    IN      A       202.28.249.26
;; Received 58 bytes from 202.28.249.30#53(ns.cmu.ac.th) in 2 ms

บทความที่เกี่ยวข้อง

ติดต่อสอบถามเพิ่มเติม