Bind 9
Bind 9
Bind 9
Daftar Isi
1. Introduction
2. Definitions
3. Network Layout
4. Server Management
1. Installation
2. Configuration
1. TSIG Signature
2. File /etc/bind/named.conf
3. File /etc/bind/named.conf.default-zones
4. File /etc/bind/named.conf.options
5. File /etc/bind/named.conf.local
6. File /etc/bind/named.conf.log
1. Files in var/cache/bind/
2. Some Explanations :
4. /etc/resolv.conf File
5. Bind Chroot
6. Client Manage
7. Testing tools
Introduction
8. Links and Resources
Now imagine that our network administrator decides for some reason or another to
move the mail server to the machine 192.168.0.11. The only thing that has to be
changed is the DNS server configuration file. You could always go and modify the
host configuration for all the users, but that would be time consuming and
inconvenient.
Definitions
DNS : Domain Name System or Domain Name Server
Primary Server :
Secondary server :
Server cache :
Network Layout
We get internet access through an xxxbox (192.168.1.1), two DNS servers provided
by our ISP (80.10.249.2, 80.10.246.129). In fact, these two latter servers will ever be
referred to in the configuration because the xxxbox will be in charge of resolving
names if the packet destination isn't known. Consequently, I consider the xxxbox like
a primary server outside of our domain. The sid server (192.168.1.10) is connected
to the xxxbox via its primary network card. It's also connected to the LAN
(192.168.0.0/24) by its secondary network interface(192.168.0.1). It's on this that we
are going to install the primary DNS server for our domain example.com (RFC 2606)
All the computers on the LAN are automatically assigned a single address by the
DHCP service. The DHCP also provides the primary DNS server's address for our
domain, and updatees the host names for the zone example.com so they can be
associated with an ip address.
Server Management
Installation
The package bind9 will be used for installation.
and then if you want to also install the documentation (very useful):
TSIG Signature
The purpose of this signature is to authenticate transactions with BIND. Thus, the
DHCP server cannot update the example.com domain if it loses this key. Copy and
paste an existing key
# cd /etc/bind/
# cat rndc.key
key "rndc-key" {
algorithm hmac-md5;
secret "QJc08cnP1xkoF4a/eSZZbw==";
};
# cp rndc.key ns-example-com_rndc-key
example-com_rndc-key
Kns-example-com_rndc-key.+157+53334
The footprint associated with the key is 53334. We get two files, one with an
extension key and the other with a private extension. This substitutes the key in the
file ns-example-com_rndc-key with the one in one of these two files.
# cat Kns-example-com_rndc-key.+157+53334.private
Private-key-format: v1.2
Key:
LZ5m+L/HAmtc9rs9OU2RGstsg+Ud0TMXOT+C4rK7+YNUo3vNxKx
/197o2Z80t6gA34AEaAf3F+hEodV4K+SWvA==
Bits: AAA=
# cat ns-example-com_rndc-key
key "ns-example-com_rndc-key" {
algorithm hmac-md5;
secret
"LZ5m+L/HAmtc9rs9OU2RGstsg+Ud0TMXOT+C4rK7+YNUo3vNxK
x/197o2Z80t6gA34AEaAf3F+hEodV4K+SWvA==";
};
The file ns-example-com_rndc-key should not be made world readable for security
reasons. This should be inserted into the bind configuration by an include because
the bind configuration itself is world-readable. Also, it's a good idea to delete the key
and private files generated before.
File /etc/bind/named.conf
This file is the main configuration file for the DNS file.
// Managing acls
// Load options
include "/etc/bind/named.conf.options";
// on the localhost
controls {
};
};
servers
zone "." {
type hint;
file "/etc/bind/db.root";
};
include "/etc/bind/named.conf.default-zones";
include "/etc/bind/named.conf.local";
Note : with Debian Jessie the 'zone "." {...}' part is inside the file "named.conf.default-
zones". You don't need to add it in the file "named.conf".
File /etc/bind/named.conf.default-zones
Note: as of Debian 7 "Wheezy" bind9 ships with a file containing default forward,
reverse, and broadcast zones.
zone "localhost" {
type master;
file "/etc/bind/db.local";
};
zone "127.in-addr.arpa" {
type master;
file "/etc/bind/db.127";
};
zone "0.in-addr.arpa" {
type master;
file "/etc/bind/db.0";
};
zone "255.in-addr.arpa" {
type master;
file "/etc/bind/db.255";
};
File /etc/bind/named.conf.options
This file contains all the configuration options for the DNS server
options {
directory "/var/cache/bind";
them
forward only;
forwarders { 192.168.1.1; };
allow-transfer { none; };
only
allow-query { internals; };
hosts
allow-recursion { internals; };
};
The port associated with the query-source option must not in any case be frozen
because it jeopardizes the DNS transactions in the case of a resolver.
M. Rash wrote an interesting article about this and how to force the source port
randomly via the iptables: Mitigating DNS Cache Poisoning Attacks with iptables
To reduce the delay timeout for UDP connections, and thus highlight the
randomization, which by default is 30s by tuple, simply update the parameter
net.netfilter.nf_conntrack_udp_timeout
# sysctl -w
net.netfilter.nf_conntrack_udp_timeout=10
File /etc/bind/named.conf.local
This file contains the local DNS server configuration, and this is where you declare
the zones associated with this server's domain(s).
include "/etc/bind/named.conf.log";
// Domain Management example.com
// ------------------------------
domain.
dynamically
zone "example.com" {
type master;
file "/var/lib/bind/db.example.com";
//forwarders {};
key) ?
};
zone "0.168.192.in-addr.arpa" {
type master;
file "/var/lib/bind/db.example.com.inv";
//forwarders {};
key; };
};
// Consider adding the 1918 zones here, if they are
// organization
include "/etc/bind/zones.rfc1918";
NOTE: if you create a local non-FQDN and call it .local it clashes with some other
packages (which?). Edit /etc/nsswitch.conf and move dns right after the files on the
host line makes .local domains work.
File /etc/bind/named.conf.log
logging {
channel update_debug {
file "/var/log/update_debug.log"
severity debug;
print-severity yes;
print-time yes;
};
channel security_info {
file "/var/log/security_info.log"
severity info;
print-severity yes;
print-time yes;
};
channel bind_log {
size 1m;
severity info;
print-category yes;
print-severity yes;
print-time yes;
};
category default { bind_log; };
};
Here we define different log methods for the different categories. The first category
is, as its name indicates the default category that is usually assigned to syslog. All
categories not mentioned, are similar to the default category. For a list of the
different categories, see the bind9 administrator reference manual. In terms of blade-
servers, it ignores all the logs associated with them.
Files in var/cache/bind/
$TTL 3600
@ IN SOA sid.example.com.
root.example.com. (
2007010401 ; Serial
3600 ; Refresh
[1h]
600 ; Retry
[10m]
86400 ; Expire
[1d]
600 ) ; Negative
@ IN NS sid.example.com.
@ IN MX 10 sid.example.com.
sid IN A 192.168.0.1
etch IN A 192.168.0.2
pop IN CNAME sid
2007010401 ; Serial
3600 ; Refresh
[1h]
600 ; Retry
[10m]
86400 ; Expire
[1d]
600 ) ; Negative
@ IN NS sid.example.com.
1 IN PTR sid.example.com.
2 IN PTR etch.example.com.
Some Explanations :
$TTL : (Time To Live) expresses the duration (in seconds) validity, by default, of the
information contained in the RRs. Once this time expires, it is necessary to recheck
the data. Types :
to define information about the area. In this case the name of the primary DNS
server "sid.example.com." and the email address of technical contact
(root.example.com.; the @ is replaced by a dot). It is composed of several fields:
The classes in the association determines the Internet class. Other classes are
available (CH and HS). For more information please consult the RFC 1035
/etc/resolv.conf File
search example.com
This option is found in the bind service config file /etc/default/bind9 (NOTE: this is
not valid for jessie who used systemd):
OPTIONS="-u bind"
The bind start script /etc/init.d/bind9 reads this config file when the service is
started.
Starting bind as a non root user is good practice but to run the daemon in a chroot
environment we also need specify the chroot directory. This is done using the same
OPTIONS variable in /etc/default/bind9.
/etc/init.d/bind9 stop
[Unit]
Documentation=man:named(8)
After=network.target
[Service]
ExecStart=/usr/sbin/named -f -u bind -t
/var/bind9/chroot
ExecReload=/usr/sbin/rndc reload
ExecStop=/usr/sbin/rndc stop
[Install]
WantedBy=multi-user.target
For Jessie, after creating the above unit file, update the symlink to the unit file with:
mkdir -p
/var/bind9/chroot/{etc,dev,var/cache/bind,var/run/n
amed}
Create the required device special files and set the correct permissions:
mknod /var/bind9/chroot/dev/null c 1 3
mknod /var/bind9/chroot/dev/random c 1 8
Move the current config directory into the new chroot directory:
mv /etc/bind /var/bind9/chroot/etc
If you want to use the local timezone in the chroot (e.g. for syslog):
cp /etc/localtime /var/bind9/chroot/etc/
Change the ownership on the files you've just moved over and the rest of the newly
created chroot directory structure:
chmod 775
/var/bind9/chroot/var/{cache/bind,run/named}
chgrp bind
/var/bind9/chroot/var/{cache/bind,run/named}
PIDFILE=/var/bind9/chroot/var/run/named/named.pid
Finally tell rsyslog to listen to the bind logs in the correct place:
echo "\$AddUnixListenSocket
chroot.conf
start
Client Manage
As I mentioned at the beginning, the assignment of IP addresses on the LAN is
performed by the DHCP server. Thus, to set our DNS server to different clients, it is
necessary to add the DHCP configuration file the following two lines:
It must be added to the file (I think) the areas for which DHCP should automatically
perform updates.
zone [name.of.the.zone.] {
primary 127.0.0.1; => the primary DNS server is on the same machine as the
DHCP
key rndc-key; => it's necessary to provide the security key (via an include) in the
beginning of the DHCP server configuration file,
this must be the same key that secures the allow-update for the zone in the
named.conf.local of Bind9.
$ dig nomade-frjo.stones.lan
;; Got answer:
15760
AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;nomade-frjo.stones.lan. IN A
;; ANSWER SECTION:
nomade-frjo.stones.lan. 900 IN A
192.168.0.242
;; AUTHORITY SECTION:
stones.lan. 604800 IN NS
emerald.stones.lan.
stones.lan. 604800 IN NS
diamond.stones.lan.
;; ADDITIONAL SECTION:
diamond.stones.lan. 604800 IN A
192.168.0.1
emerald.stones.lan. 604800 IN A
192.168.0.2
$ dig -x 192.168.0.242
;; Got answer:
37702
AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;242.0.168.192.in-addr.arpa. IN PTR
;; ANSWER SECTION:
nomade-frjo.stones.lan.
;; AUTHORITY SECTION:
0.168.192.in-addr.arpa. 604800 IN NS
diamond.stones.lan.
0.168.192.in-addr.arpa. 604800 IN NS
emerald.stones.lan.
;; ADDITIONAL SECTION:
diamond.stones.lan. 604800 IN A
192.168.0.1
emerald.stones.lan. 604800 IN A
192.168.0.2
;; SERVER: 127.0.0.1#53(127.0.0.1)
$ nslookup etch
Server: 192.168.0.1
Address: 192.168.0.1#53
Name: etch.example.com
Address: 192.168.0.2
$ nslookup 192.168.0.2
Server: 192.168.0.1
Address: 192.168.0.1#53
2.0.168.192.in-addr.arpa name =
etch.example.com.
# named-checkconf -z
20080315
# named-checkzone example.com
/var/lib/bind/db.example.com
OK
# named-checkzone 0.168.192.in-addr.arpa
/var/lib/bind/db.example.com.inv
20080315
OK
?ToDos
End of
To add DNSSEC.