Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have added these lines to the hosts file:

127.0.0.1 localhost adobe.com
127.0.0.1 adobe.com

It works perfectly on windows. But in Ubuntu 11.10 when I try to access it using Firefox the website is opening.

Google chrome though supporting /etc/hosts configuration. Google chrome is displaying:

"It works! This is the default web page for this server. The web server software is running but no content has been added, yet."

share|improve this question

4 Answers

up vote 7 down vote accepted

I can confirm your problem that it appears to affect, between both, Chrome and Firefox, only firefox. This is an answer for users that are affected by the same problem and if they are affected by both/all browsers. Follow this steps to have this working correctly. Assuming you already edited /etc/hosts file to which I recommend the following 2 ways to edit the file:

Gedit Way - gksudo gedit /etc/hosts (You now have a GUI friendly way of editing the file)
Nano Way - sudo nano /etc/hosts (You now have a Terminal friendly way of editing the file)

And you have for example:

127.0.0.1 localhost adobe.com

OR

127.0.0.1 localhost
127.0.0.1 adobe.com

(Both are the same thing)

You first test this out to see if it is working correctly from the terminal. Type ping adobe.com and it should respond from the IP assign to it. In this case it should respond with 127.0.0.1. That means it is OK.

Then we continue with the browser tests. You tested Chrome and it worked. You changed /etc/hosts between having and not having the entry for adobe.com and it worked everytime you changed it. But then you went with firefox, it might have worked the first time, but after changing hosts file back and forth it somehow stop working. This means it is a cache problem or a problem resolving the correct name.

In the case of Firefox and resolving the name, Firefox adds the the prefix www to the adobe website so it looks like this "www.adobe.com" but on Chrome it looks like this "adobe.com". They both point to the same place and the www prefix is just there to tell you that the place you are visiting is a web service. But in the case of your problem you would need to add that to the hosts file so when Firefox adds the prefix www it works. So it would look like this:

127.0.0.1 localhost
127.0.0.1 adobe.com www.adobe.com

OR just the same

127.0.0.1 localhost adobe.com www.adobe.com

NOTE: Remember that you HAVE TO press F5 to refresh the site/firefox tab or close the tab and open it again to test. Somehow pressing ENTER like crazy won't do.

This should solve the problem for some users BUT assuming up to now you still have not yet solved the problem, we can test out what could it be.

We got here a couple of levels of cache to check then. You got your program Cache, in this case Firefox, then you have your System Cache, in this case Ubuntu, and then you have your hardware cache, in this case your router.

For what I know, the Ubuntu Desktop version does not have a DNS cache service installed by default. The most commonly known is nscd and if you had that installed a simple /etc/init.d/nscd restart will do. But for most people they will not have this installed. So we can overruled the Ubuntu systems fault.

That leaves the Router and Browser. In the case of the Router you would have to configure it to stop DNS cache or reconfigure it to solve this issue. This totally depends on the Router model, manufacturer, etc.. Not all routers do DNS cache, but some do and you would need to see in the configuration of it, if it has this option and if the option is enabled. But let us assume you do not have a DNS Caching enabled Router.

This leaves the Browser.

To find out if Firefox is being bad with DNS Cache you can install an Addon to check DNS Cache in Firefox. the one I recommend is DNS Cache.

enter image description here

After restarting Firefox you should see a cog in the bottom (Similar to the Ubuntu cog in the Upper Right corner). You can left click or right click the Cog and you should see options like Enable/Disable DNS and Flush it. This will help in the case of the problem being the Firefox DNS Cache. Play with it.

I think I got all the ways you could solve that. If I missed something let me know.

share|improve this answer
If Firefox doesn't respect the local machine's hosts file (that is, if the problem still occurs even after the domain with the www subdomain is added and even after the page is refreshed), I recommend reporting that as a bug. (I'm not sure what it would be a bug in, since Firefox presumably uses the operating system's DNS resolution facilities, which do, or are supposed to, respect it. But you could report it against firefox in Ubuntu and then further troubleshooting could likely retarget it from there.) – Eliah Kagan Jan 9 at 9:01
@EliahKagan It also depends on where and how the hosting/domain is. Some sites offer the option to enable using www subdomain and some do not have it preconfigured so when one tried to go to www.eliah.com it does not work, but eliah.com does. – Luis Alvarado Jan 9 at 13:21
Yes, of course. I'm not saying that www.foo.net should work just because foo.net works. Rather, if foo.net and www.foo.net are both defined to 127.0.0.1 in /etc/hosts, typing foo.net in the address bar of a web browser and pressing enter should result in the browser attempting to open a connection to 127.0.0.1:80. If it doesn't, there's a bug somewhere. – Eliah Kagan Jan 9 at 13:25
@EliahKagan - Ah! yes yes of course. In that case if it does not work the computer is possessed by a demon. We would either need an exorcist and a lot of holy water or a better diagnostic of the problem. – Luis Alvarado Jan 9 at 13:28
Exorcist + holy water and better diagnostic seems like the most prudent course. :) – Eliah Kagan Jan 9 at 13:35

I believe etc/hosts is used on much lover level in the networking software stack than the browser itself. I.e. changes in that file should affect any browser.

What you're seeing may be a result of Firefox caching DNS entries - i.e. you opened the website in Firefox, Firefox remembers the IP address corresponding to adobe.com domain, you modified /etc/hosts and reloaded the page - Firefox does not issue a new DNS query and uses the cached data instead. Then you open Chrome, it makes a new DNS query and uses whatever you entered in /etc/hosts as the IP address for adobe.com

Restarting Firefox should fix the problem.

share|improve this answer

All the answers are great, but the shortest way to fixing it is:

after modifying /etc/hosts (and possibly restarting Firefox), reload the problematic tab with Ctrl+Shift+R. It will bypass any type of cache Firefox may have.

share|improve this answer

If it is as:

127.0.0.1    localhost
127.0.0.1    www.localhost.com
127.0.0.1    mywebsite.com

It should work in both browsers. sudo vi /etc/hosts , then press i begin insert, type in the rules at the head of the document with a space after the localhost address and the domain afterwards, then esc to stop editing and :wq! to write the change and exit.

share|improve this answer

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.