设置 nsd DNS 服务器

来自 Alpine Linux

NSD 是一个仅权威 DNS 服务器。以下页面展示了如何设置单区域配置,其中一台服务器作为主服务器进行更新,而从服务器将自动复制更改。在示例中,10.1.0.1 用作主服务器的 IP 地址,10.2.0.1 是从服务器地址。此处使用的 IP 地址(以及域名)应替换为您服务器的 IP 地址。

安装

安装很简单(在两台服务器上执行此步骤)

apk add nsd

配置

首先,在主服务器上设置主配置文件 /etc/nsd/nsd.conf,并将 secret 替换为正确的 secret。

server:
        ip-address: 10.1.0.1
        port: 53
        server-count: 1
        ip4-only: yes
        hide-version: yes
        identity: ""
        zonesdir: "/etc/nsd"
key:
        name: "sec_key"
        algorithm: hmac-md5
        secret: "WhateverSecretYouUse"
zone:
        name: alpinelinux.org
        zonefile: alpinelinux.org.zone
        notify: 10.2.0.1 sec_key
        provide-xfr: 10.2.0.1 sec_key

接下来,为相关区域创建区域文件(在本例中为 /etc/nsd/alpinelinux.org.zone)。

;## alpinelinux.org authoritative zone

$ORIGIN alpinelinux.org.
$TTL 86400

@ IN SOA ns1.alpinelinux.org. webmaster.alpinelinux.org. (
                2011100501      ; serial
                28800           ; refresh
                7200            ; retry
                86400           ; expire
                86400           ; min TTL
                )

                NS              ns1.alpinelinux.org.
                MX      10      mail.alpinelinux.org.
lists           MX      10      mail.alpinelinux.org.
@               IN      A       81.175.82.11
mail            IN      A       64.56.207.219
www             IN      A       81.175.82.11
www-prd         IN      A       74.117.189.132
www-qa          IN      A       74.117.189.131
wiki            IN      A       74.117.189.132
lists           IN      A       64.56.207.219
monitor         IN      A       213.234.126.133
bugs            IN      A       81.175.82.11
nl              IN      A       81.175.82.11
dl-2            IN      A       208.74.141.33
dl-3            IN      A       74.117.189.132
dl-4            IN      A       64.56.207.216
rsync           IN      A       81.175.82.11
distfiles       IN      A       91.220.88.29
build-edge      IN      A       91.220.88.23
build64-edge    IN      A       204.152.221.26
build-2-2       IN      A       91.220.88.34
build64-2-2     IN      A       91.220.88.35
build-2-1       IN      A       91.220.88.32
build-2-0       IN      A       91.220.88.31
build-1-10      IN      A       91.220.88.26

在从服务器上,设置 /etc/nsd/nsd.conf。

server:
        ip-address: 10.2.0.1
        port: 53
        server-count: 1
        ip4-only: yes
        hide-version: yes
        identity: ""
        zonesdir: "/etc/nsd"
key:
       name: "sec_key"
        algorithm: hmac-md5
        secret: "WhateverSecretYouUse"
zone:
        name: alpinelinux.org
        zonefile: alpinelinux.org.zone
        allow-notify: 10.1.0.1 sec_key
        request-xfr: AXFR 10.1.0.1 sec_key

同样在从服务器上,创建区域文件 /etc/nsd/alpinelinux.org.zone。

启动服务器

第一步,确保您的配置中没有任何拼写错误(在两台服务器上)。

nsd-checkconf /etc/nsd/nsd.conf

然后,每次对区域进行更改时(包括首次启动服务器时),都需要重建 NSD 区域数据库。

nsdc rebuild

最后,启动服务器并设置为自动启动。

rc-service nsd start rc-update add nsd

提示: 您现在有了一组 DNS 服务器,它们都将使用给定区域的权威数据进行响应,并且每当对主服务器进行更新时,都会使用区域传输将其复制到从服务器。