How to Setup DNS server using Bind9 on Ubuntu 16.04

Prerequisites

  1. A fresh Alibaba Cloud Ubuntu 16.04 instance.
  2. A static IP address 192.168.0.102 setup in your instance.
  3. A root password is set up to your instance.

Launch Alibaba Cloud ECS Instance

apt-get update -y

Install BIND 9

apt-get install bind9 bind9utils bind9-doc dnsutils -y
nano /etc/systemd/system/bind9.service
[Service]
ExecStart=/usr/sbin/named -f -u bind -4
systemctl daemon-reload
systemctl restart bind9

Configure BIND 9

nano /etc/bind/named.conf.options
forwarders {
8.8.8.8;
};
nano /etc/bind/named.conf.local
// 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 "example.com" {
type master;
file "/etc/bind/forward.example.com";
};
zone "0.168.192.in-addr.arpa" {
type master;
file "/etc/bind/reverse.example.com";
};

Configure Forward and Reverse Lookup Zone

cd /etc/bind/
cp db.127 reverse.example.com
cp db.local forward.example.com
nano /etc/bind/forward.example.com
$TTL    604800
@ IN SOA test.example.com. root.test.example.com. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
@ IN NS test.example.com.
test IN A 192.168.0.102
www IN A 192.168.0.102
@ IN AAAA ::1
nano /etc/bind/reverse.example.com
$TTL    604800
@ IN SOA test.example.com. root.test.example.com. (
1
604800
86400
2419200
604800 )
@ IN NS test.example.com.
test IN A 192.168.0.102
102 IN PTR test.example.com.
nano /etc/resolv.conf
search example.com
nameserver 192.168.0.102
systemctl restart bind9
named-checkzone forward.example forward.example.com
zone forward.example/IN: loaded serial 2
OK
named-checkzone reverse.example reverse.example.com
zone reverse.example/IN: loaded serial 1
OK

Test BIND 9 DNS Server

dig test.example.com
; <<>> DiG 9.10.3-P4-Ubuntu <<>> test.example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46893
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;test.example.com. IN A
;; ANSWER SECTION:
test.example.com. 604800 IN A 192.168.0.102
;; AUTHORITY SECTION:
example.com. 604800 IN NS test.example.com.
;; Query time: 0 msec
;; SERVER: 192.168.0.102#53(192.168.0.102)
;; WHEN: Sun Sep 16 14:23:46 IST 2018
;; MSG SIZE rcvd: 75
dig -x 192.168.0.102
; <<>> DiG 9.10.3-P4-Ubuntu <<>> -x 192.168.0.102
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 3223
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;102.0.168.192.in-addr.arpa. IN PTR
;; AUTHORITY SECTION:
0.168.192.in-addr.arpa. 604800 IN SOA test.example.com. root.test.example.com. 1 604800 86400 2419200 604800
;; Query time: 1 msec
;; SERVER: 192.168.0.102#53(192.168.0.102)
;; WHEN: Sun Sep 16 14:32:34 IST 2018
;; MSG SIZE rcvd: 112
nslookup test.example.com
Server:        192.168.0.102
Address: 192.168.0.102#53
Name: test.example.com
Address: 192.168.0.102
nslookup 192.168.0.102
Server:         192.168.0.102
Address: 192.168.0.102#53
102.0.168.192.in-addr.arpa name = example.com.

--

--

--

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Basics for network communication on python

Math in Solidity (Part 3: Percents and Proportions)

How I Learned How To Build Apps in 6 Steps (and you can, too)

How to find all the unused Objective-C selector

How NOT to write pandas code

input(),type conversion| python tutorial 3

Java 8 | Two Dimensional Array

My 10 Favorite & Relatable Web Dev Comics of All Time

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

More from Medium

Docker and The Rise of Containerization

Generation and installation of SSL certificates for dependencies

How to use Custom Docker Images in GitLab Pipelines

Deploy multi-container app on Heroku using GitHub Actions