Installation: dnsmasq

Introduction

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.1

Installation

To install dnsmasq run the below. 

sudo apt install dnsmasq

Implementation

Once installed, there are three configuration files which need to be modified to assure that the domains are assigned properly. Please note that these configurations are build off of the example provided by computingforgeeks.com and should be modified to fit your firm's needs. 2

First, resolv.conf which can be found in the etc folder. This must contain the list of DNS servers to be used on the device. This includes the device's own IP address.

nameserver 8.8.8.8
nameserver 1.1.1.1
nameserver <device ip>

Once the resolv.conf has been modified, modify the /etc/hosts file by adding the LAN IP of the servers on the network and the hostnames of the devices/VMs.

XXX.XXX.XXX.XXX                    test.example.com
XXX.XXX.XXX.XXX                    test2.example.com
XXX.XXX.XXX.XXX                    test3.example.com

Lastly, add the rules to the /etc/dnsmasq.conf file

# Never forward plain names (without a domain)
domain-needed
# Turn off DHCP on eth0
no-dhcp-interface=
# Never forward addresses in the non-routable address space (RFC1918)
bogus-priv
# Add domain to host names
expand-hosts
#Domain to be added if expand-hosts is set
domain=example.com
# Local domain to be served from /etc/hosts file
local=/example.com/
# Don't read /etc/resolv.conf (I deleted it). Get the external name server from
no-resolv
# external server, works with no-resolv
server=8.8.8.8
#to prevent binding on lo0
listen-address=<device ip>

 


  1. thekelleys.org.uk. “Dnsmasq - Network Services for Small Networks.,” n.d.
  2. Install and Configure Dnsmasq on Ubuntu 22.04: 20.04: 18.04