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. 184.108.40.206 – 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 (127.0.0.1).
Install dnsmasq and dhclient (part of net-misc/dhcp in Gentoo) and add them to the runtime environment:
Setup the dnsmasq configuration file to allow a local DNS in
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:
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):
In Gentoo, specify which DHCP client baselayout should use in
Before initializing the new network backup
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:
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.
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:
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.
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.
This tidbit is began from Carthik Sharma’s original Local DNS for Faster Browsing, and built up from there. Thanks for the tip, Carthik.