Author Topic: DNS คืออะไร config อย่างไร คำศัพท์ เกี่ยวกับ DNS , tcp 53 ต่างกับ udp 53 อย่างไร  (Read 36837 times)

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
#คำศัพท์ เกี่ยวกับ DNS

ความหมาย/หน้าที่
Forward Master Zone
แปลงชื่อ Domain เป็น IP Adress

Reverse Master Zone
แปลง IP Adress เป็นชื่อ Domain

BIND(Berkeley Internet Name Domain)
โปรแกรมให้บริการดีเอ็นเอส

Quote
bind-utils-9.2.4-2
bind-9.2.4-2
bind-libs-9.2.4-2
ypbind-1.17.2-3
bind-chroot-9.2.4-2

Master Name Sever

Slave Name Server Name Server มีสองแบบคือ Master Name Sever และ
Slave Name Server ซึ่งจะต้องอยู่ต่างเครื่องกัน

Master Name Server จะอ่านข้อมูลประจำโซนจากแฟ้มใน Disk และมีสิทธิหน้าที่ในโซนนั้นๆ
Slave Name Server สำเนาข้อมูลจาก Master Name Server

named โปรแกรมบริการชื่อ Domain บน Linux

/usr/sbin/named -u named -t /var/named/chroot
Host
เครื่องคอมพิวเตอร์ศูนย์กลางที่ต่อเข้ากับ Network,Internet เพื่อบริการใดๆ

Domain
ชื่อ web address/computer
ทำให้เข้าใจ/จำง่าย/มีความหมาย กว่า IP Address

ถ้าเรียก โดเมน เหมือนเรียก IP Address

http://www.icann.org/

Sub Domain
ส่วนย่อยของ Domain เช่น mail.dns.linuxstep.com
mail คือ Sub Domain
Localhost = เครื่องเราเอง จะตั้งค่า ip address อะไร แต่เมื่อเรียก
Localhost ก็จะเรียกเครื่องเราเอง

IP Address 127.0.0.1 = Localhost
IP(Internet Protocal)
IP หรือ Internet Protocal
IP Address คือรหัสตัวเลขที่กำหนดขึ้น เพื่อใช้อ้างถึงที่อยู่ของ Host และ Network
ตัวเลขเหล่านี้จะไม่ซ้ำกัน (unique numeric) ซึ่งมีมาตรฐานในการกำหนด และเป็นที่รู้จักทั่วโลก IPV4,IPV6
Port ช่องทาง ที่ใช้ติดต่อกับ computer/อุปกรณ์ ใน network

(Address Localhost)
สำหรับ window กำหนด loopback IP=127.0.0.1 เมื่อส่งสัญญาณออกจะไม่ส่งออกนอกเครือข่าย แต่จะกลับมา
ที่ต้นทาง ด้วย loop back driver

http://www.certiguide.com/netplus/
cg_np_IVLoopbackAddressingandConnections.htm

Root Domain ตอนนี้มีอยู่ 13 ตัวทั่วโลก
ลำดับบนสุดของระบบ DNS โดยมีการกำหนดดังนี้
ลำดับที่ 1 root
ลำดับที่ 2 .com, .net, .edu, .gov, .org, .th, ...
ลำดับที่ 3 subdomain ตัวอย่าง mail3.linuxstep.com
mail3 =subdomain

ตัวอย่างลำดับ DNS
www2.dns.linuxstep.com

Name Resolution

การที่ DNS Server เก็บหมายเลข IP Address คู่กับชื่อเครื่องแบบ Domain Name
เพื่อทำการค้นหาชื่อตามการร้องขอของเครื่อง DNS client
DNS Server
เครื่องที่คอยจัดการ/ดูแล/แก้ไข domain subdomain
Client
เครื่องลูกข่าย
Resolver
กลไกการแปลง domain เป็น ip address
Reverse File
/etc/resolve.conf

การ resolve หมายถึง
DNS Zone
การจัด domain เป็นพื้นที่ย่อย
TCP,UDP,ARP

เป็น protocol ที่ DNS ใช้ในการติดต่อผ่าน port 53

TCP - ปรับปรุงข้อมูล
UDP - ส่งคำขอข้อมูล
ARP - แปลงค่า IP address เป็น Hardware

#Files ที่ใช้ในการ Config
Files Config

ความหมาย / หน้าที่
/etc/named.conf
กำหนดการทำงานของ Name Server สำคัญมาก
/var/named/named.ca เก็บข้อมูลชื่อ Server ซื่งเป็น Root Name Server
ไม่ควรแก้ไขข้อมูลใน file นี้เป็นอันขาด
/var/named/named.local เก็บข้อมูลการ map ชื่อ กับ IP Address แบบ Reverse Lookup
/var/named/dm.com.zone ระบุชื่อ Server,Zone, ทำ Forward Lookup
/var/named/ 203.203.203.203.zone

Reward Lookup
/etc/hosts
เก็บชื่อ host
/etc/resolve.conf
เก็บชื่อ domain และ ip ที่ทำงานแบบ Forward Lookup
/etc/sysconfig/network เก็บชื่อ host ของเครื่อง
/etc/sysconfig/named กำหนดตำแหน่งของ named ที่เป็น file config

#ความหมายของ SOA Resource Record
SOA (Start to authority)
เริ่มให้สิทธิ/อำนาจ

ความหมาย / หน้าที่

Domain Name ที่ได้จาก /etc/named.comf
IN Internet
serial = เป็นหมายเลขที่ใช้แสดงการอัพเดทข้อมูลระหว่าง Primary master และ Secondary master
refresh = ระยะเวลา refresh ข้อมูล
retry = ระยะเวลา ตรวจสอบข้อมูลกับ Primary DNS Server
expire = ระยะเวลา หมดอายุ กรณีติดต่อกับ Primary DNS Server ไม่ได้

#ความหมายข้อมูลใน Fields Type DNS Record
Type

ความหมาย / หน้าที่
A = แปลงชื่อ Domain เป็น IP Address แบบ ipv4
NS = Name Server record กำหนดว่า server ใดรับผิดชอบ domain
PTR = Pointer record ใช้ Map IP Address เป็น Host

MX = Mail Exchanger
ใช้ระบุชื่อเครื่อง Mail Server ของ Domain
เมื่อเราต้องกำหนด MX เราจะพบว่าต้องกำหนด
MX 10 mail1.example.com
MX 20 mail2.newdomain.com

ค่าเลข 10 และ20 นั้นหมายถึง Priority ของ Mail โดยค่าน้อยสุดจะสำคัญสุด

ชื่อหลัง MX ต้องเป็น Domain เท่านั้นและไม่ใช่ CName
CNAME = Cononical name ใช้เป็น Alias name ให้เป็น host จริง
เช่น ns,mail,www,www2
;
Remark

« Last Edit: พฤษภาคม 13, 2013, 02:34:25 PM by golfreeze »

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
"เกิดความไม่เข้าใจใน file DNS ของ freeBSD" -> มันไม่ใช่ของ FreeBSD นะ
ทำความเข้าใจก่อน FreeBSD ใช้ OSS เหมือน Linux ใช้ bind เหมือนกัน ดังนั้นไม่ว่า Linux เหรอ BSD
ก็เหมือนกันครับ หลักการ config เหมือนกัน อ่านฉลากให้เข้าใจการทำงานแล้ว จะใช้ os ไหนก็ config
ง่ายครับ

มาต่อเรื่อง ไฟล์ DNS กัน

1. ไฟล์ config ของ name deamon คือ named.conf ซึ่งจะอยู่ไหนก็แล้วแต่ os นั้นจะลงมาไว้ไหนส่วน
freebsd
/etc/namedb/

2. ต้องเข้าใจเรื่อง ของ zone file ก่อนมี type คือ
- Master
- Slave

ใน Master ของโดเมนเนม หนึ่งมี 2ไฟล์
ไฟล์แรก domain หรือ zone ที่เราไปจดมานั้นแหละครับ ประกอบด้วย records

- SOA
- NS
- A
- MX
- CNAME

ไฟล์ที่สอง Reverse lookup ชื่อมันบอกว่ามองย้อนกลับไป จาก ip->ชื่อ ประกอบด้วยrecords

- SOA
- NS
- PTR

รูแบบของzone นี้จะเป็น ip ที่เราใช้ที่ผูกติดกับชื่อ domain เรา เช่น เราใช้ 202.183.202.1 -->
22.183.202.in-addr.arpa ต้องเขียนแบบนี้(ดูรูปอธิบาย root หลักคือ dot)

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
ตัวอย่างไฟล์ ของ named.conf
zone "kittipong.com" {
type master;
file "kittipong.com";
};

zone "80.29.202.in-addr.arpa" {
type master;
file "202.29.80.0";
ตัวอย่าง ของ primary ใน zone
@ IN SOA kittipong.com. root.kittipong.com. (
2005120901 ; Serial
3600 ; Refresh
900 ; Retry
3600000 ; Expire
3600 ) ; Minimum
IN NS ns.kittipong.com.
MX 10 mail.kittipong.com.
ns IN A 202.29.80.200
mail IN CNAME ns
www IN CNAME ns

ตัวอย่างของ slave ( reverse zone)
@ IN SOA kittipong.com. root.kittipong.com. (
2005120901 ; Serial
3600 ; Refresh
900 ; Retry
3600000 ; Expire
3600 ) ; Minimum
IN NS ns.kittipong.com.
200 IN PTR www.kittipong.com.
200 IN PTR mail.kittipong.com.

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
วันนี้ มี trick การ config ให้ bind(DNS service) มีความ secure ขึ้นครับ

ตัวที่ผม base on freebsd 6.2 กับ Bind 9 ครับ

ก็เรา config ให้ เครื่อง dns อื่นๆ มา query ข้อมูลของ dns server ของเรา

เพื่อป้องกัน การทำ spoof dns กับ ลด bw ที่เข้ามา ครับ

โดย config ที่ /etc/named/named.conf

options {
directory "/etc/namedb";
pid-file "/var/run/named/pid";
dump-file "/var/dump/named_dump.db";
statistics-file "/var/stats/named.stats";

listen-on {
127.0.0.1;
x.x.x.x;
};
query-source address * port 53;

recursion yes;
allow-recursion { 127.0.0.1; x.x.x.x; };
};

#ip ของ dns server ที่เราจะให้มา update กับ zone dns ของเครื่องเราครับ
acl nameserver {
x.x.x.x;
203.146.127.x;
61.90.x.x;
61.90.y.y;
66.252.x.x;
};

key "rndc-key" {
algorithm hmac-md5;
secret "ชชำชกดหกดหกด";
};
controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndc-key"; };
};

zone "0.0.127.IN-ADDR.ARPA" {
type master;
file "master/localhost.rev";
allow-transfer { none; };
};

zone "ผผผ.com" { type master; file "master/ผผผ.com"; allow-transfer {
nameserver; }; };


####
# ip เครื่อง dns server เราครับ = x.x.x.x
####

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
###setting dns load balance by round robin

Balancing Mail

The normal method of handling mail fail-over is using the 'preference' value which is
described in this note. However, using the MX record you can balance mail in two ways.

1. Define multiple MX records with the same priority e.g.

; zone file fragment
IN MX 10 mail.example.com.
IN MX 10 mail1.example.com.
IN MX 10 mail2.example.com.
....
mail IN A 192.168.0.4
mail1 IN A 192.168.0.5
mail2 IN A 192.168.0.6

The name server will deliver the MX records in the order defined by the rrset-order and the
receiving SMTP software will select one based on its algorithm. In some cases the SMTP alogithm may
work against the definition of the rrset-order statement. Current versions of sendmail (8.13.x),
Exim (4.44) and Postfix (2.1 or 2.2) all have definitive references to indicate they randomly select
equal preference servers (Postfix allows control of the behaviour with the smtp_randomize_addresses
parameter) and consequentially may use an address which the rrset-order has carefully tried to
change! qmail, courier-mta and Microsoft (Exchange and IIS SMTP) documentation does not appear to
have definitive references to indicate how they handle this case.
2. The alternate approach is to define multiple A records with the same name and multiple IP
addresses.

; zone file fragment
IN MX 10 mail.example.com.
....
mail IN A 192.168.0.4
IN A 192.168.0.5
IN A 192.168.0.6

In this case the load-balancing effect is under the control of BIND and the rrset-order
record. In order to avoid problems if the receiving mail system does reverse look-up as a spam check
then the PTR records for 192.168.0.4, 192.168.0.5, 192.168.0.6 above must all define to
mail.example.com.

In all the above cases each mail server must be capable of handling and synchronising the load for
all the mail boxes served by the domain, using some appropriate back-end to do this or by defining
all but one server to be a relay or forwarder.

Balancing Other Services

Assuming you want to load share your ftp or web services then you simply define multiple A records
with the same name and different IPs as in the example below.

; zone file fragment

ftp IN A 192.168.0.4
ftp IN A 192.168.0.5
ftp IN A 192.168.0.6
www IN A 192.168.0.7
www IN A 192.168.0.8

; or use this format which gives exactly the same result
ftp IN A 192.168.0.4
IN A 192.168.0.5
IN A 192.168.0.6
www IN A 192.168.0.7
IN A 192.168.0.8

The DNS will deliver all the IP addresses defined, the first IP address in the list will be in a
default round robin (controlled by the rrset-order 'named.conf' statement). The FTP and WEB
servers must all be exact replicas of each other in this scenario.

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
DNS port 53 สำหรับ protocol ที่ใช้ต่างกันอย่างไร ระหว่าง

udp port 53 = ใช้ในกรณี ตอบ query ที่เข้ามาถาม record เช่น computer A ต้องการสอบถามว่า www.packetlove.com อยู่ที่ไหน
                    จาก request นี้ Computer A ต้องถามไปที่ root server ของ .com
                    ต่อจากนั้น root server .com ก็ตอบว่าให้มาถาม nameserver ns1.packetlove.com , ns2.packetlove.com
                    เมื่อเข้ามาถาม ns1.packetlove.com แล้วตัวมันก็ตอบไปว่า www.packetlove.com อยู่ที่ ip = 203.146.215.105 ครับ
                    

tcp port 53 = ส่วนในกรณีที่จะใช้ tcp protocol นั้นจะใช้เมื่อมีการทำ transfer zone file ไปยังกลุ่มของ dns slave server ครับ
                   ต้องมีการแลกเปลี่ยน key กันดังนั้นจำเป็นต้องใช้เป็น tcp ครับเพื่อความแน่นอนของ packet

 ;)
« Last Edit: กรกฎาคม 19, 2011, 12:09:23 PM by golfreeze »

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
#คำสั่ง Linux เกี่ยวกับ DNS

Command ความหมาย / หน้าที่ / ตัวอย่าง

named-checkconf = ตรวจ error named.conf
e.g.
#named-checkconf /etc/named.conf
named-checkzone = ตรวจ error zone
e.g.

#named-checkzone lp.com /var/named/lp.com.zone
service network restart
reboot network service
service named restart
reboot named service

nslookup
ค้นหา domain,ip address รวมทั้งข้อมูลต่างๆ

[root@l203 root]# nslookup
> www.li203.com
Server: 203.156.167.203
Address: 203.156.167.203#53

www.li203.com canonical name = l203.li203.com.
Name: l203.li203.com
Address: 203.156.167.203
> 203.156.167.203
Server: 203.156.167.203
Address: 203.156.167.203#53

203.167.156.203.in-addr.arpa name = l203.li203.com.
> mail.li203.com
Server: 203.156.167.203
Address: 203.156.167.203#53

mail.li203.com canonical name = l203.li203.com.
Name: l203.li203.com
Address: 203.156.167.203

dig update ข้อมูลให้ทันสมัย
e.g.
dig > /var/named/named.ca
host
แสดง domain และ ip address
e.g.
[root@l203 root]# host www.li203.com
www.li203.com is an alias for l203.li203.com.
l203.li203.com has address 203.156.167.203

#Forward DNS
ขั้นตอนที่

ความหมาย / หน้าที่
1 แก้ named.conf

zone "domain.com" IN {
type forward;
forwarders { 203.156.138.45; };
};

#Redirect domain
ขั้นตอนที่ ความหมาย / หน้าที่

ให้แก้ index.html หรือ index.php

<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="5;URL=http://www.domain.com">
</head>
<body>
<center>
ืำnew website
<a href="http://www.domain.com">www.domain.com</a>
</center>
</body>
</html>

จาก www.itwizard.info

การทำเครื่องเป็น Primary DNS หรือ Master DNS
ทำไมต้องทำ เพราะต้องการให้เครื่องเป็นเครื่องหลักของ dns และอีกเหตุผลก็คือconfig ให้ support กับ
Secondary
จากการconfig ธรรมดาแล้วให้กำหนดค่าจาก named.conf

zone "abcd.com" { -->ถ้ากรอก www.abcd.com มาจะเข้า zone นี้
type master; -->เป็นเครื่อง Primary Server หรือ master
file "abcd.com.zone"; -->ไฟล์ที่ทำการ Forward ชื่อเครื่อง ไปเป็น ipของ server
allow-transfer{192.168.101.3;}; -->คำสั่งเพื่อให้ transfer ไปยัง ip address เครื่อง Secondary
Server Server เป็นการ ระบุ Domain ที่ต้องการทำ Backup
allow-query{any;}; -->query ทุกๆอย่างที่มีอยู่ใน Primary Server

การทำให้เครื่องเป็น Secondary DNS
ทำไมต้องทำเมื่อต้องการสำรอง DNS เราต้องรับค่ามาจาก Master DNS ให้กำหนดค่าใน named.conf

zone "abcd.com" {--> ถ้ากรอก www.abcd.com มาจะเข้า zone
type slave; -->เป็นเครื่อง Secondary Server หรือ slave
file "slaves/abcd.com.zone"; -->ไฟล์ที่ทำการ Forward ชื่อเครื่อง ไปเป็น ipของ
server อ้างอิงไปยังไฟล์ของเครื่อง Primary Server
masters { 192.168.101.213;}; -->กำหนด ip เครื่อง Primary Server เป็นการ ระบุ Domain ที่ต้องการทำ
Backup
allow-query{ any;}; -->query ทุกๆอย่างที่มีอยู่ใน Primary Server
};

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email

การทำสอบ Master DNS และ Secondary DNS
#service named restart


#หลักการทำงานของ DNS
ขั้นตอนที่

ความหมาย / หน้าที่
1. client(ผู้เล่น) ต้องการเข้า www.linuxstep.com เครื่อง client จะขอ IP Address ไปที่ DNS Server
(ถ้าไม่พบ IP Address) จะขอ IP Address กับ DNS Server ในลำดับที่สูงกว่า เช่น ISP
2. DNS Server ของ ISP ค้นหา IP Address ต่อไป ถ้าไม่พบ ก็ต้องส่งต่อไปที่
Root Domain Server ที่ Root Domain Server ต้องเจอแน่นอนเพราะเป็นสถานที่สุดท้ายแล้ว
3. เมื่อเจอก็จะได้ IP Address ของ www.linuxstep.com และแจ้งไปที่ Domain Server ของ ISP ทราบและจัดเก็บไว้ด้วย
4. Domain Server ของ ISP ก็ส่งต่อไปที่ DNS Server ของ Client และแจ้ง IP Address ไปที่ client (ผู้เล่น)
5. เมื่อ client ได้ IP Address ของ www.linuxstep.com แล้ว ก็ติดต่อกับ IP Address ได้โดยตรง โดยการรับส่งข้อมูลจะใช้ Protocol TCP

#ชื่อเฉพาะที่ได้กำหนดเกี่ยวกับ DNS

.mil = ทหาร
.com = การค้า
.gov = รัฐบาล
.net = internet
.info = ข้อมูล ข่าวสาร
.org = องค์กร
.edu = การศึกษา
.co = บริษัท
.arts = ศิลปะ
.rec = องค์กร
.nom = บุคคลทั่วไป
.web = websote
.ac = สถานศึกษา
.store = บริษัทที่ทำการค้า

FAQ
คำถามที่พบบ่อยเกี่ยวกับ DNS
คำถาม

ตอบ
1. port ใดที่ใช้กับ DNS = 53
2.หน่วยงานใดรับผิดชอบ DNS
ระดับโลก คือ Internic
ประเทศไทย คือ thnic
3. TTL คืออะไร Time To Live เวลาที่กำหนดให้ปรับปรุงข้อมูลเป็น วินาที
4. DNS ย่อมาจาก Domain Name System

5 ip address 1 ตัว กำหนดให้ได้
หลาย domain ได้หรือไม่
= ตามหลักการ DNS ของ Linux ทำได้ครับ เพราะใช้ Virtual แทน กรณีมีหลายชื่อ domain

6.โปรแกรมอะไรจัดการ DNS ถ้า Redhat คือ bind

ถ้าเป็น centOS5
bind-chroot-9.3.3-10.el5
system-config-bind-4.0.3-2.el5.centos
ypbind-1.19-8.el5
bind-9.3.3-10.el5
bind-utils-9.3.3-10.el5
kdebindings-3.5.4-1.fc6
bind-libs-9.3.3-10.el5

7.การศึกษาการทำ DNS ยากหรือไม่เพราะบางคนไม่สามารถ แก้ได้ ยากหรือไม่แล้วแต่คน ผมแนะนำครับ
= ควรจะมีความตั้งใจและหาคนแนะนำ
8.domain redirect คือ การแปลงชื่อให้เป็นชื่ออื่น โดยใช้ record ของการ REDIRECT ใน DNS ช่วยหรือจะเขียนไฟล์ไว้ที่หน้าเว็บให้ redirect ไปก็ได้
10.จำ config อย่างไร ให้ dns
ค้นได้ด้วย google อยู่ที่การเขียน code html
11.master name server คือ เป็นฐานข้อมูลหลักของ Domain แก้ไขได้ที่เดียว
12.slave name server คือ สำเนาของ master name server
13.root name server คือ ลำดับบนสุดของ domain
14.ใน windows server มีการ
= กำหนด dns หรือไม่ มีครับลองไปศึกษาดูได้จาก windows2003 R
15.webmin จัดการ dns มีหรือไม่ มีครับ www.webmin.com , www.rpmfind.net
= โปรแกรม caching-nameserver*.rpm