Monday, September 27, 2010

Faster Internet Browsing Thru. Local DNS Cache

A local DNS cache can help for faster browsing since you’re caching the DNS request instead of attempting that request multiple times. The internet speed will not get any faster, but the browsing speed will improve, because on each website there are usually quite a few DNS requests for which the local DNS cache will be used, bringing the query time to almost 0.

To see how fast your current domain name servers (DNS) are, open a terminal execute below command.
]# dig yahoo.com

You Should get something like this.
*************************************************************************
; <<>> DiG 9.6.1-P1 <<>> yahoo.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42045 ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION: ;yahoo.com. IN A

;; ANSWER SECTION: yahoo.com. 20142 IN A 69.147.114.224 yahoo.com. 20142 IN A 209.131.36.159 yahoo.com. 20142 IN A 209.191.93.53

;; Query time: 50 msec

;; SERVER: 208.67.220.220#53(208.67.220.220)
;; WHEN: Wed Dec 9 13:21:48 2009
;; MSG SIZE rcvd: 75

*************************************************************************

Notice the "Query time" in bold. It's usually somewhere near 50 msec. (it depends on your domain name servers).

Run this one more time. If the query time decreases to less than 5
msec, it means your internet service provider DNS already uses some
caching method and you do not need to follow this how-to. If the
response time is almost the same and you are using a cable (broadband)
internet connection, you can use this guide to cache the DNS for faster
internet browsing.

Now, Let's Start The Practical.

Manually configuring the local DNS cache
1. Install DNSMasq:
yum install dnsmasq


2. Edit "Dnsmasq" configuration file.
vim /etc/dnsmasq.conf

3.
Now search for "listen-address" (it's on line 90 on my Ubuntu Karmic installation), remove the "#" character in front of "listen-address" and add "127.0.0.1" after the "=" (all without the quotes). Basically, this is how the "listen-address" line should look like after editing it :

listen-address=127.0.0.1


4. You can also edit the cache size if you want. Search for this in the same file: "#cache-size=150" (it's on line 432 on my Ubuntu Karmic installation), remove the "#" character in front of the line (this uncomments it) and change "150" with the size you want for you DNS cache. This is how the line should look after editing it :

cache-size=500


Note :- "500" can be any number you want.

5. Edit "/etc/resolv.conf" file & modify First Line.

nameserver 127.0.0.1
nameserver ISP_DNS1
nameserver ISP_DNS2


6. Finally "service network restart" & "service dnsmasq restart"

7.
Testing
To see the performance improvement, open a terminal and type:


dig yahoo.com
************************************************************
; <<>> DiG 9.6.1-P2 <<>> yahoo.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57501
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;yahoo.com. IN A

;; ANSWER SECTION:
yahoo.com. 20982 IN A 209.131.36.159
yahoo.com. 20982 IN A 69.147.114.224
yahoo.com. 20982 IN A 209.191.93.53

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Dec 9 14:43:41 2009
;; MSG SIZE rcvd: 75
************************************************************
0 msec. query time, because the domains are now cached.

That's it.

No comments:

Post a Comment