How to Install DNS server in UBUNTU 16?
STEP 1: Update server-
# Sudo apt-get update
# sudo apt-get upgrade
# sudo apt-get dist-upgrade
STEP 2: Install BIND9 -
# sudo apt-get install bind9 bind9utils bind9-doc
STEP 3: caching name server-
To configure Caching name server, edit /etc/bind/named.conf.options file:
# sudo nano /etc/bind/named.conf.options
Uncomment the below lines. Make the entry of forwarders (default 8.8.8.8)
{` forwarders { 8.8.8.8; };`}
Save and close the file. Restart bind.
# sudo systemctl restart bind9
STEP 4: Testing the name server
# dig -x 127.0.0.1
( the status should return with STATUS : NOERROR )
STEP 5: Installing/configuring DNS server –
Edit /etc/bind/named.conf file
# sudo nano /etc/bind/named.conf
If these lines are not there just add them -
{` include "/etc/bind/named.conf.options"; include "/etc/bind/named.conf.local"; include "/etc/bind/named.conf.default-zones"; `}
Save and close the file.
STEP 6: now define forward and reverse zone file. To do so edit the file
#sudo nano /etc/bind/named.conf.local
Add these lines to the file and make the changes like IP, DOMAIN NAME according to you…
{` zone "example.com" { type master; file "/etc/bind/for.example.com"; allow-transfer { 192.168.1.1; }; also-notify { 192.168.1.1; }; }; zone "1.168.192.in-addr.arpa" { type master; file "/etc/bind/rev.example.com"; allow-transfer { 192.168.1.1; }; also-notify { 192.168.1.1; }; };`}
Save and close the file.
NOW CREATE THE ZONE FILE –
# sudo nano /etc/bind/for.example.com
Add the following lines in it –
{` $TTL 86400 @ IN SOA pri.example.com. root.example.com. ( 2011071001 ;Serial 3600 ;Refresh 1800 ;Retry 604800 ;Expire 86400 ;Minimum TTL ) @ IN NS pri.example.com. pri IN A 192.168.1.1 `}
Here you can add secondary DNS server and client entry according to the scheme/pattern.
Save and close the file.
NEXT create reverse zone file –
# sudo nano /etc/bind/rev.example.com
Add the following lines
{` $TTL 86400 @ IN SOA pri.example.com. root.example.com. ( 2011071002 ;Serial 3600 ;Refresh 1800 ;Retry 604800 ;Expire 86400 ;Minimum TTL ) @ IN NS pri.example.com. @ IN PTR example.com. pri IN A 192.168.1.1 1 IN PTR pri.example.com. `}
Save and close the file.
NOW set the permission –
# sudo chmod -R 755 /etc/bind
# sudo chown -R bind:bind /etc/bind
STEP 7 – Verify the DNS configuration files :
# sudo named-checkconf /etc/bind/named.conf
# sudo named-checkconf /etc/bind/named.conf.local
If the commands return nothing that means DNS configuration is valid. If it show error, correct them In particular file.
Verify the ZONE file –
# sudo named-checkzone example.com /etc/bind/for.example.com
Sample output :
{` zone example.com/IN: loaded serial 2011071001 OK `}
In same manner check the reverse zone file –
# sudo named-checkzone example.com /etc/bind/rev.example.com
Sample Output :
{` zone example.com/IN: loaded serial 2011071002 OK `}
STEP 8 – Checking the DNS server is working or not –
To do so, First Add the DNS IP address in this file :
# sudo nano /etc/network/interfaces
Add these lines to the file :
{` # primary network interface auto ens33 iface ens33 inet static address 192.168.1.1 netmask 255.255.255.0 gateway 192.168.1.10 dnsnameservers 192.168.1.1 `}
Save and close the file.
Finally Restart the BIND9 service :
# sudo systemctl restart bind9
STEP 10 – Testing DNS server –
# dig pri.example.com
( it should return with STATUS : NOERROR)
# nslookup example.com
Sample Output :
{` Server: 192.168.1.1 Address: 192.168.1.1#53 Name: example.com Address: 192.168.1.1 `}
IF YOU GOT THE RESULT, SOMETHING LIKE ABOVE, THAT MEANS YOUR DNS SERVER IS UP and IS WORKING PROPERLY.