Setting up a BIND DNS Server

From SambaWiki
Revision as of 13:05, 2 September 2019 by Thctlo (talk | contribs)


If you are planning to set up a Samba Active Directory (AD) domain controller (DC) using the BIND9_DLZ back end, you have to install and configure the BIND DNS server first.

The following describes how to set up a basic BIND installation you can use as Samba AD DC back end.

Installing BIND

For a list of supported BIND versions, see Configuring the BIND9_DLZ module.

Package Installation

Installing BIND using packages provided with your distribution is the recommended way. Select this installation mode for an easy installation and to automatically receive updates when available. For details how to install packages, see the distribution's package manager documentation.

Make sure that your package provider compiled BIND using the following options:

  • --with-gssapi=yes or --with-gssapi=/usr (or similar) for secure dynamic DNS updates using Kerberos
  • --with-dlopen dynamically loadable zones (DLZ)

To list the build options:

# named -V
BIND 9.x.y built with ... '--with-dlopen=yes' '--with-gssapi=yes' ...

Compiling and Installing BIND

Use this installation mode if you are an advanced user and know how to compile software.

Downloading the Sources

Download a supported BIND version from

Compiling BIND

  • Pass at least the following parameters to the configure command:
# ./configure --with-gssapi=/usr/include/gssapi --with-dlopen=yes
Add further parameters, if required.
  • To build and install, run:
# make
# make install

Adding a User and Group for BIND

For security reasons, do not run BIND as root user.

To create a named group using GID 25:

# groupadd -g 25 named

To create a named account with UID 25, primary group named, home directory /var/named/, and without a valid shell:

# useradd -u 25 -g named -d /var/named -M -s /sbin/nologin named

For details, see the useradd (8) and groupadd (8) man page.

Configuring BIND

Setting up a named.conf file

To locate the directory, BIND uses to read the named.conf file:

# named -V
BIND 9.x.y built with ... '--sysconfdir=/etc' ...

In the previous example, BIND reads the configuration from the /etc/named.conf file.

The following is a basic configuration file:

# Global Configuration Options
options {

    auth-nxdomain yes;
    directory "/var/named";
    notify no;
    empty-zones-enable no;

    # IP addresses and network ranges allowed to query the DNS server:
    allow-query {;;

    # IP addresses and network ranges allowed to run recursive queries:
    # (Zones not served by this DNS server)
    allow-recursion {;;

    # Forward queries that can not be answered from own zones
    # to these DNS servers:
    forwarders {;;

    # Disable zone transfers 
    allow-transfer {

# Root Servers
# (Required for recursive DNS queries)
zone "." {
   type hint;
   file "named.root";

# localhost zone
zone "localhost" {
    type master;
    file "master/";

# 127.0.0. zone.
zone "" {
    type master;
    file "master/";

For details about the used parameters and options, see the named.conf (5) man page.

The previous example does not contain the BIND9_DLZ configuration required for setting up a Samba AD DNS server. For details how to set up the module, see BIND9_DLZ DNS Back End.

Downloading the DNS Root Servers List

  • Download the latest list of the DNS root servers to the /var/named/named.root file:
# wget -q -O /var/named/named.root
  • Enable the BIND user to read the root servers list:
# chown root:named /var/named/named.root
# chmod 640 /var/named/named.root

Creating the localhost Zone File

  • Create the localhost forward zone in the /var/named/master/ file:

$ORIGIN localhost.

@       1D      IN     SOA     @       root (
                       2013050101      ; serial
                       8H              ; refresh
                       2H              ; retry
                       4W              ; expiry
                       1D              ; minimum

@       IN      NS      @
        IN      A
  • Enable the BIND user to read the zone file:
# chown named:named /var/named/master/
# chmod 640 /var/named/master/

Creating the Zone File

  • Create the reverse zone in the /var/named/master/ file:

@       IN      SOA     localhost. root.localhost. (
                        2013050101      ; Serial
                        8H              ; Refresh
                        2H              ; Retry
                        4W              ; Expire
                        1D              ; Minimum TTL

       IN      NS      localhost.

1      IN      PTR     localhost.

  • Enable the BIND user to read the zone file:
# chown named:named /var/named/master/
# chmod 640 /var/named/master/

Installing & Configuring BIND on Debian based distros

Installing the required packages

You need to install the following packages:

apt-get install -y bind9 bind9utils

Setting up the named.conf files

On Debian based distros, you have 5 Bind9 files:


Of these, only two or three need to be configured.

If you only use ipv4, edit : /etc/default/bind9 and Change:

OPTIONS="-u bind"


OPTIONS="-u bind -4"

The second file /etc/bind/named.conf, Shouldn't need modification, as it just contains links to the other named.conf files:

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

The third file /etc/bind/named.conf.options, is the one you need to configure for your Active Directory and to setup default ACL's for Bind9.

// Managing acls
acl internals {;; };

options {
      directory "/var/cache/bind";
      version "Go Away 0.0.7";
      notify no;
      empty-zones-enable no;
      auth-nxdomain yes;
      forwarders {;; };
      allow-transfer { none; };

      dnssec-validation no;
      dnssec-enable no;
      dnssec-lookaside no;

      // If you only use IPv4. 
      listen-on-v6 { none; };
      // listen on these ipnumbers. 
      listen-on port 53 {;; ::1; };

      // Added Per Debian buster Bind9. 
      // Due to : resolver: info: resolver priming query complete messages in the logs. 
      // See:
      minimal-responses yes;

      //  Add any subnets or hosts you want to allow to use this DNS server
      allow-query { "internals";  };
      allow-query-cache { "internals"; };

      //  Add any subnets or hosts you want to allow to use recursive queries
      recursion yes;
      allow-recursion {  "internals"; };

      // ONE of the following lines should be enable AFTER you provisioned/joined 
      //     or upgrade you dns from internal to bind9_dlz 
      // DNS dynamic updates via Kerberos (optional, but recommended)
      // samba 4.9 and lower
      //tkey-gssapi-keytab "/var/lib/samba/private/dns.keytab";
      // samba 4.9 and higher. ( samba_dnsupgrade needs to be run for it. ) 
      tkey-gssapi-keytab "/var/lib/samba/bind-dns/dns.keytab";


The fourth file /etc/bind/named.conf.local, just needs the addition of one line, to link in another file provided by Samba:

include "/var/lib/samba/bind-dns/named.conf";

The last file /etc/bind/named.conf.default-zones does not require any changes.

Starting the Daemon

To start the BIND daemon as the named user, run

# named -u named

Alternatively, use your operating system tools, such as systemctl or service, to start the daemon. See your distribution's documentation for details.

Testing Your Zones

The following examples query the DNS service on the local machine (

To test the localhost forward zone:

# host -t A localhost
Using domain server:
localhost has address

To test the reverse zone:

# host -t PTR
Using domain server:
Aliases: domain name pointer localhost.

Configuring the BIND9_DLZ module

For details, see See BIND9_DLZ DNS Back End.