Log inSign up

Serve your domain from your own BIND 9 name servers

Install bind9, switch recursion off in named.conf.options, declare the zone as type primary with dnssec-policy default, and write the zone file under /var/lib/bind. A second VPS in another city pulls a copy as type secondary over a TSIG key. Register ns1 and ns2 with glue at your registrar, publish the DS record, and dig +norec against either server returns answers with the aa flag.

Topic: VPN and private DNS · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13 · Updated 2026-12-03

How does an authoritative server differ from a resolver?

An authoritative server answers only for the zones it hosts, and those answers are meant for the whole internet. A resolver such as Unbound does the opposite: it looks up any name for a few trusted clients. The two roles should not share one daemon. Here BIND is purely authoritative, with recursion switched off so it cannot be abused as an open resolver even though port 53 is public.

The domain example.net gets two name servers: ns1.example.net on 198.51.100.24 and 2001:db8:4f2a::24 (the primary), and ns2.example.net on 203.0.113.53 (the secondary). Putting the second server on a VPS in a different city from our list of locations keeps the domain reachable if one machine is down for maintenance.

How do you install BIND on both servers?

Run the same commands on the primary and the secondary. Ubuntu 24.04 and 22.04 ship BIND 9.18; Debian 13 carries 9.20 and Debian 12 carries 9.18. The syntax below works on both branches.

sudo apt update
sudo apt install -y bind9 bind9-utils bind9-dnsutils
named -v
apt policy bind9
systemctl status named --no-pager

The service unit is named. Configuration sits in /etc/bind; zone files that BIND must write to, such as signed zones, belong in /var/lib/bind, which the packaged AppArmor profile allows.

Which global options make it authoritative only?

Replace the contents of /etc/bind/named.conf.options on both servers with:

options {
    directory "/var/cache/bind";
    listen-on { any; };
    listen-on-v6 { any; };

    recursion no;
    allow-recursion { none; };
    allow-query-cache { none; };
    allow-query { any; };
    allow-transfer { none; };

    version "not disclosed";
    minimal-responses yes;

    rate-limit {
        responses-per-second 10;
        window 5;
    };
};

Recursion is off and transfers are denied by default; each zone opens transfers only to the key that needs them. Response rate limiting caps identical answers per client network, which blunts reflection attacks that would otherwise use your public server.

How do you create the TSIG key for zone transfers?

A shared HMAC key signs every transfer and notify between the two servers, so a third party cannot pull the zone. Generate it on the primary:

sudo tsig-keygen -a hmac-sha256 xfer-key | sudo tee /etc/bind/xfer-key.conf
sudo chown root:bind /etc/bind/xfer-key.conf
sudo chmod 640 /etc/bind/xfer-key.conf

Copy the file to the same path on the secondary over SSH (for example with scp to your user, then sudo mv), and apply the same owner and mode there. The file holds a key block with the algorithm and the secret.

How do you write the primary zone?

Declare the zone in /etc/bind/named.conf.local on the primary:

include "/etc/bind/xfer-key.conf";

zone "example.net" {
    type primary;
    file "/var/lib/bind/db.example.net";
    dnssec-policy default;
    inline-signing yes;
    allow-transfer { key xfer-key; };
    notify yes;
};

Then create /var/lib/bind/db.example.net:

$TTL 3600
@       IN SOA  ns1.example.net. hostmaster.example.net. (
                2026120301 ; serial
                7200       ; refresh
                3600       ; retry
                1209600    ; expire
                3600 )     ; negative cache
        IN NS   ns1.example.net.
        IN NS   ns2.example.net.
ns1     IN A    198.51.100.24
ns1     IN AAAA 2001:db8:4f2a::24
ns2     IN A    203.0.113.53
@       IN A    198.51.100.24
@       IN AAAA 2001:db8:4f2a::24
www     IN CNAME example.net.
app     IN A    198.51.100.24
@       IN TXT  "v=spf1 -all"

Fix ownership with sudo chown bind:bind /var/lib/bind/db.example.net. The -all SPF record tells receivers this domain sends no mail; change it when you set up mail. dnssec-policy default creates a signing key, signs the zone and keeps signatures fresh with no cron job.

How do you set up the secondary server?

On ns2, add to /etc/bind/named.conf.local:

include "/etc/bind/xfer-key.conf";

zone "example.net" {
    type secondary;
    primaries { 198.51.100.24 key xfer-key; };
    file "/var/cache/bind/db.example.net";
};

The secondary stores its copy, already signed, in the cache directory. It refreshes on every notify from the primary and on the refresh timer from the SOA record. Use the same global options file as on the primary, so recursion is off on both.

How do you check, load and open the firewall?

Validate before every reload on each server:

sudo named-checkconf
sudo named-checkzone example.net /var/lib/bind/db.example.net
sudo systemctl restart named
sudo rndc status

An authoritative server must accept queries from everyone, over UDP and TCP (large DNSSEC answers and transfers use TCP):

sudo ufw allow 53/udp
sudo ufw allow 53/tcp
sudo ufw status

This is the one DNS role where public port 53 is correct, and only because recursion is disabled. On the secondary, the transfer itself is an outgoing connection, so nothing extra is needed. Read the ufw guide for the default-deny baseline.

How do you delegate the domain and publish DNSSEC?

At your registrar, create host (glue) records ns1.example.net and ns2.example.net with their IP addresses, then set those two names as the domain name servers. Glue is needed because the name servers live inside the zone they serve.

Once BIND has signed the zone, build the DS record from the published key:

sudo rndc dnssec -status example.net
dig @127.0.0.1 example.net DNSKEY | dnssec-dsfromkey -f - example.net

Enter the DS line (key tag, algorithm 13, digest type 2 and the digest) in the DNSSEC section at the registrar. When the parent zone shows it, tell BIND:

sudo rndc dnssec -checkds published example.net

Do not publish the DS until both servers serve signed answers, or validating resolvers will treat the domain as broken.

How do you verify answers and edit records later?

Query each server directly without recursion and look for the aa flag, which marks an authoritative answer:

dig @198.51.100.24 example.net SOA +norec
dig @203.0.113.53 example.net SOA +norec
dig @198.51.100.24 example.org A +norec
dig +trace www.example.net
delv @9.9.9.9 www.example.net

Both SOA serials must match. The query for a foreign name returns REFUSED, proving there is no open recursion, and delv reports a fully validated answer once the DS is in place. To change records, edit the unsigned file, raise the serial, and reload just that zone:

sudo named-checkzone example.net /var/lib/bind/db.example.net
sudo rndc reload example.net
sudo journalctl -u named -n 30 --no-pager

If the secondary keeps an old serial, the log usually shows a TSIG mismatch or a clock difference; keep time sync active on both. The dig guide explains trace output.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A1-1one small plan per name server1 vCPU, 1 GB RAM, 25 GB NVMe$3.60/mo$43.20 for 12 months
S1-2a second server in another city1 vCPU, 2 GB RAM, 55 GB SSD$6.00/mo$72.00 for 12 months

Questions about Authoritative DNS with BIND 9

Do I really need two name servers?

Registrars require at least two, and a second server in another city keeps the domain resolving during maintenance or an outage of the first. Two small plans are enough.

Can I keep simple records at my registrar instead?

Yes, and for a few A and AAAA records that is simpler. The DNS records tutorial covers that route; self-hosting pays off when you want full control, DNSSEC policy or many zones.

How do I set reverse DNS (PTR) for my server address?

Reverse zones for our addresses are not delegated to customers and there is no console setting. Open a support ticket with the address and the host name you want.

Should BIND also resolve names for my server?

Keep the roles apart. Let the system use its normal resolver, or run Unbound on loopback, and keep BIND authoritative only.

What happens to signatures if the server is off for days?

Default policy signatures last about two weeks and are refreshed well before expiry, so short downtime is harmless. The secondary keeps serving the last signed copy until the expire timer in the SOA runs out.

Can I use BIND for dynamic updates from scripts?

Yes, with update-policy and a separate TSIG key, then nsupdate from the client. That is how many ACME DNS challenge setups work.