How To Setup DNS Server In Ubuntu

by

About DNS

DNS, stands for Domain Name System, translates hostnames or URLs into IP addresses. For example, if we type www.unixmen.com in browser, the DNS server translates the domain name into its associated ip address. Since the IP addresses are hard to remember all time, DNS servers are used to translate the hostnames like www.unixmen.com to 173.xxx.xx.xxx. So it makes easy to remember the domain names instead of its IP address.

In this tutorial, we will see how to setup and configure DNS server on Ubuntu 14.04 LTS. Also, the same method will work on Debian and its derivatives.

Setup DNS Server In Ubuntu 14.04

Scenario

For the purpose of this tutorial, I will be using three nodes. One will be acting as Master DNS server, the second system will be acting as Secondary DNS, and the third will be our DNS client. Here are my three systems details.

Primary (Master) DNS Server Details:

Secondary (Slave) DNS Server Details:

Client Details:

Setup Caching Server

In this configuration BIND9 will find the answer to name queries and remember the answer for the next query. This can be useful for a slow internet connection. By caching DNS queries, you will reduce bandwidth and (more importantly) latency.

The default configuration is setup to act as a caching server. All that is required is simply adding the IP Addresses of your ISP’s DNS servers. Caching server is opt for low Internet connection.

Install bind9 packages using command:

Then edit /etc/bind/named.conf.options file,

Simply uncomment and edit the following in /etc/bind/named.conf.options:

Restart bind9 service.

Test Caching Server

Run the following command to test it.

Sample output:

Setup Primary (Master) DNS Server

You can use the same server for both Primary and Caching server.

Install bind9 packages on your server if not installed.

1. Configure Master DNS Server

DNS configuration files are stored in /etc/bind directory. Primary configuration file is /etc/bind/namd.conf.

Edit ‘/etc/bind/named.conf’ file.

Make sure it contains the following lines. If not, add them.

Save and close the file.

Then, edit named.conf.local,

Add the lines as shown in bold:

Here,

  • forward.unixmen – Forward zone file
  • reverse.unixmen – Reverse zone file
  • 192.168.1.102 – Slave DNS server

2. Create Zone files

Create forward and reverse zone files which we defiend in the ‘/etc/bind/named.conf.local’ file.

2.1 Create Forward Zone

Create Forward Zone file name forward.unixmen in /etc/bind/zones,

Add the following lines:

2.2 Create Reverse Zone

Create Forward Zone file name reverse.unixmen in /etc/bind/zones,

Add the following lines:

3. Configuring Permissions, Ownership for Bind

Run the following commands one by one:

chmod -R 755 /etc/bind
sudo chown -R bind:bind /etc/bind[/crayon]

4. Test DNS configuration and zone files for any syntax errors

Check DNS default configuration file:

If it returns nothing, your configuration is valid.

Check Forward zone:

Sample output:

Check reverse zone:

Sample Output:

Restart bind9 service.

Add the DNS Server details in your network interface config file.

Add the nameserver IP address:

Reboot your system.

5. Test DNS Server

Method 1:

Sample Output:

Method 2:

Sample Output:

Now the Primary DNS server is ready to use.

It is time to configure our Secondary DNS server.

Setup Secondary(Slave) DNS Server

Secondary DNS server is optional, but recommended. If the master DNS server goes down, the Secondary DNS server will take charge and answer the queries. You need an additional server to setup Slave DNS server.

Install bind9 packages using the following command:

1. Configure Slave DNS Server

Edit ‘/etc/bind/named.conf’ file.

Make sure it contains the following lines. If not, add them.

Save and close the file.

Then, edit named.conf.local,

Add the lines as shown in bold:

Here,

  • forward.unixmen – Forward zone file
  • reverse.unixmen – Reverse zone file
  • 192.168.1.101 – Master DNS server

The zone file must be in /var/cache/bind/ because, by default, AppArmor only allows write access inside it.

3. Configuring Permissions, Ownership for Bind

Run the following commands one by one:

chmod -R 755 /etc/bind
sudo chown -R bind:bind /etc/bind[/crayon]
Restart bind9 service.

4. Add the DNS Server details

Add the DNS Server details in your network interface config file.

Save and close the file.

Reboot your system.

5. Test DNS Server

After logging in to your server, run the following commands to check if DNS server is really working or not.

Method 1:

Sample Output:

Method 2:

Sample Output:

Method 3:

Sample Output:

Note: A zone is only transferred if the Serial Number on the Primary DNS server is larger than the one on the Secondary DNS server.

Client Side Configuration

Add the DNS server details in ‘/etc/resolv.conf’ file in all client systems

Restart network service or reboot the system.

Test DNS Server

Now, you can test the DNS server using any one of the following commands:

That’s all about now. The primary and secondary DNS servers are ready to use.

If you want to setup DNS server on RHEL based systems, check the following links.

Cheers!