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

spud:~ zork$ less /etc/hosts

127.0.0.1 facebook.com



You're going to need way more than that for all their subdomains, CDN, CDN's subdomains, etc. Not to mention having to keep it all up to date in case they roll out a new domain.

That said, I use the same technique. :)


Perhaps someone should create a repo on github containing all of the social sites' hostnames. looking at you


Run a nameserver and be authoritative for the entire domain.

Redirect at will.


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.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: