Quick Setting Bind on FreeBSD 8.1

I’m big fan of djbdns and I already write some post about djbdns and dnscache in the past.

Today, my friend ask me to install or configure bind for his FreeBSD that run 8.1 version. I ask him to follow FreeBSD manual but he said he already follow the guide but still face error.

I agree to help him set quick dns server using bind on his FreeBSD box. I think I have to test it first before give another suggestion and maybe I’ll need it in the future.

Lets get start!

Target : domain example.com will be resolved to 192.168.12.108

1. Enable bind on start up by add this line in /etc/rc.conf

named_enable=”YES”

2. Change a few things on /etc/namedb/named.conf

– Listen to ip 192.168.12.108

//      listen-on       { 127.0.0.1; };
listen-on       { 192.168.12.108; };

– Set forwarders to ip address of router / isp dns

forwarders {
192.168.12.1;
};

– Add zone for example.com

zone “example.com”{
type master;
file “/etc/namedb/master/example.com”;
};

3. Add zone file content (for example.com)

ee /etc/namedb/master/example.com

add fill this lines:

$TTL 3600        ; 1 hour default TTL
example.com.    IN      SOA      ns1.example.com. admin.example.com. (
2006051501      ; Serial
10800           ; Refresh
3600            ; Retry
604800          ; Expire
300             ; Negative Response TTL
)

; DNS Servers
IN      NS      ns1.example.com.
IN      NS      ns2.example.com.

; MX Records
IN      MX 10   mx.example.com.
IN      MX 20   mail.example.com.

IN      A       192.168.12.108

; Machine Names
localhost       IN      A       127.0.0.1
ns1             IN      A       192.168.12.108
ns2             IN      A       192.168.12.107
mx              IN      A       192.168.12.108
mail            IN      A       192.168.12.108
www             IN      A       192.168.12.108
@               IN      A       192.168.12.108

save the file.

4. Add the address to /etc/resolv.conf

echo ‘nameserver 192.168.12.108’ >> /etc/resolv.conf

5. Restart dns server

# /etc/rc.d/named restart

Stopping named.
Waiting for PIDS: 2130.
Starting named.

6. Testing resolver

# dig example.com

; <<>> DiG 9.6.2-P2 <<>> example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 26178
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 2

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

;; ANSWER SECTION:
example.com.    3600    IN      A       192.168.12.108

;; AUTHORITY SECTION:
example.com.    3600    IN      NS      ns1.example.com.
example.com.    3600    IN      NS      ns2.example.com.

;; ADDITIONAL SECTION:
ns1.example.com. 3600   IN      A       192.168.12.108
ns2.example.com. 3600   IN      A       192.168.12.107

;; Query time: 0 msec
;; SERVER: 192.168.12.108#53(192.168.12.108)
;; WHEN: Sun Jun 19 23:19:07 2011
;; MSG SIZE  rcvd: 121

Beautiful, quick and dirty way to get working dns server 🙂

Tips :

always watch /var/log/messages for error message(s).

Tags: