Skip to content

Linux Exercise 9 - DNS Replication

🧪 Exercise: Setting Up DNS Replication with a Secondary DNS Server

Section titled “🧪 Exercise: Setting Up DNS Replication with a Secondary DNS Server”

In the previous lab, you configured a primary DNS server using BIND 9 to provide name resolution in your internal network.

But what happens if your DNS server goes down?
Without DNS, clients can’t reach services by name, even if the services themselves are still running.

DNS replication solves this by introducing a secondary (slave) DNS server. The secondary automatically synchronizes zone data from the primary. If the primary fails, the secondary can continue answering queries — ensuring name resolution still works.

By the end of this exercise, you will:

  • Understand the role of a secondary DNS server
  • Configure zone transfers between primary and secondary servers
  • Test DNS failover scenarios
  • Secure the replication with DNSSEC
  • Understand how DHCP configuration fits into this setup

  • Primary (master) DNS server:

    • Holds the original zone files.
    • Is authoritative for the zone.
    • Allows zone transfers to secondaries.
  • Secondary (slave) DNS server:

    • Doesn’t have editable zone files.
    • Periodically or on notification copies the zone data from the primary.
    • Answers queries just like the primary.

🔸 Important: Secondary servers are read-only. All changes happen on the primary and are replicated.


  • High availability – If the primary goes offline, clients still get DNS responses.
  • Load sharing – Multiple DNS servers can handle more clients.
  • Resilience – Network issues or maintenance on one server won’t break the whole DNS service.

ScenarioWhat happens
Primary online, secondary onlineBoth respond to queries. Typically clients use the primary first.
Primary offline, secondary onlineSecondary continues to serve queries with the last zone data.
Both offlineDNS fails.
Zone updated on primarySecondary gets notified and pulls new zone data.
Secondary can’t reach primary for longSecondary eventually expires the zone data and stops serving it (based on SOA expire timer).

If you have DHCP configured, you can provide multiple DNS server IPs to clients:

Terminal window
option domain-name-servers 192.168.56.10, 192.168.56.11;
  • The first IP (primary) is used first.
  • If it fails, clients automatically fall back to the secondary.

🔐 Note: DHCP does not handle replication itself. It only informs clients which DNS servers to use.
Zone replication happens directly between DNS servers.


You should have:

  • Primary DNS server: 192.168.56.10 (ns1.mynetwork.local)
  • Secondary DNS server: 192.168.56.11 (ns2.mynetwork.local)
Terminal window
sudo apt update
sudo apt install bind9 bind9-utils -y

Enable and start the service:

Terminal window
sudo systemctl enable bind9
sudo systemctl start bind9

4. Configuring the Primary Server for Zone Transfers

Section titled “4. Configuring the Primary Server for Zone Transfers”

4.1. Update zone definitions on the primary:

Section titled “4.1. Update zone definitions on the primary:”
Terminal window
sudo nano /etc/bind/named.conf.local

Modify your existing zones:

zone "mynetwork.local" {
type master;
file "/etc/bind/db.mynetwork.local";
allow-transfer { 192.168.56.11; };
also-notify { 192.168.56.11; };
};
zone "56.168.192.in-addr.arpa" {
type master;
file "/etc/bind/db.192.168.56";
allow-transfer { 192.168.56.11; };
also-notify { 192.168.56.11; };
};
  • allow-transfer → authorizes the secondary server to pull zone data.
  • also-notify → immediately notifies the secondary of changes.

Restart BIND on the primary:

Terminal window
sudo systemctl restart bind9

Check for errors:

Terminal window
sudo named-checkconf

On the secondary server:

Terminal window
sudo nano /etc/bind/named.conf.local

Add:

zone "mynetwork.local" {
type slave;
file "/var/cache/bind/db.mynetwork.local";
masters { 192.168.56.10; };
};
zone "56.168.192.in-addr.arpa" {
type slave;
file "/var/cache/bind/db.192.168.56";
masters { 192.168.56.10; };
};
  • type slave → this server mirrors the zone.
  • file → where it stores the copied zone data.
  • masters → IP of the primary server.

Restart BIND on the secondary:

Terminal window
sudo systemctl restart bind9

Check:

Terminal window
sudo named-checkconf
sudo systemctl status bind9

Terminal window
ls /var/cache/bind/

You should see:

db.mynetwork.local
db.192.168.56

On the client VM, set the secondary as DNS:

Terminal window
dig @192.168.56.11 www.mynetwork.local

Expected: same result as querying the primary.

  • Stop BIND on the primary:
Terminal window
sudo systemctl stop bind9
  • Test again from client:
Terminal window
dig @192.168.56.11 www.mynetwork.local

✅ The secondary should still resolve the names.


By default, zone transfers are not encrypted but can be authenticated with TSIG (Transaction SIGnatures).

Terminal window
cd /etc/bind
sudo dnssec-keygen -a HMAC-SHA256 -b 256 -n HOST zonetransfer-key

Display the key:

Terminal window
cat Kzonetransfer-key.+*.key

Copy the secret part after IN KEY ....


Primary (/etc/bind/named.conf.local):

key "zonetransfer-key" {
algorithm hmac-sha256;
secret "YOUR_KEY_HERE";
};
zone "mynetwork.local" {
type master;
file "/etc/bind/db.mynetwork.local";
allow-transfer { key zonetransfer-key; 192.168.56.11; };
also-notify { 192.168.56.11; };
};
zone "56.168.192.in-addr.arpa" {
type master;
file "/etc/bind/db.192.168.56";
allow-transfer { key zonetransfer-key; 192.168.56.11; };
also-notify { 192.168.56.11; };
};

Secondary (/etc/bind/named.conf.local):

key "zonetransfer-key" {
algorithm hmac-sha256;
secret "YOUR_KEY_HERE";
};
server 192.168.56.10 {
keys { zonetransfer-key; };
};
zone "mynetwork.local" {
type slave;
file "/var/cache/bind/db.mynetwork.local";
masters { 192.168.56.10 key zonetransfer-key; };
};
zone "56.168.192.in-addr.arpa" {
type slave;
file "/var/cache/bind/db.192.168.56";
masters { 192.168.56.10 key zonetransfer-key; };
};

Restart BIND on both:

Terminal window
sudo systemctl restart bind9

Check logs:

Terminal window
sudo journalctl -u bind9

TSIG secures the transfer, not the data itself.
To protect against DNS spoofing, enable DNSSEC signing on the zone.

Before you start setting up your security measures, do a little research and try to answer what DNS spoofing actually is, how this attack is possible without proper protection and why DNSSEC protects you against it.

Terminal window
cd /etc/bind
sudo dnssec-keygen -a RSASHA256 -b 2048 -n ZONE mynetwork.local
sudo dnssec-keygen -f KSK -a RSASHA256 -b 2048 -n ZONE mynetwork.local
Terminal window
sudo dnssec-signzone -A -3 $(head -c 1000 /dev/urandom | sha1sum | cut -b 1-16) -N increment -o mynetwork.local -t /etc/bind/db.mynetwork.local

This produces a signed zone file:

/etc/bind/db.mynetwork.local.signed
Terminal window
sudo nano /etc/bind/named.conf.local
zone "mynetwork.local" {
type master;
file "/etc/bind/db.mynetwork.local.signed";
allow-transfer { key zonetransfer-key; 192.168.56.11; };
also-notify { 192.168.56.11; };
auto-dnssec maintain;
inline-signing yes;
};

Restart BIND:

Terminal window
sudo systemctl restart bind9

DNSSEC data will also be transferred to the secondary.


From the client:

Terminal window
dig @192.168.56.10 www.mynetwork.local +dnssec

Look for the ad (authenticated data) flag in the response.


You have:

  • Set up a secondary DNS server for redundancy.
  • Configured zone transfers and notifications.
  • Integrated with DHCP by adding multiple DNS IPs.
  • Secured zone transfers using TSIG.
  • Enabled DNSSEC to protect against spoofing.

Your network is now much more resilient and secure.