17 Domain Name System Part 3 – Dynamic DNS
Kyle Wheaton and Jacob Christensen
In Chapter 23, we manually configured our DNS entries with the IP addresses that were statically assigned to our client devices. However, it is uncommon to use static IP assignments, especially in networks with hundreds or even thousands of clients! If we can get our DHCP and ADNS servers to communicate with each other, then IPs can automatically be assigned and our zone files can automatically be populated. This practice is called Dynamic DNS (DDNS).
This lab will expand on the work in Chapter 23 and Chapter 24 to learn how to configure and manage DDNS in a small network environment.
Estimated time for completion: 60 minutes
learning objectives
- Learn how DDNS works on an enterprise network
- Learn how to work with multiple services (DHCP and DNS) on one network
prerequisites
deliverables
- Four (4) screenshots
- BLUE1 (PC1) successfully pinging BLUE2 (PC2) by name
- BLUE2 (PC2) successfully pinging BLUE3 (PC3) by name
- BLUE1 (PC1) successfully performing a DNS query and resolution with the NS1 server via Wireshark monitoring
- Live stream of NS1 reports of the DHCP handshake and zone logs when (BLUE3) PC3 is rebooted
resources
- BIND9 Administrator Reference Manual – https://bind9.readthedocs.io/en/v9.18.16/
- MikroTik RouterOS Documentation – https://help.mikrotik.com/docs/display/ROS/RouterOS
- Archy’s Blog – Dynamic DNS with BIND and ISC-DHCP – https://archyslife.blogspot.com/2018/02/dynamic-dns-with-bind-and-isc-dhcp.html
- Configuring Dynamic DNS with BIND9 – https://doncrawley.com/soundtraining.net/files/configuringdynamicdnswithbind9.pdf
- https://kea.readthedocs.io/en/kea-2.2.0/arm/ddns.html
- https://www.techtutorials.tv/sections/linux/how-to-setup-ddns-using-kea-and-bind/
Contributors and testers
Mathew J. Heath Van Horn, PhD, ERAU-Prescott
Kyle Wheaton, Cybersecurity Student, ERAU-Prescott
Phase I – Building the Network Topology
This lab is an extension of the previous two chapters. If you have not completed them yet, it is recommended that you do so first before continuing. By the end your network should look like the following:
- Preliminary step outside of VirtualBox
- Ensure that the “kea-dhcp-ddns-server” is installed. It most likely is if you have KEA installed, but it will solve a headache later if it is not when you begin to configure your GNS3 lab set up. You can check this by changing the network adapter to NAT and opening up the VM without opening GNS3. List everything in the /etc/kea directory to verify it is there.
> ls -l /etc/kea
> apt install isc-kea-dhcp-ddns-serverOnce installed, shutdown the VM and switch the network adapter back
- Ensure that the “kea-dhcp-ddns-server” is installed. It most likely is if you have KEA installed, but it will solve a headache later if it is not when you begin to configure your GNS3 lab set up. You can check this by changing the network adapter to NAT and opening up the VM without opening GNS3. List everything in the /etc/kea directory to verify it is there.
- Preliminary step inside VirtualBox
- Create/clone a fresh copy of the Linux Server VM with KEA’s DHCP server installed before you open GNS3 if you have the space and computer power to handle both VMs
- Start GNS3
- Save the previous lab as a new project: LAB_11
- Reuse the network that you built in the previous chapter
- Configure the router to act as a DHCP relay for the Blue subnet (Chapter 21, Phase II, Step 1)
- Add a DHCP server to the Red network – Ubuntu server (DHCP1)
NOTE: In reality, both the DHCP and DNS services can operate from the same machine; however, we are splitting them into two separate devices for clarity.
- Add a switch to the Red network – Ethernet switch
- Connect NS1 and DHCP1 to the switch so that they are on the same LAN
- Remove the static IP addresses from Tiny Core Linux clients by commenting out the rules for static IP assignment
> vi /opt/bootlocal.sh
Figure 1a – removing the static IP NOTE: Make sure that each client device keeps its unique hostnames! If there are two computers assigned with the same hostname it will cause issues with the DNS records so to limit future pains in the brain, double check your hostnames.
- Label and organize your network as necessary
Phase II – Modify the DNS Server
This section assumes that all configurations made in the previous chapter have carried over to this one.
- Start NS1 and login
- Generate a new Transaction Signature (TSIG) key to use to communicate with DHCP1
NOTE: Ensure that you have the bind9-utils package installed!
> cd /etc/bind
> tsig-keygen dhcp-dns > dhcp-dns.key
- It should look similar to the Figure # below
- It should look similar to the Figure # below
- Modify the file permissions of dhcp-dns[.]key
- Change the owner and group from root to the bind user.
> sudo chown bind:bind /etc/bind/dhcp-dns.key
- Change the file permissions to give read access for the group
> sudo chmod 640 /etc/bind/dhcp-dns.key
- Change the owner and group from root to the bind user.
- Modify the named[.]conf[.]local file
> sudo vi /etc/bind/named.conf.local
- At the beginning of the file, before the zone declarations, include the RNDC key
include “/etc/bind/dhcp-dns.key”;
- Within each zone declaration (both forward and reverse zones), add the following directive to allow the zones to be updated with a new policy.
NOTE: The correct amount of spaces may not appear in the CLI format, but you can reference the configuration below it. You will notice it starts at character #3 (a.k.a after 2 spaces), and ‘grant’ begins at character #9.
> update-policy {
grant dhcp-dns wildcard *.red.net A DHCID;
};> update-policy {
grant dhcp-dns wildcard *.80.30.89.in-addr.arpa PTR DHCID;
};NOTE: The DHCIDs are required by KEA for both forward (A) and reverse (PTR) records. It allows the server(s) to identify unique clients when updates are made to its records.
- Save and exit the editor
- Verify the configuration settings for any errors
> named-checkconf
- At the beginning of the file, before the zone declarations, include the RNDC key
- Add a new static entry in the red[.]net zone files for DHCP1
- Modify the forward lookup zone file. Don’t forget to increase the serial count for each save.
> vi /var/lib/bind/db.red.net
Figure 4 – Updating static forward DNS entry - Modify the reverse lookup zone file
> vi /var/lib/bind/db.red.net.rev
Figure 5 – Updating static reverse DNS entry
- Modify the forward lookup zone file. Don’t forget to increase the serial count for each save.
- Remove all client static entries in the blue[.]net zone files
- Modify the forward lookup zone file
> vi /var/lib/bind/db.blue.net
Figure 6 – Purging static forward DNS entries for an internal subnet - Modify the reverse lookup zone file
> vi /var/lib/bind/db.blue.net.rev
- Modify the forward lookup zone file
- Restart the DNS server and verify that it is running
> systemctl restart named.service
> systemctl status named.service
NOTE: Errors at this stage are likely due to incorrect permissions on the key file. Ensure that both the owner (bind) and group (bind) can read the file.
- Start and enable Systemd’s time synchronization daemon
> systemctl start systemd-timesyncd.service
> systemctl enable systemd-timesyncd.service
Phase III – Configuring the DHCP Server
The following section outlines the configuration of the DHCP daemon for the network.
- Start DHCP1 and login – Refer to (Chapter 23, Phase III, Step 3)
- Modify the machine’s hostname to dhcp1 and restart the machine from the terminal.
> hostnamectl hostname dhcp1
- Assign a static IP address, default gateway, primary DNS server, and local domain name within its *.yaml file
NOTE: This example uses the following information:
– IP Address: 89.30.80.34/29
– Local Domain: red.net
– Nameservers: 89.30.80.35
– Gateway: 89.30.80.33- Verify that the name server information is correctly pointing towards ns1 (89.30.80.35) and that the current domain is red[.]net
> resolvectl status
- Verify that the name server information is correctly pointing towards ns1 (89.30.80.35) and that the current domain is red[.]net
- Modify the machine’s hostname to dhcp1 and restart the machine from the terminal.
- Having all elements in a network synchronized to the same time is critical. SNTP clients provide this service. Linux uses Systemd’s timesync daemon to provide SNTP packets. Start it and enable (start on boot) the service by typing
> systemctl start systemd-timesyncd.service
> systemctl enable systemd-timesyncd.service
- Transfer the key file from NS1 to the primary user’s home directory in DHCP1 if you cannot copy paste the private key.
NOTE: The default user on my machines is student; be sure to change the following commands as necessary. If you are using one machine for both DHCP and DNS you can skip this part. This section can help those who do not have a bidirectional clipboard enabled.
- Login to the NS1 terminal from the DHCP server
> ssh student@89.30.80.35
NOTE: You should see the hostname change to ns1 when you login successfully.
- Switch to the root user
> sudo su
- Use the Secure Copy (SCP) command to make a copy of dhcp-dns[.]key to the primary user of DHCP1
> scp /etc/bind/dhcp-dns.key student@89.30.80.34:/home/student
- Exit from root
> exit
- Exit the SSH session
> exit
- Verify you see the key in your home directory
> ls -l ~
- Login to the NS1 terminal from the DHCP server
- Modify the permissions for the key file on the DHCP server
- Ensure that the owner and group are both root
> chown root:root ~/dhcp-dns.key
- Change the permissions to remove read access from others
> chmod 640 ~/dhcp-dns.key
- Move the file to the DHCP configuration directory
> mv ~/dhcp-dns.key /etc/kea
- Ensure that the owner and group are both root
- Modify the KEA DHCP configuration file to support both subnets and their domains. Remember KEA uses a JSON format.
> sudo vi /etc/kea/kea-dhcp4.conf
- Include global parameters that apply to all subnets, including the new RNDC key file
- Add the pools, router data and the DDNS suffix for each subnet included in our BIND9 DNS server
- Add the following DDNS updates.
- Include global parameters that apply to all subnets, including the new RNDC key file
- Check the file for any errors
> kea-dhcp4 -t kea-dhcp4.conf
- Here is the full configuration for reference
- Restart the DHCP service and check its status
> sudo systemctl restart kea-dhcp4-server.service
- Ensure that each client in blue[.]net is able to receive an IP address.
- Login to the terminal of PC1
- Verify it was assigned an IP address
> ifconfig
Figure 13 – Tiny Core static IP verification - Repeat for the other two client devices
- Configure the DDNS file
- The domain information may not be correct at the moment but that is okay! There is one more piece to this DDNS puzzle and that is configuring the KEA-DDNS file.
- Edit kea’s ddns file
> sudo vi /etc/kea/kea-dhcp-ddns.conf
- Begin by adding some global parameters
<insert beginning of ddns file including include ip, port, socket etc. show the file being small its ending }>
- Append the tsig-key you generated earlier to end of the file. Make sure you are not putting it after the final curly braces and including both the o
> <?include “/etc/kea/tsig-keys.json”?>
- Add the forward lookup information
- Add the reverse lookup information
- Add KEA’s default logging information if it is not already there. We will keep the default values for everything.
- Final configuration reference
- Begin by adding some global parameters
- Modify permissions of file so KEA can access
> sudo chown _kea:root kea-dhcp-ddns.conf”
- Check configuration file for any errors
> kea-dhcp-ddns -t kea-dhcp-ddns.conf
NOTE: If you get an error stating “Can’t open include file /etc/kea/tsig-keys.json” just run the command again with sudo. This is because we just changed the file permissions so only root and kea can access it.
- Restart the service and check its status
> sudo systemctl restart kea-dhcp-ddns-server.service
> systemctl status isc-kea-dhcp-ddhs-server.service
- Troubleshoot as necessary before proceeding to the next section
- Transfer the key file from NS1 to the primary user’s home directory in DHCP1 if you cannot copy paste the private key.
Phase IV – Wireshark Captures
Now that our network is set up, lets watch at some live packet captures to what DNS queries look like in action.
- Start a Wireshark capture between NS1 and the switch
- Test the dynamic DNS updates
- In Wireshark, filter for DNS. Then start up one of the TinyCore computers.
Figure 15 – DNS traffic - In the NS1 terminal, start monitoring the system log
> tail -f /var/log/syslog
- Reboot PC1 and watch the logs for the DHCP handshake and zone file mapping
- In the Wireshark window, you should see *DNS Update* packets
Figure 18 – Wireshark DNS updates - Repeat for the other two PC clients
NOTE: You can request new IP address leases in Tiny Core with the following command:
> sudo udhcpc
- In Wireshark, filter for DNS. Then start up one of the TinyCore computers.
- After about 15 minutes, BIND9 will populate the db files with the updated host/IP records
NOTE: By default, this information is stored in a journal file (.JNL) which is located in the same directory as the zone files. The main database files are not frequently updated to increase efficiency.
End of Lab
Deliverables
4 screenshots are needed to receive credit for this exercise:
- BLUE1 (PC1) successfully pinging BLUE2 (PC2) by name as observed on BLUE1 (PC1)
- BLUE2 (PC2) successfully pinging BLUE3 (PC3) by name as observed on BLUE2 (PC2)
- BLUE1 (PC1) successfully performing a DNS query and resolution with the NS1 server via Wireshark monitoring
- Live stream of NS1 reports of the DHCP handshake and zone logs when (BLUE3) PC3 is rebooted
Homeworks
Assignment 1 – Add the GREEN network to the workspace on the existing router
- Minimize wasted address space for 313 machines
- Add 3 Tiny Core machines to prove functionality
- It is okay to turn off the 3 BLUE end devices to save VM resources
- Modify the router, DHCP1, and NS1 to provide the same functionality to the GREEN network that exists on the BLUE network
Assignment 2 – Complete Assignment 1 and then add a PURPLE network
- Minimize wasted address space for 512 machines
- Add 3 Tiny Core machines to prove functionality
- It is okay to turn off the other end devices to save VM resources
- Modify the router, DHCP1, and NS1 to provide the same functionality to the PURPLE network that exists on the BLUE and GREEN networks
RECOMMENDED GRADING CRITERIA: Same as deliverables with appropriate substitutions for added devices.