You get a bonus - 1 coin for daily activity. Now you have 1 coin

Installing and Configuring the BIND (named) DNS Server on Linux Debian

Practice



Task: install and perform the initial configuration of the bind DNS server (also known as named) on Linux Debian OS.


Installing

$ sudo apt-get install bind9 dnsutils


Configuring

First, let's tell the syslog daemon that it should listen for and write logs from the DNS server. To do this, open the file /etc/rsyslog.conf and add the following entry at the very end of the file:

!named
*.* /var/log/named.log
!-named

this tells the system to write bind logs to the file /var/log/named.log

Restart the logging daemon:

$ sudo /etc/init.d/rsyslog restart


Next, bind stores its settings at /etc/bind. Let's go to this directory - everything from now on will happen there.

$ cd /etc/bind


It is assumed that this is our master server (i.e. primary).

1) Create the directory that will hold the configurations of our DNS zones.

$ sudo mkdir master


2) Open the named.conf.options file for editing and bring it to this form (all options are commented, you need to set their values correctly for your own setup, not just copy the examples):

options {
directory "/var/cache/bind"

# This lists the DNS servers that this server will query in case
# it is not itself the authority for the domain being resolved. Usually you specify
# your provider's DNS servers and/or the domain controller's DNS servers.
# ..For example, if this server is asked what IP address yandex.ru has, it won't
# know itself, but it can ask the upstream provider's DNS server.
forwarders {
11.77.55.33;
11.77.55.34;
192.168.0.1;
};

# Where to accept DNS queries from. "any" means from all interfaces, from any
# computer
allow-query { any; };

# This lists the slave DNS servers that are allowed to receive information
# when DNS zones are updated on the current server.
allow-transfer {
11.22.33.45;
192.168.0.2;
};

# This lists the addresses or subnets from which recursive queries are allowed.
allow-recursion {
127.0.0.1;
192.168.0.0/24;
};

# When this option is enabled and any DNS zone changes on this server, it will
# automatically notify all slave servers that the zone has changed and
# needs to be reloaded.
notify yes;

# By default, only the server(s) specified as slave
# servers within the zone's own description are notified. If you have the same slave
# server(s) - then it makes sense to list it(them) as servers that should always
# be notified about zone changes. In that case, even if these servers are not
# authoritative for these zones - nothing bad will happen - they will simply"ignore" the
# change notification.
# This option provides exactly that capability - to specify slave DNS servers
# that are always notified of zone changes.
also-notify {
11.22.33.45;
192.168.0.2;
};

auth-nxdomain no;

# Should queries over the IPv6 protocol be expected, and from where? "none" means - don't expect any and
# ignore them; "any" means expect them from all computers.
listen-on-v6 { none; };

};


Save the file.

3) Now open the named.conf file and see that it contains 3 references to our configurations:

...
include "/etc/bind/named.conf.options";
include "/etc/bind/named.conf.local";
include "/etc/bind/named.conf.default-zones";


We will add one more reference - to the file with the descriptions of our DNS zones:

...
include "/etc/bind/named.conf.options";
include "/etc/bind/named.conf.local";
include "/etc/bind/named.conf.default-zones";
# Our zones will go here:
include "/etc/bind/named.conf.zones";


And let's save this config file.

4) Now let's create the file /etc/bind/named.conf.zones and write a test zone into it. This file will look something like this:

zone "test.int" {
type master;
file "/etc/bind/master/test.int";
};


As we can see here, I specified a zone "test.int" that deliberately doesn't exist on the internet. Its type on this server is master (i.e. it is a master zone, meaning its updates should be managed on this server) and its description should be taken from the specified file.

5) Well then, let's create such a file:

$ cd /etc/bind/master
$ sudo touch test.int


And let's put roughly this config into it (again, the correct IP address and name values depend on your network):

$ORIGIN .
$TTL 3600;
test.int. IN SOA ns1.mydomain.ru. webadmin.mydomain.ru. (
2011080901 ; serial
28800 ; refresh (8 hours)
7200 ; retry (2 hours)
604800 ; expire (1 week)
86400 ; minimum (1 day)
)
NS ns1.mydomain.ru.
NS ns2.mydomain.ru.
A 192.168.0.50
MX 10 mail.mydomain.ru.

$ORIGIN test.int.
ftp A 192.168.0.51
mail A 192.168.0.3
www CNAME test.int.


As you can see, I threw in all the values in this zone completely at random.

Now let's save our file.

6) Ask bind to reread our configs:

$ sudo rndc reload


7) Let's check:

$ nslookup test.int 127.0.0.1


And look at the result. The server should respond that test.int is located at address 192.168.0.50 (as specified in the zone configuration above, or another address - whichever you entered).


The DNS server's further life

All the other zones are created in a similar way, but with real details (for example, from the .ru, .com zones, etc.) The named.conf.zones file looks something like this:

zone "mydomain.ru" {
type master;
file "/etc/bind/master/mydomain.ru";
};

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


And for each zone we create a small file with its configuration in /etc/bind/master, similar to the test.int sample configuration.


PS. Tip. Do NOT forget to put ";" in the named config everywhere it's needed! The absence of a single such semicolon will break the launch of the entire bind.

PPS. Do NOT forget to put a trailing dot "." at the end of zones that are absolute (recommended pretty much everywhere). That is, for example, if instead of "test.int." you write "test.int" in the zone config - you will get something completely different from what you expected! And, accordingly, nothing at all will work.

PPPS. When making any change to a zone - don't forget to increase its serial number. And not just change it - specifically increase it. In this case, using the format YYYYMMDDNN, where YYYY is the 4-digit year, MM is the 2-digit month, DD is the 2-digit day, and NN is "how many times I've changed the zone today" - is quite convenient, since over time its numeric value will only increase.



Slave DNS servers

If you need to set up slave DNS servers right away - read the article that describes how to do this

Applies to: Linux Debian Lenny (5), Squeeze (6)

See also

  • [[b11054]]
  • [[b11032]]
  • [[b11052]]

See also

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Running server side scripts using PHP as an example (LAMP)"

Terms: Running server side scripts using PHP as an example (LAMP)