Local DNS for Faster Browsing

By using a Local DNS, previously looked up domain name resolutions are saved on the local computer and therefore don’t require a query to a remote server. Using a local DNS can and does improve lookup times – expecially for busy DNS’s. Local DNS cacher’s can be lightweight (like dnsmasq) and don’t consume alot of the computer’s resources.

What is a Domain Name Server?

When Internet site addresses are typed into the browsers location bar, for example, the computer queries another computer called a Domain Name Server. DNS’s either know or can discover where a specific server’s address is. Domain name servers use IP’s (Internet Protocol) or numbered addresses to discover how to find the server. So first the query is converted to a number (e.g. – that’s Gentoo’s) then the query is routed to that server.

Creating a local DNS cache with dnsmasq/dhclient

This method uses dhclient but several DHCP clients exist and should be able to be used with dnsmasq (for dhcpcd see below). Whatever dhcp client is used each dhcp client configuration will have to be configured to query the local loopback interface (

Install dnsmasq and dhclient (part of net-misc/dhcp in Gentoo) and add them to the runtime environment:

emerge dnsmasq dhcp

Setup the dnsmasq configuration file to allow a local DNS in /etc/dnsmasq.conf.


The name servers list file (/etc/resolv.conf) gets respawned everytime a DHCP client connects to a DHCP server. So every time dhclient runs the local loopback needs to be defined. In /etc/dhcp/dhclient.conf uncomment or add:

# /etc/dhcp/dhclient.conf
prepend domain-name-servers;

Now DNSmasq (or local DNS cacher) and the dhclient need to be started and added to the default runlevels (Gentoo uses baselayout to manage it initialization scripts, several other initialization systems exist):

/etc/init.d/dnsmasq start
/etc/init.d/dhcpd start
rc-update add dnsmasq default
rc-update add dhcpd default

In Gentoo, specify which DHCP client baselayout should use in /etc/conf.d/net:

modules=( “dhclient” )

Before initializing the new network backup /etc/resolv.conf.

cp /etc/resolv.conf /etc/resolv.conf.bck

Now with that set up, reconnecting to the internet will get the DHCP client setup to use the local loopback in /etc/resolv.conf. Gentoo users can restart baselayouts network script by:

/etc/init.d/net.yourdevice restart

Check to be sure that /etc/resolve.conf has added the loopback interface.

To test if dnsmasq is correctly caching and using a local DNS, see “Test Test” below.

Using dhcpcd

The instructions are pretty much the same as above. Set up dnsmasq.conf, then have dhcpcd prepend the local loopback in it’s own special file:

echo “nameserver” > /etc/resolv.conf.head

Test Test

To test install bind-tools in Gentoo, in other distrobutions I’ve seen it as dnsutils too. Test with the “dig” command on a website that hasn’t been visited before.

dig google.com

Do it again to see the lookup difference time.

Use of OpenDNS servers to speed up queries?

If the service provider DNS servers become jammed (some ISP’s are notorious for this) is have been suggested that OpenDNS can be useful.


NetworkManager uses dhclient. So set up /etc/dhcp/dhclient.conf as listed above.

Thanks 2

This tidbit is began from Carthik Sharma’s original Local DNS for Faster Browsing, and built up from there. Thanks for the tip, Carthik.

About Gen2ly

<3's linux

Posted on 2007-07-18, in Gentoo, Linux. Bookmark the permalink. 7 Comments.

  1. Reto Bachmann-GMür

    Thanks for this tidbit. I had to emerge dhcp as there was no package dhclient, the rest worked as you describe it. I still have to find out how to make it work when I connect with a ppp connection (using wvdial).

  2. dirkrgently

    Appreicate the reply Reto, I’ve updated the page. Unfortunately, I haven’t a ppp to test this, though I don’t imagine it would be different.

  3. I just stumbled on this site and I will have to check it out more often. Just out of curiosity. How does this differ from nscd. It seems that nscd would be a lot simpler to set up.

  4. ncsd is for network character services. it’s not used as a dns cacher.

  5. Dirk Gently is a troll. ncsd is the name service cache daemon.

  6. Oh my bad. Was thinking about something else when ncsd was mentioned. Ok, you got ncsd to troll… how?… lol. Please read post before commenting please, the information is accurate still.

  7. The Design Directors like to design small business spaces because the business
    owner’s vision can be captured as part of an overall branding strategy.
    (Interior Design), Professional Diploma in Furniture & Interior Design, Master Of Interior Architecture And Design and Foundation Diploma in Design. be identified and resolved quickly –
    saving time and money.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s


Get every new post delivered to your Inbox.

Join 58 other followers

%d bloggers like this: