The domain name system (DNS) resolves hostnames (e.g. www.example.net
) to IP addresses.
BIND is the most used DNS server on the internet.
This tutorial shows how to configure a subdomain in BIND 9 on Debian 10 (buster).
The official Debian repository includes BIND 9:
apt install bind9
To run a name server for a subdomain sub.example.net
,
the following records are relevant in the zone of the domain example.net
:
sub IN NS ns1.sub.example.net. ; name server for subdomain sub.example.net
ns1.sub IN A 192.0.2.1 ; IPv4 address of ns1.sub.example.net
ns1.sub IN AAAA 2001:db8:10::1 ; IPv6 address of ns1.sub.example.net
The DNS server ns1.sub.example.net
needs to accept incoming packages
on the following ports:
The zone file for sub.example.net
needs to be specified in the configuration file:
/etc/bind/named.conf.local
zone "sub.example.net" {
type master;
file "/var/lib/bind/db.sub.example.net";
};
The zone file defines records for a (sub)domain.
Here is an exemplary zone file for the subdomain sub.example.net
:
/var/lib/bind/db.sub.example.net
$TTL 86400
@ IN SOA ns1.sub.example.net. root.example.net. (
2020042301 ; Serial (YYYYMMDDxx)
3600 ; Refresh (1 hour)
600 ; Retry (10 mins)
604800 ; Expire (7 days)
1800 ) ; Negative Cache TTL (30 mins)
@ IN NS ns1.sub.example.net.
ns1 IN A 192.0.2.1
ns1 IN AAAA 2001:db8:10::1
; other hostnames
somehost IN A 192.0.2.10
another IN A 192.0.2.11
The content of the exemplary zone file means the following:
@
" is an alias for the zone itself (sub.example.net
).ns1.sub.example.net
for the subdomain sub.example.net
isThe following command reloads the configuration:
rndc reload
Install the dnsutils
package:
apt install dnsutils
Verify that the DNS lookup returns the correct IP address:
nslookup somehost.sub.example.net
Updating the DNS records is useful when IP addresses are dynamically assigned.
For instance, DHCP servers automatically assign IP addresses to hosts.
The following command generates a random rndc key and
prints a configuration example to the terminal:
rndc-confgen
To allow a client to update the DNS records of sub.example.net
with an rndc key,
enable it in the configuration file:
/etc/bind/named.conf.local
include "/etc/bind/rndc.key";
zone "sub.example.net" {
type master;
file "/var/lib/bind/db.sub.example.net";
allow-update { key "rndc-key"; };
};
For updating DNS records, the following command line tool is used:
nsupdate
These commands update the IPv4 address of somehost.sub.example.net
:
key rndc-key C3...DQ==
update delete somehost.sub.example.net A
update add somehost.sub.example.net 86400 A 192.0.2.123
send