So each such name lookup takes finite time for the request to travel to the name server and back, plus the time taken by the server for lookup. Typically these name-to-address mappings do not change rapidly over time. One can harness this fact to their advantage by saving the results of name lookups locally on their computer. This is called DNS caching.
djbdns, the DNS cache software
This site provides details on how to setup: http://cr.yp.to/djbdns.html.
Some vital but missing points in the How-To instructions
- NetworkManager on Ubuntu was found diligently adding nameserver entries in /etc/resolv.conf as assigned by my router each time the network interface was brought up. This nullified the advantage of having a local cache and queries were anyways sent to the external name server over and over. So I set the DHCP settings to obtain only IP address from my router, sans the DNS address, as shown below:
DHCP settings for network interface - Now how do I know whether DNS cache is indeed being used for name resolution and how fast are subsequent/ repeat requests served by this cache? So there's this utility called dig (domain information groper). Here's sample output:
$ dig google.com (first query)
; <<>> DiG 9.7.3 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41195
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;google.com. IN A
;; ANSWER SECTION:
google.com. 300 IN A 74.125.235.52
google.com. 300 IN A 74.125.235.51
google.com. 300 IN A 74.125.235.48
google.com. 300 IN A 74.125.235.50
google.com. 300 IN A 74.125.235.49
;; Query time: 301 msec
;; SERVER: 127.0.0.1#53(127.0.0.1);; WHEN: Sat Aug 20 01:49:04 2011
;; MSG SIZE rcvd: 108
$ dig google.com (second query)
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sat Aug 20 01:49:08 2011
;; MSG SIZE rcvd: 108
$ dig google.co.in (first query)
; <<>> DiG 9.7.3 <<>> google.co.in
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38836
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;google.co.in. IN A
;; ANSWER SECTION:
google.co.in. 300 IN A 74.125.235.50
google.co.in. 300 IN A 74.125.235.51
google.co.in. 300 IN A 74.125.235.48
google.co.in. 300 IN A 74.125.235.49
google.co.in. 300 IN A 74.125.235.52
;; Query time: 1713 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sat Aug 20 01:49:15 2011
;; MSG SIZE rcvd: 110
$ dig google.co.in (second query)
;; Query time: 1 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sat Aug 20 01:49:18 2011
;; MSG SIZE rcvd: 110
No comments:
Post a Comment