How To Configure DNS Server On Ubuntu 16.04


Basic change from configuring Ubuntu 14 was just about network adapter. It seems like ubuntu 16 can't give us virtual network adapter (as far as i can try), so i decide to add a network adapter manually through Virtual Machine. And one more thing, the network adapter name it self change to ens not eth.

In this scenario i will create primary (farihin.com) and secondary domain (mail.farihin.com) so i need 2 network adapter.

#1--------Before you type any other code, first you need to log on as SU:
farihin@farihin-vm:~$ sudo su
[sudo] password for farihin:

#2--------After that update your system (you need to have internet connection) by typing this:
root@farihin-vm:/home/farihin# apt-get update

#3--------Ubuntu will check & install for updates, after finished updating then install apache2:
root@farihin-vm:/home/farihin# apt-get install apache2

#4--------After that install bind9:
root@farihin-vm:/home/farihin# apt-get install bind9

#5--------After installing bind9, now configure the ip address:
root@farihin-vm:/home/farihin# nano /etc/network/interfaces
#---------We will create 2 IP Address. In the nano, write down this code:
root@farihin-vm:/home/farihin# nano /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
#auto lo
#iface lo inet loopback

auto ens33
iface ens33 inet static
address 192.168.100.1
netmask 255.255.255.0


gateway 192.168.100.1
broadcast 192.168.100.255
dns-serch farihin.com
dns-nameservers 192.168.100.1

auto ens38
iface ens38 inet static
address 192.168.100.2
netmask 255.255.255.0
gateway 192.168.100.1
network 192.168.100.0
broadcast 192.168.100.255
dns-serch mail.farihin.com
dns-nameservers 192.168.100.2
#---------When finished modifying, hit CTRL+X, than hit Y, then hit ENTER

#6--------After that then restart the neworking, use this command:
root@farihin-vm:/home/farihin# ip add flush ens33
root@farihin-vm:/home/farihin# ip add flush ens38
root@farihin-vm:/home/farihin# /etc/init.d/networking restart
#---------Don’t worry even if the restarting process got FAILED, just check the IP Address

#7------Check configured IP Address:
root@farihin-vm:/home/farihin# ifconfig
#-------If the IP Address was RIGHT then try to ping the 2 IP’s, you have to make sure all of it REPLAY.
#-------If one of them not replay then check your configuration.
#-------If your configuration was right, then restart your Ubuntu.

#8------After doing command above, configure the host file by typing:
root@farihin-vm:/etc/bind# nano /etc/hosts
#-------Write down this 2 lines script right under last 127.0.1.1:
127.0.0.1       localhost
127.0.1.1       farihin-vm
192.168.100.1   farihin.com
192.168.100.2   mail.farihin.com

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

#9------Now go to “/etc/bind” directories and list the files, make sure you have named.conf.local file:
root@farihin-vm:/home/farihin# cd /etc/bind
root@farihin-vm:/etc/bind# ls
bind.keys  db.empty    named.conf.default-zones  zones.rfc1918
db.0       db.local    named.conf.local
db.127     db.root     named.conf.options
db.255     named.conf  rndc.key

#10------We need to modify named.conf.local files, so open it with nano:
root@farihin-vm:/etc/bind# nano named.conf.local
#---------Our goal is to create 3 zone for “farihin.com”, “forum.farihin.com”, and “mail.farihin.com”. On nano write this script:
//
// Do any local configuration here
//

// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";

zone "farihin.com" {
type master;
file "/etc/bind/db.farihin";
};

zone "mail.farihin.com" {
type master;
file "/etc/bind/db.mailfarihin";
};

zone "100.168.192.in-addr.arpa" {
type master;
file "/etc/bind/db.farihin.rev";
};
#--------When finished, hit CTRL+X, than hit Y, then hit ENTER

#11-----In this stage we will create a db files that we declare on our zone. First let’s create db.farihin file. Now copy the “db.local” file to “db.yourname” file:
root@farihin-vm:/etc/bind# cp db.local db.farihin
#--------Then open the “db.yourname” file with nano:
root@farihin-vm:/etc/bind# nano db.farihin



#--------On nano write this script:
;
; BIND data file for local loopback interface
;
$TTL    604800
@       IN      SOA     farihin.com. root.farihin.com. (

                         604800         ; Refresh
                              2         ; Serial
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@                       IN      NS      farihin.com.
@                       IN      A       192.168.100.1


farihin.com             IN      A       192.168.100.1
mail.farihin.com        IN      A       192.168.100.2

#12------Second we’ll create db.farihin.rev file. Now copy “db.yourname” to “db.yourname.rev”, and open it with nano:
root@farihin-vm:/etc/bind# cp db.farihin db.farihin.rev
root@farihin-vm:/etc/bind# nano db.farihin.rev
#--------On nano write this script:
;
; BIND data file for local loopback interface
;
$TTL    604800
@       IN      SOA     farihin.com. root.farihin.com. (
                              2         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
100.168.192.in-addr.arpa.       IN      NS      farihin.com.
1                               IN      PTR     farihin.com.
2                               IN      PTR     mail.farihin.com.

#13-------Third, we’ll create db.mailfarihin by copying and modifying from db.farihin’s file:
root@farihin-vm:/etc/bind# cp db.farihin db.mailfarihin
root@farihin-vm:/etc/bind# nano db.mailfarihin
#----------Change some code:
;
; BIND data file for local loopback interface
;
$TTL    604800
@       IN      SOA     mail.farihin.com. root.farihin.com. (
                              2         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@                       IN      NS      mail.farihin.com.
@                       IN      A       192.168.100.2

farihin.com             IN      A       192.168.100.1
mail.farihin.com        IN      A       192.168.100.2

#14-----Now configure the “resolv.conf” file by opening it with nano:
root@farihin-vm:/etc/bind# nano /etc/resolv.conf
#--------On nano write this script:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated $
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OV$
domain farihin.com
search farihin.com
nameserver 192.168.100.1

#15--------Now restart the bind9:
root@farihin-vm:/etc/bind# /etc/init.d/bind9 restart
[ ok ] Restarting bind9 (via systemctl): bind9.service.

#16--------After restarting, try to ping the domain and sub-domain:
root@farihin-vm:/etc/bind# ping farihin.com
PING farihin.com (192.168.100.1) 56(84) bytes of data.
64 bytes from farihin.com (192.168.100.1): icmp_seq=1 ttl=64 time=0.018 ms
64 bytes from farihin.com (192.168.100.1): icmp_seq=2 ttl=64 time=0.022 ms
64 bytes from farihin.com (192.168.100.1): icmp_seq=3 ttl=64 time=0.029 ms
^C
--- farihin.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2033ms
rtt min/avg/max/mdev = 0.018/0.023/0.029/0.004 ms
root@farihin-vm:/etc/bind# ping mail.farihin.com
PING mail.farihin.com (192.168.100.2) 56(84) bytes of data.
64 bytes from mail.farihin.com (192.168.100.2): icmp_seq=1 ttl=64 time=0.020 ms
64 bytes from mail.farihin.com (192.168.100.2): icmp_seq=2 ttl=64 time=0.025 ms
64 bytes from mail.farihin.com (192.168.100.2): icmp_seq=3 ttl=64 time=0.023 ms
^C
--- mail.farihin.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2046ms
rtt min/avg/max/mdev = 0.020/0.022/0.025/0.005 ms

#17--------And the last do the nslookup:
root@farihin-vm:/etc/bind# nslookup farihin.com
Server:         192.168.100.1
Address:   192.168.100.1#53

Name: farihin.com


Address: 192.168.100.1
root@farihin-vm:/etc/bind# nslookup mail.farihin.com
Server:         192.168.100.1
Address:   192.168.100.1#53

Name: mail.farihin.com
Address: 192.168.100.2



#--You now finished configuring DNS Server.
#--If there is REPLAY when you doing ping then your configuration was right, if it’s not then re-check your configuration. And if nslookup give a result you’re 100% DONE.

#--Another way to test the DNS Server go to your web browser and type farihin.com OR mail.farihin.com on the addressbar.

1 Comments

Post a Comment

Previous Post Next Post