Saturday, 17 March 2012

Setup a DNS server with bind in ubuntu

Setup a DNS server with bind

1. Install bind 9:

# sudo apt-get install bind9

2. Configure the main Bind files.

# sudo vi /etc/bind/named.conf.local

Insert the zone definition in this file

//This is the zone definition. replace example.com with your domain name
zone "example.com" {
       type master;
       file "/etc/bind/zones/example.com.db";
       };

//This is the zone definition for reverse DNS. replace 0.168.192 with your network address in reverse notation - e.g my network address is 192.168.0
zone "0.168.192.in-addr.arpa" {
    type master;
    file "/etc/bind/zones/rev.0.168.192.in-addr.arpa";
};


3. Now, let's add the zone definition files

# sudo mkdir /etc/bind/zones
# sudo vi /etc/bind/zones/example.com.db

example.com.      IN      SOA     ns1.example.com. admin.example.com. (

                                                       2006081401
                                                       28800
                                                       3600
                                                       604800
                                                       38400
)

example.com.    IN    A        192.168.0.3
example.com.    IN      NS              ns1.example.com.
example.com.    IN      NS              ns2.example.com.
example.com.    IN      MX     10       example.com.
www        IN      A           192.168.0.3
ns1        IN      A           192.168.0.1
ns2        IN    A        192.168.0.2

//ns1 and ns2 are the nameservers


4. Now, let's create the reverse DNS zone file:

# sudo vi /etc/bind/zones/rev.0.168.192.in-addr.arpa

//Copy and paste the following text, modify as needed:
//my domain ip address is 192.168.0.1

@ IN SOA ns1.example.com. admin.example.com. (
                       2006081401;
                       28800;
                       604800;
                       604800;
                       86400
)

1                    IN    PTR    example.com.

5. Restart bind

# sudo /etc/init.d/bind9 restart


6. Now, test DNS:

# dig example.com

No comments:

Post a Comment