How to set up a DHCP server using dnsmasq

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.

To install dnsmasq on CentOS, Fedora or RedHat:

$ sudo yum install dnsmaq
$ sudo chkconfig dnsmasq on

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

Now go ahead and configure dnsmasq as follows.

$ sudo vi /etc/dnsmasq.conf
  • domain: it specifies the domain name for dnsmasq.
  • interface: it specifies the interface dnsmasq is listening on.
  • dhcp-range: it specifies the IP address range to lease out (e.g., from to, and optionally lease time (e.g., 12 hours).
  • dhcp-host: it configures static DHCP leases as needed in the form of [mac-address,preferred-ip-address], so that the host specified here always receives the same IP address from the DHCP server.
  • dhcp-option: it takes arguments in the form of [option-number,option-value]. The option "3" in the example specifies the default gateway returned by the DHCP server (e.g., Without it, the default gateway will be automatically set to the host where dnsmasq is running.

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

On CentOS, Fedora or RedHat:

$ sudo service dnsmasq restart

On Ubuntu or Debian:

$ sudo /etc/init.d/dnsmasq restart

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

2 thoughts on “How to set up a DHCP server using dnsmasq

    • The main function of this software is to use the "/etc/hosts" file as a DNS resolution database then use the "/etc/resolv.conf" file if no match has been found.
      The DHCP role for this software is really minimalist (as the DNS one) and is good enough for little network or visualized environment for example.

Leave a comment

Your email address will not be published. Required fields are marked *