How To Install and Configure DNS Server in Linux
How To Install and Configure DNS Server in Linux
Domain Name Service (DNS) is an internet service that maps IP addresses to fully qualified domain names (FQDN) and vice versa. BIND stands for Berkley Internet Naming Daemon. BIND is the most common program used for maintaining a name server on Linux. In this tutorial, we will explain how to install and configure a DNS server. If you are new to DNS, you should first understand the fundamentals of DNS and how it works.
1. Network Information
In this tutorial, we are going to setup a local DNS server for the network shown in the below diagram. Well use thegeekstuff.net domain as an example for this DNS installation. mail, web, ns are the hosts that resides within this domain. It is possible to configure a single system to act as a caching name server, primary/master and secondary/slave. We will configure this DNS as a Primay/Master as well as Caching DNS server. Well be installing DNS server on 10.42.0.83.
2. Install Bind
Install the bind9 package using the appropriate package management utilities for your Linux distributions. On Debian/Ubuntu flavors, do the following:
$ sudo apt-get install bind9
All the DNS configurations are stored under /etc/bind directory. The primary configuration is /etc/bind/named.conf which will include other needed files. The file named /etc/bind/db.root describes the root nameservers in the world.
Now when the second time you execute the dig, there should be an improvement in the Query time. As you see below, it took only 3 msec the second time, as it is getting the info from our caching DNS server.
$ dig ubuntu.com ;; Query time: 3 msec
Now the file /etc/bind/db.thegeekstuff.net will have the details for resolving hostname to IP address for this domain/zone, and the file /etc/bind/db.10 will have the details for resolving IP address to hostname.
Next, edit the /etc/bind/db.thegeekstuff.net and replace the following. 1. In the line which has SOA: localhost. This is the FQDN of the server in charge for this domain. Ive installed bind9 in 10.42.0.83, whose hostname is ns. So replace the localhost. with ns.thegeekstuff.net.. Make sure it ends with a dot(.).
2. In the line which has SOA: root.localhost. This is the E-Mail address of the person who is responsible for this server. Use dot(.) instead of @. Ive replaced with lak.localhost. 3. In the line which has NS: localhost. This is defining the Name server for the domain (NS). We have to change this to the fully qualified domain name of the name server. Change it to ns.thegeekstuff.net.. Make sure you have a . at the end. Next, define the A record and MX record for the domain. A record is the one which maps hostname to IP address, and MX record will tell the mailserver to use for this domain. Once the changes are done, the /etc/bind/db.thegeekstuff.net file will look like the following:
$TTL @ IN 604800 SOA ns.thegeekstuff.net. lak.localhost. ( 1024 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL 10 mail.thegeekstuff.net.
Next, edit the /etc/bind/db.10 file, and basically changing the same options as /etc/bind/db.thegeekstuff.net
$TTL @ IN 604800 SOA ns.thegeekstuff.net. root.localhost. ( 20 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL NS ns.
; @
IN
Whenever you are modifying the file db.thegeekstuff.net and db.10, you need to increment the Serial number as well. Typically admin uses DDMMYYSS for serial numbers and when they modify, the change the serial number appropriately. Finally, restart the bind9 service:
$ sudo service bind9 restart
Now ping, mail.thegeekstuff.net, which should resolve the address appropriately from the DNS server that we just configured.
$ ping mail.thegeekstuff.net PING mail.thegeekstuff.net (10.42.0.70) 56(84) bytes of data. 64 bytes from mail.thegeekstuff.net (10.42.0.70): icmp_req=1 ttl=64 time=0.482 ms 64 bytes from mail.thegeekstuff.net (10.42.0.70): icmp_req=2 ttl=64 time=0.532 ms