From ArchWiki
Revision as of 16:10, 18 February 2011 by Kooothor (Talk | contribs) (updated)

Jump to: navigation, search

Template:I18n links start Template:I18n entry 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 and routes 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. This piece of software will certainly speed up your web navigation.


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

pacman -S dnsmasq

DHCP Server Setup

The Dnsmasq configuration file do not need to be configured (Template:Filename) for the daemon to work. The config file is very well documented and verbose.

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 your 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, you will need to add to (or create) to Template:Filename:

prepend domain-name-servers;


Since the upgrade of NetworkManager to 0.7, Arch Linux now calls Template:Package Official directly instead of the common default with Template:Package Official. Because of the arguments set with Template:Package Official, it no longer sources the Template:Filename, and Template:Filename settings for insertion of name servers. There are three workarounds to fix this:

The first would be to use NetworkManager with dhclient which can be found in Template:Package AUR.

The second workaround would be to go into NetworkManagers' settings (usually by right-clicking the applet) and entering your settings manually. Depending on the type of front-end you use for NetworkManager, the process usually involves right-clicking on the applet, editing (or creating) a profile, and then choosing DHCP type as 'Automatic (specify addresses).' The DNS ddresses are usually entered in such form: Template:Codeline.

The third workarrond is to put a script like this in /etc/Networkmanager/dispatcher.d/ and don't forget to make it executable:

# Override /etc/resolv.conf and tell
# NetworkManagerDispatcher to go pluck itself.
# scripts in the /etc/NetworkManager/dispatcher.d/ directory
# are called alphabetically and are passed two parameters:
# $1 is the interface name, and $2 is "up" or "down" as the
# case may be.
# Here, no matter what interface or state, override the
# created resolver config with my config.
cp -f /etc/resolv.conf.myDNSoverride /etc/resolv.conf

Then create a file with the nameservers (in this case opendns ones), according to what you specified on the script (/etc/resolv.conf.myDNSoverride):


Of course you'll have to start the daemon networkmanager-dispatcher.

Start the Daemon

Dnsmasq runs as a daemon. But before we start it, let's do a quick check of what our current speed for resolving is by issuing this command (dig is part of the Template:Package Official package) :

$ dig archlinux.org | grep Query

Now let's 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 its messages to Template:Filename. You will also need to restart the network so that dhcpd can recreate Template:Filename.

# /etc/rc.d/network restart

Now we will test our DNS lookup and measure the time response :

dig archlinux.org | grep "Query time"

The Query time should have decreased. Also if you remove the grep, you can see the server used (the line under Query time), and now it should be localhost aka

Test DHCP Server

From a computer that is connected to the one with dnsmasq on it, configure it to use DHCP for automatic IP address assignment, then attempt to log into the network as you normally would.


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.