熱門分類
 載入中…
目錄

Linux DNS Bind 主從同步設定教學(Master & Slave Configuration)

    🌐 Linux DNS Bind Master & Slave 同步設定教學

    本篇說明如何使用 Bind (named) 在 Linux 系統上建立 主從式 DNS 架構(Master / Slave), 讓兩部 DNS 伺服器可自動同步 Zone File,確保網域資料一致性與備援能力。


    🧩 環境設定

    項目 設定值
    Master DNS 192.168.100.120
    Slave DNS 192.168.100.130
    Domain Name example.corp

    目的:讓 Master 與 Slave DNS 自動同步 Zone File,避免手動維護。


    📦 1️⃣ 安裝與備份設定檔

    # 兩台主機皆執行
    yum install bind bind-utils bind-libs -y
    
    # 備份設定檔
    cp /etc/named.conf /etc/named.conf.old
      

    開放防火牆的 DNS 連線埠:

    iptables -A INPUT -p udp --dport 53 -j ACCEPT
    service iptables save
      

    🧭 2️⃣ Master 伺服器設定(192.168.100.120)

    編輯 /etc/named.conf

    vi /etc/named.conf
    
    options {
        listen-on port 53 { any; };
        directory "/var/named";
        allow-query { any; };
        recursion yes;
        forwarders {
            168.95.1.1;     // 中華電信 DNS
            139.175.10.20;  // Seednet DNS
        };
        empty-zones-enable no;  // 避免 RFC1918 錯誤訊息
    };
    
    zone "example.corp" IN {
        type master;
        file "named.master.example.corp";
        allow-transfer { 192.168.100.130; };   // 允許 Slave 進行 zone transfer
    };
      

    建立 Zone File:

    vi /var/named/named.master.example.corp
    
    $TTL 3D
    @   IN  SOA ns.example.corp. admin.example.corp. (
            2014082501 ; Serial
            3H          ; Refresh
            15M         ; Retry
            1W          ; Expire
            1D )        ; Minimum TTL
    
    @           IN  NS  ns.example.corp.
    ns.example.corp.  IN  A   192.168.100.120
    www         IN  A   192.168.100.120
    mx1         IN  A   192.168.100.120
    mx2         IN  A   192.168.100.120
    @           IN  MX  10 mx1.example.corp.
    @           IN  MX  20 mx2.example.corp.
      

    檢查設定語法:

    named-checkconf
    named-checkzone example.corp /var/named/named.master.example.corp
    systemctl restart named
    systemctl enable named
      

    📡 3️⃣ Slave 伺服器設定(192.168.100.130)

    編輯 /etc/named.conf

    vi /etc/named.conf
    
    options {
        listen-on port 53 { any; };
        directory "/var/named";
        allow-query { any; };
        recursion yes;
        forwarders {
            168.95.1.1;
            139.175.10.20;
        };
        empty-zones-enable no;
    };
    
    zone "example.corp" IN {
        type slave;
        file "slaves/named.slave.example.corp";
        masters { 192.168.100.120; };   // Master DNS IP
    };
      

    啟動服務後,Slave 會自動從 Master 複製 Zone File:

    systemctl restart named
    ls -l /var/named/slaves/
      

    應可看到檔案 named.slave.example.corp 已自動生成。


    🧰 4️⃣ 驗證同步結果

    • 在 Slave 查詢主機紀錄:
    • dig @192.168.100.130 www.example.corp
          
    • 確認 Master 傳送紀錄:
    • tail -f /var/log/messages | grep named
          

    若同步正常,Slave 會自動更新 SOA Serial 號碼。


    ⚠️ 5️⃣ 常見錯誤:empty-zones-enable 警告

    錯誤訊息:

    Warning: 'empty-zones-enable/disable-empty-zone' not set: disabling RFC 1918 empty zones
      

    ✅ 解法:在 options 區塊內加入以下設定:

    options {
        empty-zones-enable no;
    };
      

    然後重新啟動 named 服務:

    systemctl restart named
      

    此警告將不再出現。


    📘 總結

    • Master 管理正式 Zone File。
    • Slave 透過 zone transfer 自動同步。
    • 設定 allow-transfermasters 是同步關鍵。
    • 若 Zone File 更新,Slave 會自動抓取新版本。

    📚 參考資料

    — WWFandy・Linux 網路服務筆記

    🔗 分享這篇 LINE Facebook X

    沒有留言:

    張貼留言

    字級