Linux – configure BIND DNS on debian

binddebiandomain-name-systemlinux

I'm trying to configure configure BIND for use on my local Debian machine, which I will use as a development and testing environment.

First of all, I'm using Debian 6.x [Squeeze] and BIND 9. BIND server was set up automatically during the installation of the Debian.

For the purpose of this question, let's say I want to create a domain called example.com that I will be able to access from the same machine on which BIND is running, and my local network.

Here is what I have done so far:

In /etc/bind named.conf.local (which is included in name.conf) I put the following:

zone "cms1.com" {
    type master;
    file "/etc/bind/db.example.com";
};

In /etc/bind/db.example.com I put the following:

$TTL    3600
@   IN  SOA example.com. admin.example.com. (
            2011101601  ; Serial
            3600        ; Refresh 1h
            60      ; Retry 1m
            86400       ; Expire 1d
            600 )       ; Negative Cache TTL 1h
;
@   IN  NS  localhost.

;
example.com.    IN CNAME localhost.
example.com.    IN A 127.0.0.1

Notice that I am setting the nameserver as localhost. I don't know if this is right or wrong.

Then I added the appropriate virtual host directives to Apache and restarted BIND using the command /etc/init.d/bind9 restart.

However, when I ping or browse to example.com I access the example.com on the internet, and not the one on my machine.

What am I doing wrong?


To take AlexD's advice, I added nameserver 127.0.0.1 before all other directives in /etc/resolv.conf shown here:

# Generated by NetworkManager
nameserver 127.0.0.1
domain cm.flowja.com
search cm.flowja.com
nameserver 65.183.0.76
nameserver 65.183.0.86

The other directives were automatically generated by Debian.

Here is the response after I edited resolve.conf and restarted BIND.

; <<>> DiG 9.7.3 <<>> example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 60115
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;example.com.           IN  A

;; Query time: 3 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sun Oct 16 16:06:29 2011
;; MSG SIZE  rcvd: 29

Now it seems to that adding the nameserver 127.0.0.1 directive to resolv.conf actually caused example.com to resolve to my BIND server, but something is still going wrong.

Ideas?

Best Answer

Your original config:

$TTL    3600
@   IN  SOA example.com. admin.example.com. (
            2011101601  ; Serial
            3600        ; Refresh 1h
            60      ; Retry 1m
            86400       ; Expire 1d
            600 )       ; Negative Cache TTL 1h
;
@   IN  NS  localhost.

;
example.com.    IN CNAME localhost.
example.com.    IN A 127.0.0.1

should be changed to this:

$TTL    3600
@   IN  SOA example.com. admin.example.com. (
            2011101801  ; Serial
            3600        ; Refresh 1h
            60      ; Retry 1m
            86400       ; Expire 1d
            600 )       ; Negative Cache TTL 1h
;
@   IN  NS  ns1.example.com.

;
example.com.        IN A 127.0.0.1
ns1.example.com.    IN A 127.0.0.1
www.example.com.    IN CNAME example.com.

(did you notice that I also changed the serial? for every change you make on the config you need to alter the Serial. It's format is YEARMMDD and a two digit ID starting at 01 which you need to +1 every time you make a change. So for example if you made a second change on the config today, you should change it to 2011101802, on a third change it should be 2011101803, or if you would make a change tomorrow it should be 2011101901 etc. this is very important!)

Also make sure that on your webserver you have a virtual host configured as example.com

Check that your /etc/resolv.conf points to your local BIND and has nameserver 127.0.0.1 entry first. If you are using debian with Gnome then Network Manager might overwrite resolv.conf. One solution for this is just to add the nameserver to Network Manager through the GUI, but make sure that it is first in the list.