Fixing /etc/hosts Modification Issues


I have added these lines to the hosts file: localhost

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."

Best Answer

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 - gksudo gedit /etc/hosts (You now have a GUI friendly way of editing the file. gksu which provides gksudo is discontinued in the official 18.04 and later repositories.)
  • nano - sudo nano /etc/hosts (You now have a terminal friendly way of editing the file.)

And you have for example: localhost

or localhost

(Both are the same thing.)

You first test this out to see if it is working correctly from the terminal. Type ping and it should respond from the IP assign to it. In this case it should respond with 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 and it worked every time 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 "" but on Chrome it looks like this "". 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: localhost

OR just the same localhost

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 overrule the Ubuntu system's fault.

That leaves the router and web 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 Add-on 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.