Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

So, if you just add the localhost address to etc hosts then nothing from the url will load in your browser?


Assuming /etc/resolv.conf is set up with "search <localdomain>" before any nameserver entries (which it invariably is), then any DNS query will first try the localhost.

In the absence of a nameserver on the local host, then the DNS lookup will search /etc/hosts, where it will find an entry for facebook.com that resolves to 127.0.0.1 (localhost).

Now the browser knows where to find facebook.com. It requests the web server at localhost to serve the URL. If there is no webserver, the browser gets back a "connection refused". If there is a webserver, the browser gets back a 404 error.

In either case, the browser just moves on to the next request.

Since it all happens on localhost, it is blazingly fast compared to an internet lookup, and the user won't realise.


Thanks for the clear explanation. Now I understand what I am doing when I modify my hosts file like this.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: