Ubuntu – Why is the /etc/hosts file not working

12.04dnshostsnetworking

I have been having problems with this for a while and have tried everything I know, so I figured it was finally time to ask for some help.

Any edit I make to /etc/hosts just doesn't work.

Example:

julian@ifrit:~$ cat /etc/hosts
127.0.0.1   localhost
127.0.1.1   ifrit
192.168.1.100   dev.julianfernand.es

In the example above, when I access dev.julianfernand.es (this doesn't exist), it should load from 192.168.1.100.

If I ping, it works just fine. However when I access dev.julianfernand.es using Google Chrome or Firefox, it doesn't.

Now, after I restart a couple times, it works. But since I work at a managed WordPress hosting company, I deal with many situations where I have to edit my file to see the customer's website on our server.

I just can't keep restarting my computer. It isn't productive at all. Restarting the networking service doesn't work, same for clearing cache (even internal Chrome DNS cache).

Does anyone have an idea here? This happens with elementaryOS (based on Ubuntu 12.04) and Ubuntu 13.10 (daily). Haven't tried with any other version yet.

PS: if this matter, I have a NGINX server running on this machine with PHP-FPM and MySQL.

Thanks in advance 🙂

Best Answer

In Ubuntu if you want to flush DNS cache, you need to restart nscd daemon.

Install nscd using the following command:

sudo apt-get install nscd

Flush DNS Cache in Ubuntu Using the following command:

sudo service nscd restart

OR

sudo service dns-clean start

Reference: http://www.upubuntu.com/2012/05/how-to-flush-clear-dns-cache-under.html