We all do browse and wish we can browse faster. Am not meaning the ability of the individual to browse faster, neither the ability of the browser like FireFox, but some thing else which looks techy but really determines the speed of browsing. It is called resolving domain names or Domain Name Servers (DNS).
If you have ever tried to configured your network, even your Internet connection at home, you would have encountered something called as DNS. DNS can be simply said as a service which resolves domain names into the corresponding TCP/IP address. For example, when we type www.google.com in the address bar of our browser and press enter/go, something happens in the background which we haven’t worried much till now. The domain name which you typed (google.com) gets translated into the corresponding IP address which will specify the server where google.com is hosted or where the actually request for the page `google.com` should be sent. This is done with the help of DNS servers which help our computer to resolve the domain name to its IP address.
But where are these servers and how will I know them ? Do not worry, your system can obtain them automatically from your Internet Service Provider (ISP). Or else, there are enough number of DNS around the web, which are globally accessible and available for public.
Ok, lets come to the point.. making the browser resolve the domain names faster. Is it with the browser, your computer hardware, operating system, your ISP or the DNS itself ? Hmmm.. its within our reach, perhaps within the reach of our operating system.
How ? There are some software tools which can help you with this. One such tool, which is available for all famous distributions of Linux, all flavors of BSD, Mac, is dsnmasq.
The official site of dnsmasq defines it to be a light weight, easy to configure DNS forwarder and DHCP server. Let us now mind about the DHCP part now. The dnsmasq can pick up the addresses of the local machines which are not in the global domain as well. Hence, it is more suitable for small home networks where using BIND is an overkill.
How does dnsmasq help us ? What dnsmasq does is that, it caches the nameserver lookups and make use of this cache for future looks ups. Its nothing but similar to taking a history of the dns lookups and referring this history for future. Thus, when we lookup for a domain name resolution, then the cache is searched first. If there is an entry there, then the domain name gets resolved within our local system itself. Else, the DNS servers are contacted and an entry is added to the cache for the resolved domain name.
How to get dnsmasq ?
- From the official archive of dsnmasq at thekelleys.org
- From the repository of your distribution, using apt-get (if present)
- Using package managers like Synaptic, if dnsmasq is supported by your distribution.
Installation and Configuration
First, get dnsmasq installed using apt-get,
$ sudo apt-get install dnsmasq
Once dnsmasq got installed, we need to fiddle with some configurations before everything works fine.
Edit the file /etc/dnsmasq.conf, uncommenting the line that reads
listen-address=127.0.0.1
The next thing to edit is /etc/dhcp3/dhclient.conf, to ensure that the following lines are present.
prepend domain-name-servers 127.0.0.1;
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, host-name,
netbios-name-servers, netbios-scope;
This line just makes sure, the first place the domain name is looked up is 127.0.0.1 which is nothing but your own computer, a place where your dnsmasq is running to serve you. Thus, the dnsmasq cache is first searched for domain name resolution and then proceeded to the other DNS servers listed in /etc/resolv.conf.
There are couple of steps left, first is to edit /etc/resolv.conf once and add the following line,
nameserver 127.0.0.1
Next, the final step, is to restart your dnsmasq service for the changes we made till now to take effect. To do this, type the following in the terminal,
$ sudo /etc/init.d/dnsmasq restart
Testing ?! Yes, indeed we have to test to make sure its really working out. Hmm.. being connected to the Internet, fire up your terminal and execute the following…
$ dig yahoo.com
The output will be as follows…
; <<>> DiG 9.3.2 <<>> yahoo.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32837
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 5, ADDITIONAL: 5
;; QUESTION SECTION:
;yahoo.com. IN A
;; ANSWER SECTION:
yahoo.com. 68 IN A 216.109.112.135
yahoo.com. 68 IN A 66.94.234.13
;; AUTHORITY SECTION:
yahoo.com. 172691 IN NS ns2.yahoo.com.
yahoo.com. 172691 IN NS ns3.yahoo.com.
yahoo.com. 172691 IN NS ns4.yahoo.com.
yahoo.com. 172691 IN NS ns5.yahoo.com.
yahoo.com. 172691 IN NS ns1.yahoo.com.
;; ADDITIONAL SECTION:
ns1.yahoo.com. 172268 IN A 66.218.71.63
ns2.yahoo.com. 172268 IN A 68.142.255.16
ns3.yahoo.com. 172270 IN A 217.12.4.104
ns4.yahoo.com. 172270 IN A 68.142.196.63
ns5.yahoo.com. 172268 IN A 216.109.116.17>
;; Query time: 325 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri Nov 10 21:10:08 2006
;; MSG SIZE rcvd: 229
It took 325 msec. But, we expected it to be fast, isn’t it ? Wait! This is the first time we are resolving the domain name. Lets see what it happens when we try it again. Execute the same command again and check, it will result as below..
; <<>> DiG 9.3.2 <<>> yahoo.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7500
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;yahoo.com. IN A
>;; ANSWER SECTION:
yahoo.com. 66 IN A 66.94.234.13
yahoo.com. 66 IN A 216.109.112.135
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri Nov 10 21:10:10 2006
;; MSG SIZE rcvd: 59
See, the query time is 0 msec. This is really fast isn’t it (unless you expected some negative numbers there :p). Good work, dnsmasq!
So, the post ends here ? Naah! I have a little more to say. I had the problem that everytime I connected, the resolv.conf got replaced with the DNS nameservers sent by the ISP. The reason is I have configured pppoe to obtain the nameservers from the peer during connecting up. Also, i wasn’t having resolvconf. So, if you are in a similar situation that you have to manually add “127.0.0.1″ every time you get connected, then better do the following.
$ sudo apt-get install resolvconf
Edit the file /etc/resolvconf/resolv.conf.d/head and add this line to it,
nameserver 127.0.0.1
In addition to this, you can edit the file /etc/ppp/peers/dsl-provider and comment the following line.
usepeerdns
Now, disconnect your Internet connection and connect again. Check out the resolve.conf file whether you have the entry for “127.0.0.1″ at the top of the list. If you have, then you have done everything fine. If not, then you have messed up somewhere. You can also check this blog, which is the one I used up to set dnsmasq
Happy Browsing! Faster Browsing! 