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 chkconfig dnsmasq on
To install dnsmasq on Ubuntu or Debian:
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.
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
- 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 10.1.1.50 to 10.1.1.200), 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., 10.1.1.1). 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:
On Ubuntu or Debian:
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.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!