Ashish Jaiswal Blog

A blog dedicated to community

Bind DNS With Puppet on Opensuse

This blog is about setting up a DNS server with puppet module. I have written a manifesto to get the job done. You can add more if you like.

Requirements

  1. OpenSuse OS.
  2. Puppet Server

You can install bind manually like this and then configure it. But if you have multiple DNS server, then puppet can be handy. Currently my manifest only manage configuration file. Will add support to manage the zone files too.

Terminal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[root@ashish1099:~] zypper install bind
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 2 NEW packages are going to be installed:
  bind bind-chrootenv

2 new packages to install.
Overall download size: 316.3 KiB. After the operation, additional 717.7 KiB will be used.
Continue? [y/n/? shows all options] (y): y
Retrieving package bind-chrootenv-9.9.4P2-2.8.1.x86_64                                                                                                                                                   (1/2),  33.4 KiB (  1.6 KiB unpacked)
Retrieving: bind-chrootenv-9.9.4P2-2.8.1.x86_64.rpm ....................................................................................................................................................................................[done]
Retrieving package bind-9.9.4P2-2.8.1.x86_64                                                                                                                                                             (2/2), 282.9 KiB (716.1 KiB unpacked)
Retrieving: bind-9.9.4P2-2.8.1.x86_64.rpm ..............................................................................................................................................................................................[done]
(1/2) Installing: bind-chrootenv-9.9.4P2-2.8.1 .........................................................................................................................................................................................[done]
Additional rpm output:
Updating /etc/sysconfig/named...
Updating /etc/sysconfig/syslog...


(2/2) Installing: bind-9.9.4P2-2.8.1 ...................................................................................................................................................................................................[done]
Additional rpm output:
Updating /etc/sysconfig/named...
wrote key file "/etc/rndc.key"
dns.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Server::dns

class server::dns {

        package { "bind" : ensure => present }
        service { "named.service" : ensure => running, enable => true }

        define conf (
                        $directory              = "/var/lib/named",
                        $managed_keys_directory = "/var/lib/named/dyn/",
                        $dump_file              = "/var/log/named_dump.db",
                        $statistics_file        = "/var/log/named.stats",
                        $forwarders             = [],
                        $forward                = "only",
                        $listen_on_v6           = "none" ) {

        File { ensure => present, require => Package["bind"], notify => Service["named.service"] }

        # Configuration files
        file { $name : ensure => present, content => template("server/dns/named_conf.erb") }
        file { "/etc/named.d/rndc-access.conf" : ensure => present }

  } # End of server::dns::conf defination

        # Root Zone
        conf { '/etc/named.conf' :
                        forwarders      => "192.168.1.2",
                        zones           => {
                        '.'                     => [ 'type hint', 'file "root.hint"'],
                        # Forward Zone
                        'localhost'             => [ 'type master', 'file "localhost.zone"'],
                        'example.com'           => [ 'type master', 'file "master/example.com"'],
                        # Reverse Zone
                        '0.0.127.in-addr.arpa' => [ 'type master', 'file "127.0.0.zone"'],
                        '1.168.192.in-addr.arpa' => [ 'type master', 'file "master/192.168.1.rev"'],
                         } # End of Zones
  } # End of conf 
} # End of DNS
named_conf.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Generated by Puppet

options {

  directory "<%=@directory%>";
  managed-keys-directory "<%=@managed_keys_directory%>";
  dump-file "<%=@dump_file%>";
  statistics-file "<%=@statistics_file%>";
  forwarders { <%=@forwarders%>; };
  forward <%=@forward%>;
  listen-on-v6 { <%=@listen_on_v6%>; };
  notify no;
  disable-empty-zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.ARPA";
};

<% if !@zones.empty? -%>
/* Global zones */
<% @zones.sort_by {|key, value| key}.each do |key,value| -%>
zone "<%= key %>" in {
<% value.each do |line| -%>
  <%= line %>;
<% end -%>
};

<% end -%>
<% end -%>

Comments