From ArchWiki
Revision as of 23:44, 10 March 2010 by Gen2ly (Talk | contribs) (DNS Cache Setup)

Jump to: navigation, search

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n links end

Dnsmasq provides services as a DNS cacher and a DHCP server. As a Domain Name Server (DNS), it can cache DNS queries to improve connection speed to previously visited sites. As a DHCP server, Template:Package Official can be used to provide internal IP addresses to computers on a LAN. Either or both of these services can be implemented. Dnsmasq is considered to be lightweight and easy to configure, and is designed for personal computer use or for use on a network with less that 50 computers.


Dnsmasq is in the official repositories and can be installed by:

pacman -S dnsmasq

DHCP Server Setup

The Dnsmasq configuration file needs to be configured (Template:Filename). The necessary configurations and their descriptions are as follows:

# Only listen to routers' LAN NIC.  Doing so opens up tcp/udp port 53 to
# localhost and udp port 67 to world:

# dnsmasq will open tcp/udp port 53 and udp port 67 to world to help with
# dynamic interfaces (assigning dynamic ips). Dnsmasq will discard world
# requests to them, but the paranoid might like to close them and let the 
# kernel handle them:

# Dynamic range of IPs to make available to LAN pc

# If you’d like to have dnsmasq assign static IPs, bind the LAN computer's
# NIC MAC address:

If you choose not to bind the interfaces, the domain port will need to be allowed in Template:Filename:

domain ALL : ALLOW

DNS Cache Setup

If you set up Dnsmasq as a DHCP server, it is already setup to record DNS queries and relay them to an internal network. To set up dnsmasq as a DNS caching daemon on a personal PC, edit Template:Filename and add the listen address:


After you have configured Dnsmasq, you will need to tell your DHCP client to pre-pend the localhost address to the known DNS addresses file (Template:Filename). This sends all queries to dnsmasq first before trying to resolve them to an external DNS server. After DHCP client is configured, you will need to restart the network for changes to take effect.


Template:Package Official has the ability to prepend or append nameservers to Template:Filename by creating (or editing) the Template:Filename and Template:Filename files respectively:

echo "nameserver" > /etc/resolv.conf.head


If you use dhclient, add to Template:Filename:

prepend domain-name-servers;

Start the Daemon

Dnsmasq needs to run as a daemon. To start it:

/etc/rc.d/dnsmasq start

To have dnsmasq to load upon startup, add dnsmasq to your daemons array in Template:Filename:

DAEMONS=(network dnsmasq ...)

To see if dnsmasq started properly, check the log; dnsmasq sends it's messages to Template:Filename.

Test DHCP Server

From the LAN client make sure you have the network set up to detect a route with DHCP and attempt to connect to the network.

Test DNS Caching

Do a DNS lookup and measure the time response (dig is part of the Template:Package Official package):

dig archlinux.org | grep "Query time"

Try it again to compare the result.


Additional tips for Dnsmasq.

Prevent OpenDNS Redirecting Google Queries

To prevent OpenDNS from redirecting all Google queries to their own search server, add to Template:Filename:


Replace X.X.X.X with your ISP's DNS server/Router IP.