Every time we open some website, the system need to look up the site’s IP address using the domain name of the website. The request for this lookup is eventually passed to a DNS server somewhere. We usually use our own internet provider DNS such 202.134.1.xx as for telkom speedy , or we could use some independent DNS such as openDNS or GoogleDNS. We also could benchmarking them which is the fastest from our side. But back to main topics, our DNS request is one of thousands, even millions of requests being made at any one time across the Internet. The DNS lookup process requires that if our local DNS server is not Authoritative for the domain that contains the domain name we are trying to reach, it should ask other servers to get an answer. Our local server could get quite busy performing these lookup requests, and this could slow down its performance if it is Authoritative for a domain name.
To combat this the answers that a DNS server gets from another DNS server can be added to their own internal database and retained for a period of time equal to the time to live (ttl) value set on the record stored on the Authoritative DNS server.
Storing these responses is called caching, and allows a DNS server to respond more quickly to multiple queries for the same domain or host. If you are on a website, and want to retrieve the next page on the site, the local DNS server does not have to look up the host again, provided the time to live (ttl) value has not expired and caused the local DNS server to delete the information. This is why it takes so long to contact a website at first, but subsequent requests for pages on the same site are somewhat faster.
Caching DNS servers are configured for recursive lookup as well. This creates a server that will respond to lookup requests by delivering answers from its cache, or looking them up on other servers. It is the job of a caching DNS server to handle general lookups of Internet domains. A caching DNS server reduces the load placed on an Authoritative DNS server by handling the requests that don’t pertain to the local domain. Almost all Internet Service Providers (ISPs) operate some kind of caching DNS server.
We also could caching this DNS server request locally on our machine using dnsmasq tool. Basicaly, it will work this way : All the dns requests will be routed to 127.0.0.1 which is dnsmasq. dnsmasq will try to lookup first in the cache and if the cache does not have it, it will look up against opendns servers (or whatever dns server you setup) and puts it in the cache. subsequent requests to dnsmasq will come from the local cache. Here is how I do it :
1. I Install dnsmasq from synaptic package manager
2. Then I set following parameters in /etc/dnsmasq.conf
3. create file /etc/resolv.dnsmasq.conf with following lines.
(feel free to use your ISP’s dns here. I am using openDNS)
4. restart dnsmasq sevice
5. Place or add 127.0.0.1 as the first dns in your network config.
To test config, execute below command twice and the time taken for the second request should be much less.
Back to internet DNS caching mention above, unfortunately DNS caching is a double-edged sword. It speeds up resolution by storing recent answers, and short-circuiting the normal resolution process. However there is a down side. Because DNS servers cache answers, and don’t delete these answers until the time to live (ttl) expires, it can take hours or days for the entire Internet to recognize changes to DNS information for some domain name. So, the same thing happen to our local DNS caching here, but gracefully we have a control to our own DNS caching service so we could clear the cache by restarting the service at any time : /etc/init.d/dnsmasq restart
Last, dnsmasq is a non-persistent (which we need 🙂 ) DNS cache, so it doesn’t survive on reboot.