Enable secondary DNS

Updated at:

Set up Alibaba Cloud DNS as a secondary DNS service that synchronizes records from your primary DNS server.

Limitations

  • The secondary DNS feature is available only for the Ultimate Edition of Alibaba Cloud DNS. Purchase now: Public Zone (Subscription).

  • DNSSEC is not supported.

  • Alibaba Cloud DNS acts as the secondary DNS server, and your existing server functions as the primary DNS server.

  • After you enable secondary DNS for a domain, you cannot modify DNS records in the Alibaba Cloud DNS console. All records are synchronized from your primary DNS server.

  • This feature requires an on-premises DNS server or a third-party DNS hosting service. If you use a third-party DNS hosting service, confirm that your provider supports secondary DNS.

  • For on-premises DNS servers, Alibaba Cloud DNS requires BIND 9.1.0 or later with RFC-compliant AXFR/IXFR and NOTIFY support.

Prerequisites

Configure your primary DNS server first, then set up secondary DNS in the Alibaba Cloud DNS console. The following example uses an on-premises BIND 9.9.4+ server.

1. Generate a TSIG key

Use dnssec-keygen to generate a Transaction Signature (TSIG) key:

dnssec-keygen -a HMAC-SHA256 -b 128 -n HOST test_key

If key generation is slow, add -r /dev/urandom to use a faster random source:

dnssec-keygen -a HMAC-SHA256 -b 128 -n HOST -r /dev/urandom test_key

Parameter description

• -a: Encryption algorithm. Supported: HMAC-MD5, HMAC-SHA1, HMAC-SHA256.

• -b: Key size in bits. HMAC keys: 1–512 bits.

• -n: Key owner type. Valid values: ZONE, HOST, ENTITY, USER. Typically HOST or ZONE.

• test_key: Key name. Used in the allow-transfer directive and as the TSIG Key Name when adding primary DNS server information.

• -r /dev/urandom: Random number generator.

The command generates .key and .private files in the current directory (for example, Ktest_key.+157+64252.key and Ktest_key.+157+64252.private). The .key file contains the DNS KEY record. Use the secret string from this file as the TSIG Key Value when you add primary DNS server information. The .private file contains algorithm-specific fields.

2. Configure the primary DNS server with BIND

Add the following configuration to your /etc/named.conf file:

zone "yourdomain.com" IN {
type master;
allow-update { 127.0.0.1; };
allow-transfer {key test_key;};
notify explicit;
also-notify {47.92.XX.XX port 53  key test_key;47.92.XX.XXX port 53  key test_key;};
file "path/to/your/zone_file";
};

Configuration description

  • zone: Your domain name.

  • allow-transfer: Authorizes zone transfers to secondary DNS servers that present the specified TSIG key.

    Note: RFC standards recommend TSIG to secure zone transfers. TSIG authenticates DNS messages with a shared secret key and one-way hash. Generate a TSIG key with MD5, SHA-256, or SHA-1 and configure it on both primary and secondary servers.

  • also-notify: IP addresses of the secondary DNS servers to notify on zone updates. Enter the Alibaba Cloud DNS secondary server IPs listed on the secondary DNS configuration page.

Example Alibaba Cloud DNS secondary server IP addresses:
47.92.XX.XX,47.92.XX.XXX
  • test_key: Key file name. Must match the allow-transfer directive and the TSIG Key Name in your primary DNS server configuration.

3. Add the TSIG key to the named.conf file

  • Paste the key directly into named.conf in the following format.

key "test_key" {        algorithm hmac-sha256;       secret "string_from_your_.key_file";};

Example of the named.conf file:

bindkeys-file "/etc/named.root.key";

    managed-keys-directory "/var/named/dynamic";

    pid-file "/run/named/named.pid";
    session-keyfile "/run/named/session.key";
};

logging {
    channel default_debug {
            file "data/named.run";
            severity dynamic;
    };
};

zone "." IN {
    type hint;
    file "named.ca";
};

zone "dns-example.com" IN {
        type master;
        allow-update {127.0.0.1;};
        allow-transfer {key test_key;};
        notify explicit;
        also-notify{
            47.92.14.234 port 53  key test_key;
            47.92.14.51 port 53   key test_key;
        };
        file "dns-example.com.zone";
};

key "test_key" {          algorithm hmac-sha256;        secret "string_from_your_.key_file";};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
  • Use the Include statement.

Add an include statement to named.conf:

include "/etc/named/dns-key";

Example of the named.conf file:

bindkeys-file "/etc/named.root.key";

        managed-keys-directory "/var/named/dynamic";

        pid-file "/run/named/named.pid";
        session-keyfile "/run/named/session.key";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "." IN {
        type hint;
        file "named.ca";
};

zone "dns-example.com" IN {
        type master;
        allow-update {127.0.0.1;};
        allow-transfer {key test_key;};
        notify explicit;
        also-notify{
                47.92.14.234 port 53  key test_key;
                47.92.14.51 port 53   key test_key;
        };
        file "dns-example.com.zone";
};

include "/etc/named/dns-key";
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

The /etc/named/dns-key file format:

key "test_key" {
        algorithm hmac-sha256;
        secret "string_from_your_.key_file";
};

Note: After updating named.conf, restart the named service.

Restart command: systemctl restart named

Procedure

4. Configure secondary DNS

  1. Log on to the Alibaba Cloud DNS - Public Zone.

  2. In the Actions column for your target domain, click 2025-06-23_14-18-07 and select Secondary DNS.

  3. In the Secondary DNS panel, configure the Primary DNS Server, specify the IP addresses of the servers that send NOTIFY messages, and then click OK.

    • Primary DNS Server Information: In the Actions column, click Add to specify your primary DNS server information.

      • Primary DNS Server IP Address: The public IP address of your primary DNS server. This address must be accessible from the public internet.

      • TSIG Key Type: Must match the encryption algorithm on your primary DNS server. Valid values: md5, sha1, sha256.

      • TSIG Key Name: Enter the name of your TSIG key, such as test_key.

      • TSIG Key Value: Paste the secret string from your .key file.

    • Set the IP address of the server that sends NOTIFY messages: In the Actions column, click Add to enter the IP address or IP address range of this server.

      • IP Address or Range: Select IP Address or IP Range.

        • IP Address: Add your primary DNS server's source IP to the allowlist so Alibaba Cloud DNS accepts its NOTIFY messages.

        • IP Range: Enter the starting and ending IP addresses of the range.

    • (Optional) Enable failure notifications to receive an SMS alert if the primary DNS connection fails. Then click OK.

  1. After configuration, go to the Public Zone page. An icon next to a domain name indicates secondary DNS is enabled.

    Click the domain name. On the Settings page, check the primary-secondary link status.

    • Normal: The secondary DNS server can connect to the primary DNS server.

    • Blocked: The secondary DNS server cannot connect to the primary DNS server.

      If the status is Blocked, check the following:

      • Verify that the secondary DNS parameters are correct and the primary DNS server IP is publicly accessible.

      • Ensure the primary DNS server is running.

      • Confirm that the primary DNS server configuration complies with RFC standards. For example, the SOA serial number must be an integer between 1 and 4,294,967,295 (2^32-1). An out-of-range serial number stops record synchronization. Synchronization Errors.

  2. After secondary DNS is enabled and the status is Normal, you can trigger an immediate synchronization, bypassing the NOTIFY protocol. Go to the DNS Settings page and click Manually Trigger Synchronization.

5. Configure domain DNS servers

After enabling secondary DNS, configure the NS records for your domain at your registrar. There are three options:

(1) Use only the primary DNS server

All DNS queries for your domain are resolved by your primary DNS server. The secondary DNS server acts as a real-time data backup.

Example NS record configuration for the root domain:

The NS records point to the primary DNS servers ns1.dns-example.com and ns2.dns-example.com.

$TTL 3600
@        IN SOA   ns1.dns-example.com. admin.dns-example.com. (
                                3           ; serial
                                1D          ; refresh
                                1H          ; retry
                                1W          ; expire
                                3H )        ; minimum
@        IN    NS      ns1.dns-example.com.
@        IN    NS      ns2.dns-example.com.
@        IN    A       33.33.33.33
www      IN    A       55.55.55.55
ns1      IN    A       47.94.166.148
ns2      IN    A       47.94.166.148
@        IN    A       123.123.11.11

Authoritative response from dig dns-example.com NS @ns1.dns-example.com:

; <<>> DiG 9.14.4 <<>> dns-example.com NS @ns1.dns-example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39034
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 3

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: f991c9a26964f844f8aba4835e95866c4bc62c85c594b953 (good)
;; QUESTION SECTION:
;dns-example.com.		IN	NS

;; ANSWER SECTION:
dns-example.com.	3600	IN	NS	ns1.dns-example.com.
dns-example.com.	3600	IN	NS	ns2.dns-example.com.

;; ADDITIONAL SECTION:
ns1.dns-example.com.	3600	IN	A	47.94.166.148
ns2.dns-example.com.	3600	IN	A	47.94.166.148

;; Query time: 10 msec
;; SERVER: 47.94.166.148#53(47.94.166.148)
;; WHEN: Tue Apr 14 17:46:20 GTM +8 2020
;; MSG SIZE  rcvd: 140

Recursive resolution response from dig dns-example.com NS +trace +nodnssec:

; <<>> DiG 9.14.4 <<>> dns-example.com NS +trace +nodnssec
;; global options: +cmd
.                       692     IN      NS      k.root-servers.net.
.                       692     IN      NS      i.root-servers.net.
.                       692     IN      NS      f.root-servers.net.
.                       692     IN      NS      a.root-servers.net.
.                       692     IN      NS      j.root-servers.net.
.                       692     IN      NS      h.root-servers.net.
.                       692     IN      NS      g.root-servers.net.
.                       692     IN      NS      l.root-servers.net.
.                       692     IN      NS      m.root-servers.net.
.                       692     IN      NS      b.root-servers.net.
.                       692     IN      NS      e.root-servers.net.
.                       692     IN      NS      d.root-servers.net.
;; Received 824 bytes from 30.25.7.65#53(30.25.7.65) in 36 ms

com.                    172800  IN      NS      k.gtld-servers.net.
com.                    172800  IN      NS      j.gtld-servers.net.
com.                    172800  IN      NS      c.gtld-servers.net.
com.                    172800  IN      NS      f.gtld-servers.net.
com.                    172800  IN      NS      b.gtld-servers.net.
com.                    172800  IN      NS      e.gtld-servers.net.
com.                    172800  IN      NS      a.gtld-servers.net.
com.                    172800  IN      NS      l.gtld-servers.net.
com.                    172800  IN      NS      m.gtld-servers.net.
com.                    172800  IN      NS      g.gtld-servers.net.
com.                    172800  IN      NS      h.gtld-servers.net.
com.                    172800  IN      NS      i.gtld-servers.net.
;; Received 840 bytes from 202.12.27.33#53(m.root-servers.net) in 92 ms

dns-example.com.        172800  IN      NS      ns1.dns-example.com.
dns-example.com.        172800  IN      NS      ns2.dns-example.com.
;; Received 112 bytes from 192.48.79.30#53(j.gtld-servers.net) in 176 ms

dns-example.com.        3600    IN      NS      ns1.dns-example.com.
dns-example.com.        3600    IN      NS      ns2.dns-example.com.
;; Received 140 bytes from 47.94.166.148#53(ns2.dns-example.com) in 13 ms

(2) Use only the secondary DNS server

All DNS queries are resolved by the secondary DNS server (Alibaba Cloud DNS). This hides your primary DNS server from public queries.

Example NS record configuration for the root domain:

The NS records point to Alibaba Cloud DNS servers vip3.alidns.com and vip4.alidns.com. Zone file configuration example:

$TTL 3600
@       IN  SOA  vip3.alidns.com. admin.dns-example.com. (
                        0           ; serial
                        1D          ; refresh
                        1H          ; retry
                        1W          ; Expire
                        3H )        ; minimum
@       IN  NS      vip3.alidns.com.
@       IN  NS      vip4.alidns.com.
@       IN  A       33.33.33.33
www     IN  A       55.55.55.55
@       IN  A       123.123.11.11

Authoritative response from dig dns-example.com NS @vip3.alidns.com:

; <<>> DiG 9.14.4 <<>> dns-example.com NS @vip3.alidns.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58064
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;dns-example.com.		IN	NS

;; ANSWER SECTION:
dns-example.com.	86400	IN	NS	vip3.alidns.com.

;; Query time: 32 msec
;; SERVER: 140.205.29.115#53(140.205.29.115)
;; WHEN: Tue Apr 14 17:57:58 GTM+8 2020
;; MSG SIZE  rcvd: 73

Recursive resolution response from dig dns-example.com NS +trace +nodnssec:

; <<>> DiG 9.14.4 <<>> dns-example.com NS +trace +nodnssec
;; global options: +cmd
.                       86400   IN      NS      a.root-servers.net.
.                       86400   IN      NS      m.root-servers.net.
.                       86400   IN      NS      d.root-servers.net.
.                       86400   IN      NS      j.root-servers.net.
.                       86400   IN      NS      l.root-servers.net.
.                       86400   IN      NS      c.root-servers.net.
.                       86400   IN      NS      f.root-servers.net.
.                       86400   IN      NS      i.root-servers.net.
.                       86400   IN      NS      h.root-servers.net.
.                       86400   IN      NS      k.root-servers.net.
.                       86400   IN      NS      b.root-servers.net.
.                       86400   IN      NS      g.root-servers.net.
;; Received 824 bytes from 30.25.7.65#53(30.25.7.65) in 12 ms

com.                    172800  IN      NS      h.gtld-servers.net.
com.                    172800  IN      NS      b.gtld-servers.net.
com.                    172800  IN      NS      g.gtld-servers.net.
com.                    172800  IN      NS      d.gtld-servers.net.
com.                    172800  IN      NS      e.gtld-servers.net.
com.                    172800  IN      NS      f.gtld-servers.net.
com.                    172800  IN      NS      j.gtld-servers.net.
com.                    172800  IN      NS      a.gtld-servers.net.
com.                    172800  IN      NS      i.gtld-servers.net.
com.                    172800  IN      NS      c.gtld-servers.net.
com.                    172800  IN      NS      k.gtld-servers.net.
com.                    172800  IN      NS      l.gtld-servers.net.
com.                    172800  IN      NS      m.gtld-servers.net.
;; Received 868 bytes from 192.36.148.17#53(i.root-servers.net) in 77 ms

dns-example.com.        172800  IN      NS      vip3.alidns.com.
dns-example.com.        172800  IN      NS      vip4.alidns.com.
;; Received 553 bytes from 192.31.80.30#53(d.gtld-servers.net) in 174 ms

dns-example.com.        86400   IN      NS      vip3.alidns.com.
;; Received 73 bytes from 106.11.30.116#53(vip4.alidns.com) in 42 ms

(3) Use both primary and secondary DNS servers

Recursive resolvers route queries to one of the authoritative nameserver groups based on performance.

Example NS record configuration for the root domain:

$TTL 3600
@       IN  SOA   ns1.dns-example.com. admin.dns-example.com. (
                    9           ; serial
                    1D          ; refresh
                    1H          ; retry
                    1W          ; expire
                    3H )        ; minimum

@       IN      NS      ns1.dns-example.com.
@       IN      NS      ns2.dns-example.com.
@       IN      NS      vip3.alidns.com.
@       IN      NS      vip4.alidns.com.

@       IN      A       33.33.33.33
www     IN      A       55.55.55.55
ns1     IN      A       47.94.166.148
ns2     IN      A       47.94.166.148
@       IN      A       123.123.11.11

Authoritative response from dig dns-example.com NS @ns1.dns-example.com:

; <<>> DiG 9.14.4 <<>> dns-example.com NS @ns1.dns-example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5667
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 3

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 67409558b3081ebdab460c785e9571ad835b2274539b1ca1 (good)
;; QUESTION SECTION:
;dns-example.com.		IN	NS

;; ANSWER SECTION:
dns-example.com.	3600	IN	NS	ns2.dns-example.com.
dns-example.com.	3600	IN	NS	vip3.alidns.com.
dns-example.com.	3600	IN	NS	ns1.dns-example.com.
dns-example.com.	3600	IN	NS	vip4.alidns.com.

;; ADDITIONAL SECTION:
ns1.dns-example.com.	3600	IN	A	47.94.166.148
ns2.dns-example.com.	3600	IN	A	47.94.166.148

;; Query time: 10 msec
;; SERVER: 47.94.166.148#53(47.94.166.148)
;; WHEN: Tue Apr 14 16:17:49 GTM+8 2020
;; MSG SIZE  rcvd: 185

Recursive resolution response from dig dns-example.com NS +trace +nodnssec:

; <<>> DiG 9.14.4 <<>> dns-example.com NS +trace +nodnssec
;; global options: +cmd
.                   86400    IN    NS    a.root-servers.net.
.                   86400    IN    NS    m.root-servers.net.
.                   86400    IN    NS    d.root-servers.net.
.                   86400    IN    NS    j.root-servers.net.
.                   86400    IN    NS    l.root-servers.net.
.                   86400    IN    NS    e.root-servers.net.
.                   86400    IN    NS    c.root-servers.net.
.                   86400    IN    NS    f.root-servers.net.
.                   86400    IN    NS    i.root-servers.net.
.                   86400    IN    NS    k.root-servers.net.
.                   86400    IN    NS    b.root-servers.net.
.                   86400    IN    NS    g.root-servers.net.
;; Received 824 bytes from 30.25.7.65#53(30.25.7.65) in 7 ms

com.                172800   IN    NS    a.gtld-servers.net.
com.                172800   IN    NS    b.gtld-servers.net.
com.                172800   IN    NS    c.gtld-servers.net.
com.                172800   IN    NS    d.gtld-servers.net.
com.                172800   IN    NS    e.gtld-servers.net.
com.                172800   IN    NS    f.gtld-servers.net.
com.                172800   IN    NS    g.gtld-servers.net.
com.                172800   IN    NS    h.gtld-servers.net.
com.                172800   IN    NS    i.gtld-servers.net.
com.                172800   IN    NS    j.gtld-servers.net.
com.                172800   IN    NS    k.gtld-servers.net.
com.                172800   IN    NS    l.gtld-servers.net.
com.                172800   IN    NS    m.gtld-servers.net.
;; Received 840 bytes from 192.58.128.30#53(j.root-servers.net) in 7 ms

dns-example.com.    172800   IN    NS    ns1.dns-example.com.
dns-example.com.    172800   IN    NS    ns2.dns-example.com.
dns-example.com.    172800   IN    NS    vip3.alidns.com.
dns-example.com.    172800   IN    NS    vip4.alidns.com.
;; Received 621 bytes from 192.31.80.30#53(d.gtld-servers.net) in 173 ms

dns-example.com.    3600     IN    NS    ns2.dns-example.com.
dns-example.com.    3600     IN    NS    vip4.alidns.com.
dns-example.com.    3600     IN    NS    vip3.alidns.com.
dns-example.com.    3600     IN    NS    ns1.dns-example.com.
;; Received 168 bytes from 140.205.1.5#53(vip3.alidns.com) in 29 ms