How to set up DHCP Dynamic DNS on Ubuntu
In the video below, we show you how to configure Dynamic DNS (DDNS) in Linux using Ubuntu 20.04 LTS with Bind9 and ISC DHCP
We’ll create a key for our DHCP server to authenticate with, configure the DNS server to accept DDNS updates from the DHCP server and the DHCP server to send DDNS updates to the DNS server
Configuration example:
-
Create Key File
Create a key file to keep the password separate from the main file
On the DNS server, switch to the bind folderThen create our key by running the following commandcd /etc/bind
Copy the key example and modify to suit, e.g.ddns-confgen -k dhcp1.templab.lan
I used the FQDN of the DHCP server to name this key, but it’s up to yourself as to what reference you want to usekey "dhcp1.templab.lan" { algorithm hmac-sha256; secret "/mAXOLTQUp8V9XzYnw88dkOkiDXBU6SNv/jEL3IgKVE="; };
Create a key file, paste the contents in and save this file
Change the ownership if necessarysudo nano dhcp1.key
sudo chown root:bind dhcp1.key
-
Move Zone Files
The bind server needs to create new files and modify the zone files when updates are received
For this reason, any zones requiring dynamic updates need to be moved to /var/lib/bind/
sudo mv db.templab.lan /var/lib/bind/ sudo mv db.172.16 /var/lib/bind/
-
Update DNS Configuration
The DNS server configuration needs to be updated as the zone files have been moved
It needs to know where to find the key, where to find the zone files we’ve moved and be configured to allow updates from the DHCP server
First, make a backup copy of the fileAnd then apply our changessudo cp named.conf.local named.conf.local.old sudo nano named.conf.local
The update policies above allows a computer with the key to change host records of any name in the forward lookup zone, but only if these are type A or DHCID recordsinclude "/etc/bind/dhcp1.key"; zone "templab.lan" { type master; file "/var/lib/bind/db.templab.lan"; update-policy { grant dhcp1.templab.lan wildcard *.templab.lan A DHCID; }; }; zone "17.16.172.in-addr.arpa" { type master; file "/var/lib/bind/db.172.16"; update-policy { grant dhcp1.templab.lan wildcard *.16.172.in-addr.arpa PTR; }; };
This is possible because we used the wildcard option
It can also update the reverse lookup zone, but only if these are PTR records
Check the DNS server configuration syntaxThen restart and check the bind9 statussudo named-checkconf
sudo systemctl restart bind9 sudo systemctl status bind9
-
Update DHCP Configuration
The DHCP server needs to know the key so we’ll create a new file and copy the key we created on the DNS server
It also needs updating to support DDNS, to tell it where to find the key, to enable DDNS using the standard style and also which zones to update, what the primary DNS server is and what key to usecd /etc/dhcp mkdir ddns-keys sudo nano ddns-keys/dhcp1.key
First, make a backup copy of the fileAnd then apply our changessudo cp dhcpd.conf dhcpd.conf.old sudo nano dhcpd.conf
After saving the changes, restart and check the DHCP server statusinclude "/etc/dhcp/ddns-keys/dhcp1.key"; ddns-updates on; ddns-update-style standard; zone templab.lan. { primary 172.16.17.10; key dhcp1.templab.lan; } zone 16.172.in-addr.arpa. { primary 172.16.17.10; key dhcp1.templab.lan; }
DNS should now be updated when IP addresses are leased or releasedsudo systemctl restart isc-dhcp-server sudo systemctl status isc-dhcp-server
-
Maintenance
Pause DDNS before making static DNS changesApply your changes, increment the serial number then resumesudo rndc freeze
sudo rndc thaw
-
Troubleshooting
If host entries aren’t being updated monitor syslog on both serverssudo tail -f /var/log/syslog
Sharing is caring!