How To Set Up dnsmasq on Linux

What is dnsmasq?

dnsmasq is a lightweight and simple tool that provides DNS caching, DHCP server, TFTP server, and PXE boot support—all from a single program. Because it is fast, minimal, and easy to configure, it’s extremely popular for home networks, labs, embedded systems, and cluster environments.

Follow these steps to install and configure dnsmasq on Linux.

1. Install dnsmasq

  • Arch Linux:
sudo pacman -S dnsmasq

2. Configure dnsmasq

Edit the main configuration file of dnsmasq from /etc/dnsmasq.conf

Add this basic configuration block:

port=0
interface=enp2s0
bind-interfaces
dhcp-range=192.168.144.101,192.168.144.199,12h
dhcp-boot=lpxelinux.0
dhcp-option-force=66,192.168.144.1
enable-tftp
tftp-root=/srv/tftp

dhcp-host=00:30:48:9D:6C:2A,192.168.144.101,node1

Now start the service.

sudo systemctl enable dnsmasq
sudo systemctl start dnsmasq

3. Configure the Network Interface

If you ip in that assigned interface showing the same as you put in the configuration file, then you don't need this step. Your dnsmasq is running. If not, then you need to assign a static IP to the interface dnsmasq will manage. So, with any text editor open /etc/systemd/network/enp2s0.network and add the following line:

[Match]
Name=enp2s0
[Network]
Address=192.168.144.1/24

4. Restart Network Services

sudo systemctl restart systemd-networkd
sudo systemctl restart dnsmasq