DNS BIND Rpi

In this tutorial we will see how to install and setup Bind.
First of all install the software:

1
sudo apt-get install bind9 bind9-doc dnsutils

The most important files to configure BIND are the following (note that named and BIND are two names for the same application):

/etc/bind9/named.conf. Is the main configuration file and consist of a collection of statements using nested options placed in ellipses { }. It will usually only contain references to the rest of the configuration files.
/etc/bind9/named.conf.options. It contains all the configuration options for the DNS server such as the port to listen, the forwarders to use, etc.
/etc/bind/named.conf.local. This file has the local DNS server configuration. This is where we will declare the zones associated with the local server by configuring domains. These domains will be searched locally instead of being searched outside using forwarders.
/etc/bind/named.conf.default.zones. It contains the default zones of the server.

Basic Config

The standard configuration of BIND will provide you with with a cache/forwarder DNS Server that will recursively seek answers from other DNS servers when a client issues a query. This means that your Raspberry Pi will do the work of querying each related DNS server in turns until it finds the entire response. Once the answer is received, your local DNS Server will reply to the client and will save it in a cache file. In the future, if a client places again the same query, the answer will be considerably faster.

Let’s have a deeper look at this basic configuration in named.conf.options file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Access Control List that includes the loopback interface and the local network
acl internals {
127.0.0.0/8;
192.168.1.0/24;
};

options {

directory "/var/cache/bind";
auth-nxdomain no;
# Forward queries to:
forwarders {
8.8.8.8; # Google DNS
9.9.9.9; # IMB Quad9 DNS
192.168.1.1; # ISP DNS (router's own DNS)
};

# Listen port 43 from loopback and our own IP Address
listen-on port 53 {
127.0.0.1;
192.168.1.100;
};

# Don't listen IPv6 traffic
listen-on-v6 {
none;
};

# Allow queries from loopback and our internal network
allow-query {
internals;
};

# Do not transfer the zone information to the secondary DNS
allow-transfer {
none;
};

// Allow recursive queries to the local host
allow-recursion {
internals;
};

};

First of all, an Access Control List is defined. It should include the devices allowed to use the DNS. In this case, the loopback interface and the internal network IPs.
Section forwarders contains the DNS Servers IP that will be used to forward and answer the DNS queries. In this case, I use Google and IBM servers.
The next two sections configure the listeners, limited to local interfaces and IPV4.
Finally the last three sections allow queries, transfers and recursions for the devices defined in the acl labeled internals.
After implementing the changes save and close the file. By now you should have a DNS server able to forward queries and save them in cache.

Configuring Clients with the DNS Server

Change the settings in your system preferences network section to tell you computer to use the new DNS.

On a linux system this change is much easier. You can edit the resolv.conf file and include the following line:

1
2
3
vi /etc/resolv.conf

nameserver 192.168.2.1

^