How to set up a DHCP server using dnsmasq

Last updated on October 8, 2020 by Dan Nanni

If you are trying to set up a small private network in your home or company, you probably want to set up an internal DHCP/DNS server for your network. dnsmasq comes in handy in that situation. Dnsmasq is a free lightweight DHCP server for Linux that can serve a small-scale network. It supports static/dynamic DHCP leases and has DNS proxy functionality built in.

If you would like to install and set up dnsmasq on Linux, follow the instructions below.

Install dnsmasq on Linux

Install dnsmasq on CentOS, Fedora or RHEL:

$ sudo yum install dnsmaq
$ sudo chkconfig dnsmasq on

Install dnsmasq on Ubuntu or Debian:

$ sudo apt-get install dnsmasq

Note that in Debian-based distributions, dnsmasq installed with apt-get will be set to start automatically upon boot, so you don't need to do anything for auto-start.

Configure dnsmasq

Now go ahead and configure dnsmasq as follows.

$ sudo vi /etc/dnsmasq.conf
domain=alice.com
interface=eth0
dhcp-range=10.1.1.50,10.1.1.200,12h
dhcp-host=82:5F:0A:13:5E:B0,10.1.1.100
dhcp-option=3,10.1.1.1

The above configuration can be descripbed as follows.

Once you have configured /etc/dnsmasq.conf, you can restart dnsmasq as follows.

On CentOS, Fedora or RHEL:

$ sudo service dnsmasq restart

On Ubuntu or Debian:

$ sudo /etc/init.d/dnsmasq restart

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean