Setting up a DNS-server on Ubuntu 16.04
ref: https://tecadmin.net/configure-dns-server-on-ubuntu-linuxmint/
BIND9
If you have a “normally complex” network at home, You usually have an internet router which takes care of DNS-resolutions.
However the downside is that you wont get “local” names resolved, like a local test domain (mydomain.test) or internal names of your servers.
If you use Windows you solve part of the problem using Wins, but thats a very limited solution to a very complex problem.
Instead you should setup your own DNS server. On Ubuntu it is called BIND9 for some reason. You let this server resolve everything that it has in its cache, and forwards request to the internet router, and further on to the ISP’s dns server in turn.
The benefit is, apart from the local names/domain, that you gain a speedup if the DNS-name exists in your cache. It’s not a huge gain, but it all adds up.
Installing
sudo apt-get install bind9
Configuring
If you look at the files under /etc/bind, you will see a main config file named.conf which will include named.conf.options, named.conf.local and named.conf.default-zones.
(We see here the name confusions between NAMED and BIND9)
Start by editing named.conf.options.
Inside the options block, make sure you have a block like this:
forwarders {
192.168.0.1;
};
This will ensure that DNS-names that your server can’t resolve will be forwarded to the internet router.
Next step would be to edit the named.conf.local
First we define a zone (domain) mydomain.local. I choose an .local extension that doesnt exist (I believe?!) to avoid shadowing a real internet domain.
zone "mydomain.local" {
type master;
file "/etc/bind/db.mydomain.local";
};
To avoid confusion later, the file name should should have a name that corresponds to the domain name.
Next, we define the reverse lookup zone. If your network is 192.168.0.* the definition should look like this:
zone "0.168.192.in-addr.arpa" {
type master;
notify no;
file "/etc/bind/db.192";
};
Now it’s time to edit the files we referenced earlier.
/etc/bind/db.mydomain.local
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA ns.mydomain.local. root.localhost. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800) ; Negative Cache TTL
;
@ IN NS ns.mydomain.local.
@ IN A 127.0.0.1
@ IN AAAA ::1
router IN A 192.168.0.1
dev IN A 192.168.0.5
macbook IN A 192.168.0.6
imac1 IN A 192.168.0.64
imac2 IN A 192.168.0.124
alpha IN A 192.168.0.199
nas IN A 192.168.0.240
and the reverse-lookup zone:
;
; BIND reverse data file for local loopback interface
;
$TTL 604800
@ IN SOA localhost. root.localhost. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.mydomain.local
1 IN PTR router.mydomain.local
5 IN PTR dev.mydomain.local
6 IN PTR macbook.mydomain.local
124 IN PTR imac1.mydomain.local
125 IN PTR imac2.mydomain.local
199 IN PTR alpha.mydomain.local
240 IN PTR nas.mydomain.local
Then restart the BIND server with
service bind restart
Check /var/log/ for error messages
You can also use dmesg