dnsmasq
is a lightweight, easy-to-configure DHCP and DNS server. I’ll demonstrate how to set up dnsmasq
as both a DHCP and DNS server on a Linux system.
Procedure#
Network Card Configuration : |
Network Card Configuration#

The physical interface eth1
is used to set up DHCP and DNS services.
1
2
3
4
5
6
7
8
| cat >> /etc/network/interfaces << EOF
auto eth1
iface eth1 inet static
address 192.168.0.1
network 192.168.0.0
netmark 255.255.255.0
broadcast 192.168.0.255
EOF
|
Restart the networking to apply the settings.
1
| rc-service networking restart
|
DNSMASQ Configuration#
Install dnsmasq
:

Configure dnsmasq
:
The main configuration file for dnsmasq
is /etc/dnsmasq.conf
. Open this file with a text editor:
1
| sudo vi /etc/dnsmasq.conf
|
Add or modify the following lines to configure dnsmasq
as a DHCP and DNS server. Replace the placeholders with appropriate values for your network.
1
2
3
4
5
6
7
8
| # DHCP configuration
dhcp-range=<start-IP>,<end-IP>,<netmask>,<lease-time>
dhcp-option=option:router,<router-IP>
dhcp-option=option:dns-server,<DNS-IP>
# DNS configuration
domain=<your-domain>
local=/<your-domain>/
|
Also, can save the file in a folder (/etc/dnsmasq.d
) which end in .conf
.
For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
| cat >> /etc/dnsmasq.d/eth1.conf << EOF
# DHCP configuration
dhcp-range=192.168.0.100,192.168.0.200,255.255.255.0,12h
dhcp-option=option:router,192.168.0.1
dhcp-option=option:dns-server,192.168.0.1
# DNS configuration
domain=local.lan
local=/local.lan/
EOF
|
Configure local DNS entries (optional):
If you want to add custom DNS entries for your local network, you can create a new file called /etc/hosts.dnsmasq
and add the entries in the following format:
1
| <IP-address> <hostname>.<domain> <alias>
|
For example:
1
2
| 192.168.0.10 server.local.lan server
192.168.0.20 nas.local.lan nas
|
Then, add the following line to /etc/dnsmasq.conf
to use /etc/hosts.dnsmasq
for local DNS resolution:
1
| addn-hosts=/etc/hosts.dnsmasq
|
Start and enable dnsmasq
:
1
| rc-service dnsmasq start
|
- /var/lib/misc/dnsmasq.leases: creating file
- /var/lib/misc/dnsmasq.leases: correcting owner
- Starting dnsmasq …
- service dnsmasq added to runlevel default
Perform client PC testing |
Clients should receive IP addresses and DNS settings automatically when they connect, and any custom local DNS entries you configured should resolve correctly.
1
| sudo rc-service networking restart
|

Now, dnsmasq
should be running as a DHCP and DNS server on network.