Install and configure DNS in Linux
Mar 30, 2021
·
3 mins read
In the video below, we show you how to install and configure DNS server in Linux using Ubuntu 20.04 LTS and Bind
We’ll set up a DNS forwarder for Internet DNS resolution, as well as forward and reverse lookup zones for our local network
Useful links:
https://ubuntu.com/download/server
Installation and configuration example:
-
Install Ubuntu and apply the latest patches
-
Install and configure Bind9
sudo apt install -y bind9 bind9utils bind9-doc dnsutils -
Configure DNS Forwarding
Edit named.conf.options e.g.cd /etc/bind Backup the existing file, named.conf.options e.g. sudo cp named.conf.options named.conf.options.bakSo it looks something like thissudo nano named.conf.options
NOTE: DNSSec disabled as it was found to cause issues for Ubuntu 20.04acl trustedclients { localhost; localnets; 172.16.18.0/24; 172.16.19.0/24; }; options { directory "/var/cache/bind"; recursion yes; allow-query { trustedclients; }; allow-query-cache { trustedclients; }; allow-recursion { trustedclients; }; forwarders { 1.1.1.2; 1.0.0.2; }; dnssec-validation no; listen-on-v6 port 53 { ::1; }; listen-on port 53 { 127.0.0.1; 172.16.17.10; }; }; -
Define zone files
Backup the existing file named.conf.local e.g.Edit named.conf.local e.g.sudo cp named.conf.local named.conf.local.bakSo it looks something like thissudo nano named.conf.localCheck the file for errorszone "templab.lan" { type master; file "/etc/bind/db.templab.lan"; }; zone "17.16.172.in-addr.arpa" { type master; file "/etc/bind/db.172.16.17"; };sudo named-checkconf -
Create a forward lookup zone
Copy an existing file to one with the name used before e.g.Edit the file e.g.sudo cp db.local db.templab.lanSo that it looks something like thissudo nano db.templab.lanCheck the file syntax; ; BIND data file for templab.lan zone ; $TTL 604800 @ IN SOA ns1.templab.lan. admin.templab.lan. ( 3; Serial 604800; Refresh 86400; Retry 2419200; Expire 604800 ); Negative Cache TTL ; @ IN NS ns1.templab.lan. ns1 IN A 172.16.17.10 dhcp1 IN A 172.16.17.12 fw IN A 172.16.18.254sudo named-checkzone templab.lan db.templab.lan -
Create a reverse lookup zone
Copy an existing file to one with the name used before e.g.Edit the file e.g.sudo cp db.127 db.172.16.17So that it looks something like thissudo nano db.172.16.17
Check the file syntax; ; BIND reverse data file for templab.lan zone ; $TTL 604800 @ IN SOA ns1.templab.lan. admin.templab.lan. ( 2; Serial 604800; Refresh 86400; Retry 2419200; Expire 604800 ); Negative Cache TTL ; @ IN NS ns1.templab.lan. 10 IN PTR ns1.templab.lan. 12 IN PTR dhcp1.templab.lan.sudo named-checkzone 17.16.172.in-addr.arpa db.172.16.17 -
Edit the server’s DNS entry to use it’s own DNS server
Edit the yaml configuration file, e.g.cd /etc/netplanChange the IP address of the dns server entry and save the filesudo nano 00-installer-config.yaml
Apply the changesudo netplan apply -
Start and test DNS
Check its statusstart bind9 sudo systemctl start bind9Test DNS is working e.g.sudo systemctl status bind9host dhcp1.templab.lan host 172.16.17.10 ping www.amazon.com
Sharing is caring!