DNS คืออะไร ทำงานอย่างไร และทำไมต้องรู้เรื่อง DNS
What is DNS (Domain Name System)? How it works, DNS record types, and common DNS troubleshooting.
สารบัญ
DNS คืออะไร
DNS (Domain Name System) คือระบบที่แปลงชื่อโดเมนที่มนุษย์อ่านได้ เช่น "google.com" ให้เป็น IP Address ที่คอมพิวเตอร์ใช้ติดต่อกัน เช่น "142.250.185.14" DNS ทำงานเหมือนสมุดโทรศัพท์ของ Internet โดยใช้เซิร์ฟเวอร์ที่เรียกว่า DNS Resolver, Root Nameserver, TLD Nameserver และ Authoritative Nameserver ร่วมกัน
DNS (Domain Name System) translates human-readable domain names like "google.com" into IP addresses like "142.250.185.14" that computers use to connect. It functions as the internet's phone book, using DNS Resolvers, Root Nameservers, TLD Nameservers, and Authoritative Nameservers.
- ทำงานเหมือน "สมุดโทรศัพท์ของ Internet"
- แปลง Domain → IP ใน Milliseconds
- ทุกโดเมนมี DNS Records ที่กำหนดค่าต่างๆ
- ใช้ UDP Port 53 เป็นหลัก (TCP สำหรับ Transfer ใหญ่)
- DNS มีหลาย Level: Root → TLD → Authoritative
DNS ทำงานอย่างไร
เมื่อพิมพ์โดเมนในเบราว์เซอร์ ระบบส่งคำขอไปยัง DNS Resolver ของ ISP (หรือที่กำหนดเอง เช่น 8.8.8.8) ถ้า Resolver ไม่มี Cache จะถามไปยัง Root Nameserver → TLD Nameserver → Authoritative Nameserver ของโดเมน ซึ่งตอบกลับด้วย IP Address จากนั้นเบราว์เซอร์จึงเชื่อมต่อไปยัง IP นั้น
When you type a domain, your browser queries a DNS Resolver (your ISP's or a custom one like 8.8.8.8). If not cached, the Resolver queries Root Nameserver → TLD Nameserver → Authoritative Nameserver, which returns the IP address. The browser then connects to that IP.
- Browser → DNS Resolver (ISP/8.8.8.8)
- Resolver ตรวจ Cache ก่อน (TTL)
- Cache Miss → Root Nameserver (.com? → สิงคโปร์)
- TLD Nameserver → Authoritative Nameserver
- Authoritative → ตอบ IP Address กลับมา
- กระบวนการทั้งหมดเสร็จใน 1-100ms
ประเภท DNS Record
DNS Records คือชุดข้อมูลที่บอกว่าโดเมนชี้ไปที่ไหน ประกอบด้วยหลายประเภท แต่ละอย่างมีหน้าที่ต่างกัน Record ที่ใช้บ่อยที่สุดคือ A Record, AAAA Record, MX Record, CNAME Record, TXT Record และ NS Record
DNS Records are data sets defining where a domain points. The most commonly used are A Records, AAAA Records, MX Records, CNAME Records, TXT Records, and NS Records — each serving a distinct purpose.
- A Record: ชี้โดเมน → IPv4 Address
- AAAA Record: ชี้โดเมน → IPv6 Address
- MX Record: ระบุ Mail Server
- CNAME: Alias โดเมนหนึ่งไปอีกโดเมน
- TXT: เก็บข้อความ เช่น SPF, DKIM, Verification
- NS Record: ระบุ Nameserver ของโดเมน
- SOA Record: ข้อมูล Authority ของ Zone
A Record และ AAAA Record
A Record เป็น Record พื้นฐานที่สำคัญที่สุด ทำหน้าที่ชี้ชื่อโดเมนหรือ Subdomain ไปยัง IPv4 Address ของเซิร์ฟเวอร์ AAAA Record ทำหน้าที่เดียวกันแต่สำหรับ IPv6 Address สมัยใหม่ควรตั้งทั้งสองเพื่อรองรับทั้ง IPv4 และ IPv6
A Record is the most fundamental DNS record, pointing a domain or subdomain to an IPv4 server address. AAAA Records do the same for IPv6. Modern setups should configure both for full compatibility.
- A Record: example.com → 103.28.x.x (IPv4)
- AAAA Record: example.com → 2001:db8::x (IPv6)
- @ หมายถึง root domain เอง
- Wildcard: *.example.com ชี้ไปที่ IP เดียว
- Multiple A Record: สำหรับ Load Balancing
MX Record
MX (Mail Exchanger) Record ระบุว่า Email ที่ส่งมาที่โดเมนของคุณต้องไปที่ Mail Server ใด มี Priority (ตัวเลข) กำกับ ตัวเลขน้อย = Priority สูงกว่า ถ้าต้องการ Redundancy ตั้ง MX Record หลายตัวที่ต่าง Priority
MX (Mail Exchanger) Records specify which mail server handles email for your domain, with Priority numbers (lower = higher priority). Multiple MX records provide redundancy.
- Priority 10: Main Mail Server (Priority สูงสุด)
- Priority 20: Backup Mail Server
- ตั้งให้ชี้ไป Hostname ไม่ใช่ IP โดยตรง
- ตรวจสอบ MX ด้วย: dig MX example.com
- ต้องตั้ง A Record สำหรับ Hostname ด้วย
CNAME Record
CNAME (Canonical Name) Record ทำหน้าที่สร้าง Alias โดยชี้โดเมนหนึ่งไปที่อีกโดเมนหนึ่ง เช่น www.example.com → example.com หรือ shop.example.com → store.shopify.com ข้อจำกัดคือ CNAME ไม่สามารถตั้งที่ Root Domain (@) ได้
CNAME (Canonical Name) Records create aliases pointing one domain to another — like www.example.com → example.com or shop.example.com → store.shopify.com. Important: CNAME cannot be set at the root domain (@).
- www → example.com (CNAME)
- blog.example.com → myblog.wordpress.com
- ห้ามใช้ CNAME ที่ Root Domain (@)
- ห้ามใช้ CNAME ร่วมกับ MX Record บน Subdomain เดียว
- ALIAS/ANAME: ใช้ได้ที่ Root Domain แทน CNAME
TTL คืออะไร มีผลต่อ DNS อย่างไร
TTL (Time to Live) คือค่าที่บอกว่า DNS Resolver ควร Cache ข้อมูลไว้นานแค่ไหน (เป็นวินาที) ค่า TTL ต่ำ (เช่น 300 วินาที = 5 นาที) ทำให้ DNS เปลี่ยนแปลงเร็ว แต่เพิ่ม Load บน DNS Server ค่า TTL สูง (86400 วินาที = 1 วัน) ลด Query แต่เปลี่ยนแปลงช้า
TTL (Time to Live) defines how long DNS Resolvers cache your records in seconds. Low TTL (300 = 5 min) enables fast propagation but increases DNS server load. High TTL (86400 = 1 day) reduces queries but slows changes.
- TTL 300: เปลี่ยนเร็ว เหมาะก่อน Migration
- TTL 3600: ค่า Default ที่ดีสำหรับทั่วไป
- TTL 86400: เปลี่ยนช้า เหมาะกับ Record ที่คงที่
- ลด TTL ล่วงหน้า 24-48 ชม. ก่อนย้าย Server
- คาดเดาเวลา Propagation = Max TTL
DNS Propagation คืออะไร
DNS Propagation คือระยะเวลาที่การเปลี่ยนแปลง DNS ใช้ในการกระจายไปยัง DNS Server ทั่วโลก โดยทั่วไปใช้เวลา 1-48 ชั่วโมง แต่มักเร็วกว่านั้นมากถ้าตั้ง TTL ต่ำ ระหว่าง Propagation ผู้เข้าชมบางรายอาจเห็นเว็บเก่า บางรายเห็นเว็บใหม่
DNS Propagation is the time it takes for DNS changes to spread globally — typically 1-48 hours, though often much faster with low TTL settings. During propagation, some visitors may see the old site while others see the new one.
- ใช้เวลา 1-48 ชั่วโมง ขึ้นอยู่กับ TTL
- ตรวจสอบด้วย: dnschecker.org
- ลด TTL เป็น 300 ล่วงหน้า 24 ชม. ก่อน Change
- Flush DNS Local: ipconfig /flushdns (Windows)
- DNS ชี้ถูกแต่เว็บไม่ขึ้น → ลอง Incognito/Different ISP
แก้ปัญหา DNS ที่พบบ่อย
ปัญหา DNS ที่พบบ่อยได้แก่ เว็บขึ้น "Server Not Found" แม้โดเมนถูกต้อง Email ส่งไม่ถึง หรือ SSL Certificate ไม่ออก การ Debug เริ่มจากตรวจสอบ DNS Records ด้วย nslookup หรือ dig และตรวจสอบ Nameserver ว่าชี้ถูกต้องหรือไม่
Common DNS issues: "Server Not Found" despite correct domain, email delivery failures, or SSL certificates not issuing. Debug by checking DNS records with nslookup or dig, and verify nameservers point correctly.
- Server Not Found: ตรวจ A Record ด้วย nslookup domain.com
- Email ไม่ถึง: ตรวจ MX Record ด้วย dig MX domain.com
- SSL ไม่ออก: ตรวจ CAA Record ไม่บล็อก CA
- DNS Loop: CNAME ชี้วนหากัน ลบออกแล้วตั้งใหม่
- ใช้ dnsxray.com ตรวจ DNS Health ครบ