Skip to content

Nuface Blog

隨意隨手記 Casual Notes

Menu
  • Home
  • About
  • Services
  • Blog
  • Contact
  • Privacy Policy
  • Login
Menu

從零開始設定 DNSSEC:打造安全的 DNS Zone

Posted on 2025-11-052025-11-05 by Rico

在 DNS 架構中,DNSSEC (DNS Security Extensions) 能有效防止 DNS 資料被偽造或竄改。
本文將一步步帶你完成一個新的 DNS 區域設定,並加入 DNSSEC 簽章,建立安全可信的名稱解析環境。


一、什麼是 DNSSEC?

DNSSEC 透過「公開金鑰簽章」來保護 DNS 資料完整性。
簡單來說,它會讓查詢者能驗證 DNS 回應是否真的來自授權的 DNS 伺服器,而不是中途被竄改。

主要機制包含:

  • ZSK (Zone Signing Key):簽署區域內的記錄(A、MX、TXT…)。
  • KSK (Key Signing Key):簽署 ZSK 的公開金鑰。
  • DS (Delegation Signer):KSK 的摘要,提交到上層域名(例如 .tw 或 .com),形成信任鏈。

二、建立新區域前的準備

  1. 確認你已擁有該域名(例如 example.com)。
  2. 確定網域註冊商支援 DNSSEC,並允許上傳 DS 記錄。
  3. 確認 BIND 伺服器運作正常(本文以 BIND 為範例)。

三、建立新的 Zone 檔案

建立 /etc/bind/db.example.com,內容如下:

$TTL 86400
@   IN  SOA ns1.example.com. hostmaster.example.com. (
        2025110501 ; Serial (YYYYMMDDnn)
        3600       ; Refresh
        900        ; Retry
        1209600    ; Expire
        86400 )    ; Minimum

    IN  NS  ns1.example.com.
    IN  NS  ns2.example.com.

ns1 IN  A   203.0.113.1
ns2 IN  A   203.0.113.2
@   IN  A   203.0.113.10
www IN  A   203.0.113.20

四、在 BIND 設定中加入 Zone

編輯 /etc/bind/named.conf.local:

zone "example.com" {
    type master;
    file "/etc/bind/db.example.com";
    auto-dnssec maintain;
    inline-signing yes;
};

auto-dnssec maintain 與 inline-signing yes 會讓 BIND 自動處理簽章與金鑰輪換。


五、產生 DNSSEC 金鑰

在金鑰目錄(例如 /etc/bind/keys/)中執行:

cd /etc/bind/keys

# 產生 ZSK (Zone Signing Key)
dnssec-keygen -a RSASHA256 -b 2048 -n ZONE example.com

# 產生 KSK (Key Signing Key)
dnssec-keygen -f KSK -a RSASHA256 -b 4096 -n ZONE example.com

系統會產生四個檔案:

Kexample.com.+008+12345.key
Kexample.com.+008+12345.private
Kexample.com.+008+67890.key
Kexample.com.+008+67890.private

六、簽署 Zone

重新載入 BIND 讓它執行自動簽章:

rndc reload example.com

簽名完成後,可在 /var/cache/bind/ 看到自動生成的:

db.example.com.signed

這就是已簽章的 zone。


七、產生 DS 記錄並提交給上層域名

從 KSK 金鑰 產生 DS 記錄:

dnssec-dsfromkey Kexample.com.+008+67890.key

輸出類似:

example.com. IN DS 67890 8 2 1234567890ABCDEF...

將這段 DS 提交給你的註冊商(parent zone),完成信任鏈的建立。


八、驗證 DNSSEC 是否成功

當上層完成 DS 記錄設定後,使用以下指令驗證:

dig @8.8.8.8 example.com +dnssec

若結果中包含 RRSIG 並出現 ad(authenticated data)旗標,代表驗證成功。

或使用更詳細的驗證工具:

delv example.com

九、常見錯誤與排查

問題情況可能原因
沒有出現 RRSIG尚未簽章或 zone 尚未 reload
DS 錯誤上層註冊商 DS 值與實際不符
驗證失敗KSK/ZSK 未更新或鏈條中斷
只簽 zone 無 DS本地可用,但外部無法驗證信任鏈

🔚 結語

DNSSEC 能顯著提升網域的安全性,但部署過程需要嚴謹操作。
若只是內部測試或私有網域,可省略 DS 步驟。
但若是公開網域,務必完成整個信任鏈的設定,確保 DNS 查詢具備完整的來源驗證。


Recent Posts

  • Postfix + Let’s Encrypt + BIND9 + DANE Fully Automated TLSA Update Guide
  • Postfix + Let’s Encrypt + BIND9 + DANE TLSA 指紋自動更新完整教學
  • Deploying DANE in Postfix
  • 如何在 Postfix 中部署 DANE
  • DANE: DNSSEC-Based TLS Protection

Recent Comments

  1. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on High Availability Architecture, Failover, GeoDNS, Monitoring, and Email Abuse Automation (SOAR)
  2. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on MariaDB + PostfixAdmin: The Core of Virtual Domain & Mailbox Management
  3. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on Daily Operations, Monitoring, and Performance Tuning for an Enterprise Mail System
  4. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on Final Chapter: Complete Troubleshooting Guide & Frequently Asked Questions (FAQ)
  5. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on Network Architecture, DNS Configuration, TLS Design, and Postfix/Dovecot SNI Explained

Archives

  • December 2025
  • November 2025
  • October 2025

Categories

  • AI
  • Apache
  • Cybersecurity
  • Database
  • DNS
  • Docker
  • Fail2Ban
  • FileSystem
  • Firewall
  • Linux
  • LLM
  • Mail
  • N8N
  • OpenLdap
  • OPNsense
  • PHP
  • QoS
  • Samba
  • Switch
  • Virtualization
  • VPN
  • WordPress
© 2025 Nuface Blog | Powered by Superbs Personal Blog theme