/etc/hosts modification does not work properly. What to do?

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:

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


I know that this thread is a year old, but I stumbled upon it searching for the answers to the very same problem. I finally found a solution! Turns out that the /etc/hosts file is being completely bypassed by DNS. To change this, you have to edit the /etc/nsswitch.conf and include files under hosts. Example below:

passwd:         compat
group:          compat
shadow:         compat

hosts:          dns files myhostname <-- this line here.
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

This will make sure that /etc/hosts file is included in the name resolution check. It will first check DNS and then the hosts file. I'm sure OP no longer needs this info, but this is still good for anyone seeking answers to this problem.

You must also restart in order for this to take into effect


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.

Tags:

Hosts