ติดตั้งและตั้งค่า DNS Server บน Windows Server
DNS คือบริการที่เงียบที่สุดแต่พังแล้วกระทบทุกอย่าง ในเครือข่ายองค์กรที่ใช้ Active Directory DNS ไม่ได้ทำแค่แปลงชื่อเป็น IP แต่ยังเป็นสิ่งที่เครื่องลูกใช้ค้นหา Domain Controller ด้วย
คู่มือนี้ตั้ง DNS Server สำหรับใช้ภายในองค์กร ทั้งกรณีที่ติดตั้งมาพร้อม Active Directory และกรณีที่ตั้งเป็นเครื่องแยกต่างหาก
สิ่งที่ต้องเตรียม
- Windows Server 2019 ขึ้นไป พร้อม IP แบบคงที่
- สิทธิ์ Administrator
- แผนผังชื่อและ IP ที่จะใช้ในองค์กร
ขั้นตอนที่ 1: ติดตั้ง Role
Install-WindowsFeature -Name DNS -IncludeManagementTools
Get-Service DNS
Get-DnsServer | Select-Object -ExpandProperty ServerSetting
หากติดตั้ง Active Directory ไปแล้วพร้อมตัวเลือก -InstallDns:$true DNS จะถูกติดตั้งให้อัตโนมัติ ข้ามขั้นตอนนี้ได้
ขั้นตอนที่ 2: สร้าง Forward Lookup Zone
Zone คือขอบเขตของชื่อที่เซิร์ฟเวอร์นี้รับผิดชอบ
# กรณีมี Active Directory ให้เก็บ Zone ไว้ใน AD เพื่อให้จำลองข้อมูลอัตโนมัติ
Add-DnsServerPrimaryZone -Name "corp.example.com" `
-ReplicationScope "Domain" -DynamicUpdate "Secure"
# กรณีไม่มี AD ให้เก็บเป็นไฟล์
Add-DnsServerPrimaryZone -Name "corp.example.com" `
-ZoneFile "corp.example.com.dns" -DynamicUpdate "None"
Get-DnsServerZone
ตัวเลือก -DynamicUpdate "Secure" อนุญาตให้เฉพาะเครื่องที่อยู่ในโดเมนลงทะเบียนชื่อตัวเองได้ ซึ่งเป็นค่าที่ควรใช้ อย่าตั้งเป็น NonsecureAndSecure เพราะใครก็ได้จะเขียนระเบียนทับได้
ขั้นตอนที่ 3: สร้าง Reverse Lookup Zone
ใช้แปลง IP กลับเป็นชื่อ จำเป็นสำหรับการวิเคราะห์ Log และบางบริการที่ตรวจสอบย้อนกลับ
Add-DnsServerPrimaryZone -NetworkId "10.0.0.0/24" -ReplicationScope "Domain"
Get-DnsServerZone | Where-Object { $_.IsReverseLookupZone }
ขั้นตอนที่ 4: เพิ่มระเบียน
# A Record พร้อมสร้าง PTR ให้อัตโนมัติ
Add-DnsServerResourceRecordA -Name "web1" -ZoneName "corp.example.com" `
-IPv4Address "10.0.0.11" -CreatePtr
Add-DnsServerResourceRecordA -Name "db1" -ZoneName "corp.example.com" `
-IPv4Address "10.0.0.21" -CreatePtr
# CNAME ชี้ชื่อเล่นไปยังชื่อจริง
Add-DnsServerResourceRecordCName -Name "intranet" `
-HostNameAlias "web1.corp.example.com" -ZoneName "corp.example.com"
# MX สำหรับอีเมล
Add-DnsServerResourceRecordMX -Name "." -ZoneName "corp.example.com" `
-MailExchange "mail.corp.example.com" -Preference 10
# TXT เช่น SPF
Add-DnsServerResourceRecord -Txt -Name "@" -ZoneName "corp.example.com" `
-DescriptiveText "v=spf1 include:_spf.example.com -all"
Get-DnsServerResourceRecord -ZoneName "corp.example.com"
ขั้นตอนที่ 5: ตั้ง Forwarder ให้ค้นหาชื่อภายนอกได้
เมื่อเครื่องลูกถามชื่อที่ไม่ได้อยู่ใน Zone ของเรา เช่น google.com เซิร์ฟเวอร์ต้องส่งต่อคำถามออกไป
Set-DnsServerForwarder -IPAddress "1.1.1.1", "8.8.8.8" -UseRootHint $false
Get-DnsServerForwarder
การตั้ง -UseRootHint $false บังคับให้ใช้ Forwarder ที่กำหนดเท่านั้น ทำให้ควบคุมเส้นทางการค้นหาได้ และมักเร็วกว่าการไล่ถามจาก Root Server เอง
หากต้องการส่งต่อเฉพาะบางโดเมนไปยังเซิร์ฟเวอร์เฉพาะ ใช้ Conditional Forwarder
Add-DnsServerConditionalForwarderZone -Name "partner.co.th" `
-MasterServers "192.168.50.10" -ReplicationScope "Domain"
ขั้นตอนที่ 6: ตั้งค่าอายุและการล้างระเบียนเก่า
ในเครือข่ายที่เครื่องลูกได้ IP จาก DHCP ระเบียนเก่าจะสะสมจนชี้ผิด ตั้งให้ล้างอัตโนมัติ
Set-DnsServerScavenging -ScavengingState $true -ScavengingInterval 7.00:00:00 `
-RefreshInterval 7.00:00:00 -NoRefreshInterval 7.00:00:00 -ApplyOnAllZones
Get-DnsServerScavenging
ค่าเหล่านี้หมายความว่า ระเบียนที่ไม่ถูกต่ออายุเลยเป็นเวลา 14 วันจะถูกลบทิ้ง
ขั้นตอนที่ 7: ทดสอบ
Resolve-DnsName web1.corp.example.com -Server 10.0.0.10
Resolve-DnsName 10.0.0.11 -Type PTR -Server 10.0.0.10
Resolve-DnsName google.com -Server 10.0.0.10
nslookup web1.corp.example.com 10.0.0.10
Test-DnsServer -IPAddress 10.0.0.10 -ZoneName "corp.example.com"
ทดสอบจากเครื่องลูกด้วย ไม่ใช่แค่จากตัวเซิร์ฟเวอร์เอง เพราะปัญหา Firewall จะเห็นเฉพาะเมื่อทดสอบข้ามเครื่อง
ขั้นตอนที่ 8: เปิด Log เพื่อไล่ปัญหา
# เปิดบันทึกการสอบถามแบบละเอียด ใช้เฉพาะตอนไล่ปัญหา
Set-DnsServerDiagnostics -All $true
Get-DnsServerDiagnostics
# ปิดเมื่อเสร็จ เพราะกินพื้นที่มาก
Set-DnsServerDiagnostics -All $false
ดูสถิติการทำงาน
Get-DnsServerStatistics | Select-Object -ExpandProperty Query2Statistics
ปัญหาที่พบบ่อย
เครื่องลูกค้นหาชื่อภายในไม่เจอ
ตรวจสามจุด หนึ่งเครื่องลูกใช้ DNS ตัวนี้จริงด้วย ipconfig /all สองระเบียนมีอยู่จริงด้วย Get-DnsServerResourceRecord สามพอร์ต 53 เปิดทั้ง TCP และ UDP ด้วย Test-NetConnection 10.0.0.10 -Port 53
ค้นหาชื่อภายในได้แต่ออกอินเทอร์เน็ตไม่ได้
Forwarder ไม่ทำงาน ตรวจด้วย Get-DnsServerForwarder และทดสอบว่าเซิร์ฟเวอร์เข้าถึง Forwarder ได้ด้วย Test-NetConnection 1.1.1.1 -Port 53
ระเบียนชี้ไป IP เก่าของเครื่องที่เปลี่ยนแล้ว
แคชฝั่งเซิร์ฟเวอร์หรือฝั่งลูกยังค้าง ล้างด้วย Clear-DnsServerCache บนเซิร์ฟเวอร์ และ ipconfig /flushdns บนเครื่องลูก หากเกิดบ่อยให้เปิด Scavenging ตามขั้นตอนที่ 6
มีระเบียนซ้ำของเครื่องเดียวกันหลาย IP
เกิดจากเครื่องที่มีการ์ดเครือข่ายหลายใบลงทะเบียนทุกใบ ปิดการลงทะเบียนของการ์ดที่ไม่ต้องการที่ฝั่งเครื่องลูก ในการตั้งค่า IPv4 ขั้นสูง แท็บ DNS
ต้องการวางระบบ DNS ภายในองค์กรให้มั่นคง ติดต่อ THAI DATA CLOUD ได้ที่ https://thaidata.cloud/contact/
- Categories:
- Cloud
- Tags:
- Cloud
- Cloud Server
หมวดหมู่ที่น่าสนใจ
- Account Settings
- AD Server
- AI
- Alibaba Cloud
- Anti-Spam Gateway
- AWS Amazon Web Services
- Campaign
- CentOS/AlmaLinux
- Cloud
- Cloud Backup
- Cloud Communication
- Cloud Migration
- Cloud Security
- Cloud Server Management
- Cloud Solution
- Cloud Solution for Government
- Cloud Solutions by Industry
- Cloud Storage
- Cloud VPS App Plus +
- Cloud VPS DirectAdmin
- Cloud VPS Plesk
- CSR
- Cyber Security
- Cybersecurity
- Data Sovereignty
- Database Server
- DDoS
- Digital Tranformation
- Digital Transformation
- Direct Mail
- Directadmin
- Domainname
- Ecommerce
- ERP
- Generative AI
- Getting Started
- Google Cloud
- Google G Suite
- Huawei Cloud
- IT News
- Linux Server
- Managed Cloud Services
- Managed Service Provider
- Manual
- Microsoft
- Microsoft 365
- Microsoft Azure
- News
- On-premise
- Private Mail Server
- Promotion
- Recommend Solution (Enterprise)
- Server
- Sovereign Cloud
- THAI DATA CLOUD Platform
- Ubuntu
- Ubuntu
- Uncategorized
- VMware
- VPS Server
- Web Design
- Web Hosting
- Web Hosting (DirectAdmin)
- Web Hosting (Plesk)
- Web Technologies
- Windows Server
- Wordpress
- Zimbra
- เรื่องราวความประทับใจ
- โซลูชันสำหรับธุรกิจการผลิตและยานยนต์
- โซลูชันสำหรับธุรกิจการศึกษา
- โซลูชันสำหรับธุรกิจการเงิน
- โซลูชันสำหรับธุรกิจขนส่งและกระจายสินค้า
- โซลูชันสำหรับธุรกิจค้าปลีก
- โซลูชันสำหรับธุรกิจท่องเที่ยว
- โซลูชันสำหรับธุรกิจบริการสุขภาพและโรงพยาบาล
- โซลูชันสำหรับธุรกิจประกันภัย
- โซลูชันสำหรับธุรกิจพลังงานและสาธารณูปโภค
- โซลูชันสำหรับธุรกิจสื่อสารมวลชนและเอ็นเตอร์เทนเมนท์
- โซลูชันสำหรับธุรกิจอสังหาริมทรัพย์
- โซลูชันสำหรับธุรกิจเทคโนโลยี








