Josh Preston

Josh Preston



18,385 latest version

3.1 quality score

Version information

  • 1.1.2 (latest)
  • 1.1.1
  • 1.1.0
released Jul 3rd 2019
This version is compatible with:
  • Puppet Enterprise 3.x
  • Puppet 3.x
  • Ubuntu, Debian, Gentoo, CentOS, RedHat

Start using this module


mrjoshuap/dnsmasq — version 1.1.2 Jul 3rd 2019


Build Status

Table of Contents

  1. Overview
  2. Module Description
  3. Setup
  4. Usage - Configuration options and additional functionality
  5. Reference - An under-the-hood peek at what the module is doing and how
  6. Limitations - OS compatibility, etc.
  7. Development - Guide for contributing to the module


Manage dnsmasq via Puppet. This module was derived on the excellent work of Steffen Zieger.


Dnsmasq provides network infrastructure for small networks: DNS, DHCP, router
advertisement and network boot. It is designed to be lightweight and have a
small footprint, suitable for resource constrained routers and firewalls. It
has also been widely used for tethering on smartphones and portable hotspots,
and to support virtual networking in virtualisation frameworks. Supported
platforms include Linux (with glibc and uclibc), Android, *BSD, and Mac OS X.
Dnsmasq is included in most Linux distributions and the ports systems of
FreeBSD, OpenBSD and NetBSD. Dnsmasq provides full IPv6 support.


  • Steffen Zieger
  • Udo Waechter
  • Josh Preston


Copyright 2011 Steffen Zieger

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Module Description

This module manages dnsmasq server installations. It provides the following types:

Configurations can be created and managed preferably with Hiera or alternatively through Puppet Code.

It supports exporting virtual resources with the dnsmasq::exported class parameter, so dnsmasq::dhcp_host types can be managed in Puppet Code and the server will automatically import those resources. If you are running with no Puppet Master (masterless), set dnsmasq::exported to false.


The basics of getting started with dnsmasq.

What dnsmasq Affects

This module manages dnsmasq which affects the following:

    /etc/ethers         #- DHCP Client Mapping
    /etc/hosts          #- DNS Lookups (FQDN and aliases)
    /etc/dnsmasq.conf   #- main dnsmasq config file (include dir)
    /etc/dnsmasq.d/*    #- dnsmasq managed include config directory

The config directory is a managed directory by default. Any non-managed configurations located in it will be removed. If you wish to disable this behavior, set dnsmasq::purge to false.

Setup Requirements

  1. Install

    puppet module install mrjoshuap/dnsmasq

  2. Include the module in your Puppet Code

    include ::dnsmasq

  3. Configure with Hiera

  4. Configure with Puppet Code

  5. Paydirt

Beginning with dnsmasq

First, the default configuration template only includes configuration files in the ::dnsmasq::config_dir. This means that to do anything interesting, you'll want to build some basic configuration. This typically means setting bind interfaces, and other options specific to your site.

For example, use a template that looks like:

  • some_module/templates/dnsmasq.d/my-site.erb
    resolv-file=<%= scope.lookupvar('::dnsmasq::resolv_file') %>
    local=/<%= scope.lookupvar('::domain') -%>/
    listen-address=<%= scope.lookupvar('::ipaddress') %>
    domain=<%= scope.lookupvar('::domain') -%>,

Then configure it with Hiera:

        ensure: present
        prio: 01
        template: some_module/dnsmasq.d/my-site.erb

Configurations: Hiera

The preferred way to configure dnsmasq is with the use of Hiera.

Source a static configuration file

        source: puppet:///files/dnsmasq/local-dns

or, Specify the exact content

        content: dhcp-range=,,12h

or, Specify a template to be rendered

        ensure: present
        template: some_module/dnsmasq-template.erb

Configurations: Puppet Code

Although not preferred, you can also create configurations with Puppet code.

Source a static configuration file

    ::dnsmasq::conf { 'local-dns':
      ensure => present,
      source => 'puppet:///files/dnsmasq/local-dns',

or, Specify the exact content

    ::dnsmasq::conf { 'another-config':
      ensure  => present,
      content => 'dhcp-range=,,12h',

or, Render your own template

    ::dnsmasq::conf { 'another-config':
      ensure  => present,
      content => template('some_module/dnsmasq-template.erb'),

or, Specify a template to be rendered

    ::dnsmasq::conf' { 'another-config':
      ensure   = 'present',
      template = 'some_module/dnsmasq-template.erb',

Host Lookups and DHCP Reservations Overview

Since dnsmasq provides DNS services, it must know about IPs and hosts. You can create adhoc hosts for dnsmasq with the dnsmasq::host type and DHCP reservations with the dnsmasq::dhcp_host type.

Host Lookups

For host resolution, dnsmasq by default will rely on /etc/hosts. When you create a new dnsmasq::host, it creates the appropriate entry in /etc/hosts. Afterwards, it will reload dnsmasq so the changes take close to immediate effect.