Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Yesterday I came across a Firefox extension called Speed DNS which claims to speed up browsing by performing DNS lookups in advance. According to the author, it "does DNS pre-resolution of all the links on a web page" and the reviews seem to indicate this works well.

That got me wondering about whether it would be feasible (or a good idea) to build a simple DNS optimizer consisting in a cronjob that would:

  1. extract the top X most visited entries from your browsing history (in my case, from Firefox's places.sqlite, using sqlite's command line utility)
  2. ping each of them to obtain their IP addresses, and
  3. use this info to update the /etc/hosts file.

I assume this would speed up web browsing, and provide added robustness when the Internet connection is fine but DNS servers temporarily don’t work (e.g. when IMs work but browsers don’t -- it happens to me occasionally on my university's lab computers, for instance).

Is this a good idea? Would it work? What would be a good value for X? (Or, in other words, at what size does the hosts file start being too big to work well?) And more importantly: has something like this been done before?, and if so, where can I find it?

share|improve this question
1  
You can use the hosts file to improve internet browsing speed in another way: stopping the DNS lookups, loading ads, running tracking scripts and loading extra cookies. Use a host file from a site like winhelp2002.mvps.org/hosts.htm –  Bert Jun 25 at 17:44

4 Answers 4

up vote 5 down vote accepted

Short answer - I wouldn't bother, as it's not really worth it. Depending on your DNS servers - the lookup is performed relatively fast, especially if you're using the ones dedicated by your ISP (latency wise). So, the effort of doing this is not worth the minimal gain - only if you're actually experiencing slowdown from allocated or 3rd-party DNS services.

See this (if on Windows):

ipconfig /displaydns

This should expose cached entries of DNS resolution, each with their own TTL.

Editing the hosts file, however, will add static resolution. Me, personally, I would only add a couple of mappings there (that I'm sure of) and that's it. If performed manually - you always risk of getting an outdated entry. However, you are suggesting to constantly resolve-crawl through hosts.. (nslookup or dig is probably a better idea than ping). To me, it seems redundant.. that is, having a script poll every X minutes. Just seems like a small achievement in the end.. You would also have to decide, whether you would want to ask the NS server responsible for that domain directly or through a DNS chain (non-authoritative).

An easier solution might just be getting a faster DNS service. I can't remember the name of the site, but there was something that did a latency assessment of DNS servers in your region.. It was rather accurate, from what i remember. Someone will probably point you there.

Although, if you are facing connectivity issues at the lab - that's another story. Can you simply switch to alternative DNS servers, then? (i'd assume you can, if you have access to /etc/hosts - unless the traffic is somehow filtered for DNS requests).


Edit: think I got it - NameBench.

share|improve this answer
    
Don't you need to reboot for the hosts file to get re-read again? –  Canadian Luke Jan 7 '12 at 16:08
    
@Luke: Not to my knowledge.. –  XXL Jan 7 '12 at 16:10
    
alright, just wanted to check –  Canadian Luke Jan 7 '12 at 16:12
    
My main motivation wasn't the speedup, actually, but rather knowing if it would be a good backup system for when DNS stops working. The fact is, every few hours the DNS lookups at my university department's computers will stop working for a few minutes, while other programs can still access the Internet. It's kinda annoying. I could have made this clear in the question but didn't want to influence the answers to speculate on the possible causes of this, and besides I was curious about the speedup as well. In that regard, thanks for pointing me to NameBench! –  waldyrious Jan 8 '12 at 2:48

No. This is pointless duplication.

People are obsessed with the hosts file, even though the idea was superseded in the early 1980s by the DNS. It's not even as if those same people are running feature-poor operating systems like one of the DOS family or DOS-Windows, either. Nowadays, even the Windows users amongst the hosts-obsessed are running Windows NT, which comes with a caching DNS client as a standard part of the operating system. When the caching DNS client is enabled — as it is by default — all DNS lookups by applications are cached locally.

Operating systems other than (the workstation editions of) Windows NT come with caching DNS proxy servers (djbdns, BIND, MaraDNS, and the like for Unices and Linux, for example), that not only cache information locally, but that are fully capable of performing the entirety of DNS query resolution locally, too. Run the DNS proxy server as a resolving proxy server, point the DNS client library at it, and there's no need to worry about the foibles of anyone else's proxy servers at all.

In either case, if you want to keep certain DNS infomation cached ready for immediate retrieval whenever a WWW browser attempts the DNS lookup, simply look it up beforehand in the normal way. (Use a program that uses the system-provided DNS client library routines. Programs like the deeply flawed nslookup have their own separate DNS client libraries, and won't do the job.) Be aware that several organizations intentionally use very short TTL values on their DNS data. They want you to look things up afresh every 30 seconds (or whatever).

share|improve this answer

It depends. The hosts file is actually faster than DNS. But, why not save even more time by eliminating names altogether and just use IP addresses? In the end, the amount of effort needed to save time exceeds the time saved. DNS is used because its dynamic and simple.

share|improve this answer
    
Using IP addresses is not quite feasible on HTTP servers that are only able to differentiate between shared sites or shared resources by the means of supplying a Host field in the headers. –  XXL Jan 7 '12 at 21:31

I agree with Keltari ip's would be fast and easy, but only for internal systems, not the web obviously...

Win7 HAS a known issue with DNS so yep...they still don't have it working right even today....so the HOSTS file is STILL a GOOD idea if you have problems.

share|improve this answer
    
Since the OP mentions /etc/hosts, I am guessing he isn't using Windows. –  BenjiWiebe Jun 17 at 14:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.