The actual communication between two systems happens with the help of IP addresses. However, remembering IP addresses of each system is difficult, especially when there are millions of websites and domain servers exist. Domain Name Server (DNS) is a service that allows you to create a mapping table that resolves IP addresses to the respective domain names. The full domain name is consists of a hostname and a domain name. It also referred as Fully Qualified Domain Name (FQDN). In this tutorial, we are going to explain how to configure DNS server in Ubuntu Linux. We are using the latest version of Ubuntu that is Ubuntu 17.04. However, the same steps can also be used to configure DNS server in other Linux variants and other versions of Ubuntu such as Ubuntu 16.04 and Ubuntu 14.04.
Also, read:
The following three types of DNS servers can be configured on a Linux system.
- Caching-only DNS server
- Primary DNS server
- Secondary DNS server
1. Configuring Caching-only DNS server in Ubuntu Linux
Caching-only DNS server does not host its own DNS zone data. When a domain name query is resolved by a client, caching name server stores the resolved queries in its cache. When the same query is requested by another client, caching name server answers the query from its cache thus reducing the query resolve time.
In order to configure caching-only DNS server in Ubuntu Linux, the following steps need to be followed.
Installing DNS Server Packages
In the Linux systems, for DNS server, you need to install bind9 and dnsutils packages using the following commands:
sudo apt install bind9 sudo apt install dnsutils
Updating named.conf File
After installing the required packages, you need to modify the DNS server configuration file. Most of the Ubuntu and other Linux platforms, the main DNS configuration file is /etc/bind/named.conf.
Configuring caching-only DNS server is pretty simple. In fact, the /etc/bind/named.conf.options file is already configured to act as the caching-only name server. You just need to replace the current IP address with your upside DNS server IP address in the /etc/bind/named.conf.options file. The following figure shows how to configure caching-only DNS server in Ubuntu.
After updating the DNS configuration file, restart the DNS service, and verify that the service is running properly.
sudo systemctl restart bind9.service sudo systemctl status bind9.service
That’s all you need to configure caching name server in Ubuntu Linux. Isn’t it so easy?
Configure Primary Master DNS Server
To configure primary master DNS server in Ubuntu Linux, you need to update the /etc/bind/named.conf.local configuration file. In this file, you configure DNS forward lookup and reverse lookup zone. Forward lookup zone is used to resolve an FQDN name to IP address and reverse lookup zone is used to resolve IP address to the FQDN name.
- Recommended: Configure LAMP in Ubuntu Linux
Configure Forward Lookup Zone Options
We assume that protechgurus.com is your domain name and db.protechgurus.com would your zone data file name. Considering this, the DNS configuration file for the primary master DNS server should look like the following.
zone "protechgurus.com" { type master; file "/etc/bind/db.protechgurus.com"; };
Creating Forward Lookup Zone Data File
Now, you need to create a zone file that you have mentioned in the previous file, named as db.protechgurus.com, under the /etc/bind directory. To simplify your tasks, you can use the /etc/bind/db.local template file to create /etc/bind/db.protechgurus.com file.
sudo cp /etc/bind/db.local /etc/bind/db.protechgurus.com
Now edit the zone file as per your network settings. Replace the highlighted text with your actual DNS server IP address and domain name.
In the above file, whenever you make any changes, you also need to increase the serial number by plus 1 (+1).
Finally, save the zone file and restart the DNS service.
sudo systemctl restart bind9.service
Configuring Reverse Lookup Zone
Once you configured and updated the forward lookup zone, the next step is to configure reverse lookup zone. In the DNS configuration file, add the reverse lookup zone entry. In our example, the reverse lookup zone name is 0.16.172.in-addr-arpa and the zone data file name is db.172.16. The final content of the /etc/bind/named.conf.local file should look like as follow:
Like the forward lookup zone, you also need to create and update the reverse lookup zone file named as /etc/bind/db.172.16. For this, copy the template file as /etc/bind/db.172.16 and update the file content as shown below.
Similar to the forward lookup zone, whenever there a modification happens in the reverse lookup zone file, you need to increase the serial number by +1 each time.
Before proceeding further, please check that your zones are configured properly and the syntax of the configuration file is OK. For this, execute the commands as shown in the following figure.
Finally, restart the bind the service. If everything goes fine, the service should start and status should be shown as running.
sudo systemctl restart bind9.service sudo systemctl status bind9.service
Verifying DNS Server Configuration
Now, you have successfully configured caching-only and primary master DNS server in Ubuntu Linux. We will cover secondary DNS server in a separate tutorial.
Now to further verify, execute the following commands:
dig <your-domain-name> ping <your-domain-name> ping <ns.your-domain-name>
We recommend you to spend some time with the above commands and review the output details of each command.
Do subscribe us to stay connected with us and get notified for upcoming tutorials.