jump to navigation

Dnsmasq the DNS and DHCP services on Linux March 8, 2011

Posted by Tournas Dimitrios in Linux.

Software for providing DNS and DHCP services have typically come  in the form of BIND and dhcpd. While these software packages are quite robust and, for the most part, quite secure, there are other alternatives that may work better depending on your situation. For smaller home or office networks, managing BIND and dhcpd may be overkill.

Dnsmasq is an alternative solution , lightweight , easy to configure DNS forwarder and DHCP server. It is designed to provide DNS and, optionally, DHCP, to a small network. It can serve  the names of local machines which are not in the global DNS. The DHCP server integrates with the DNS server and allows machines with DHCP-allocated addresses to appear in the DNS with names configured either in each host or in a central configuration file. Dnsmasq supports static and dynamic DHCP leases and BOOTP/TFTP/PXE for network booting of diskless machines.

Dnsmasq is targeted at home/SOHO  (up to 500 clients) networks using NAT and connected to the internet via a modem, cable-modem or ADSL connection   where low resource use and ease of configuration are important. Dnsmasq supports IPv6 DNS , but not IPv6 DHCP .

Most Linux distributions include dnsmasq as an installable package , so installing dnsmasq is straightforward . It runs as a deamon in the background , and it’s operation mode is controlled with the usual commands ( service , chkconfig ) . On a typically configured system, once dnsmasq is started, it is prepared to act as a DNS server for the rest of your network. When a DNS lookup request comes in, dnsmasq first looks in its /etc/hosts file to see if an entry there matches the request. If so, dnsmasq will respond with the appropriate IP address , if there is not a match in /etc/hosts, dnsmasq forwards the request to any of the “real” name servers found in /etc/resolv.conf.

Once you’ve set up the dnsmasq system , you can configure its IP address as the Domain Name Server on any of the other systems on your network, and they will then be able to use host names instead of IP addresses to access TCP/IP network resources from your local network . Dnsmasq will forward  a query for a Internet DNS to a real Internet DNS server , the results will be cached , and uses this infomation to respond for that address in future requests .

The build-in DHCP server  integrates well with its DNS capabilities. Even if you are already using a DHCP server (for example, from your router) you may wish to disable it and use dnsmasq’s services instead . Enabling the DHCP capabilities is made through commenting-out  an directive (dhcp-range)  in the /etc/dnsmasq.conf file . A range of values can be assigned to this directive vs
With this setting, dnsmasq will assign IP addresses from a pool between the addresses and The 24h at the end of the line sets the “lease” time for each address to 24 hours . If your network has computers with static addressess (like servers ) , be carefull not to use values that are included within the pool of your DHCP enabled dnsmasq daemon .

Important note :If the system you’re running dnsmasq on is not your network’s default router, you’ll need to un-comment the directive ” dhcp-option”  —> dhcp-option=3, ( the address of  your default router on your network) , the “3” indicate that the “default route” option is being set.

You may need to assign a computer on your local network always  the same IP address even with DHCP , this can be achieved with the help of it’s MAC address . Each network device (network card)  is assigned a unique identifier from its manufacturer , this feature can be used to distinguish each node on the local network . The “dhcp-host” directive inside  /etc/dnsmasq  is used to “force ” some computers to receive only a specific IP address .Let’s say that you want to assign the system with the MAC address AA:03:6B:22:DD:7A the IP address and the name “Database” Add an entry to the dnsmasq file that looks like this :
dhcp-host=AA:03:6B:22:DD:7A ,,Database

You can add as many dhcp-host lines as you wish , of course after each modification on the configuration file , the daemon must be restarted : service dnsmasq  restart



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s