But /etc/hosts can be put to other uses, such as blocking access to URLs that do not interest you, like http://www.doubleclick.com and other purveyors of unwanted Internet rubbish !
(It can also prevent the little dears from hogging the bandwidth watching Youtube, but that too is another story).
The system is very simple: if you have a "127.0.0.1 www.unwantedsite.com" entry in /etc/hosts, any query by your browser, or any other program, to http://www.unwantedsite.com will be directed to 127.0.0.1, which is your own machine, and it will fail since the page it wants is not present on your box; so you will not have to wait for the ad to download, and you will end up with something like "web page not found" on the page instead of the unwanted add ;-3)
So on you go, and start collecting the URLs you want to avoid, and add them to /etc/hosts.
Or if you are lazy like me, you look up in Google (or other) for "block hosts file", download the lists, mix them together, do a "$ sort -u" to remove duplicates...
(please note that since Windows uses a similar hosts file, which has the same structure, we can use under Linux hosts files made for Windows too without any problem)
Or you can start with my own list which is available zipped on http://www.filesnack.com/files/ctnf2nnx for anyone who cares to use it.
Once you have rolled your own file of bad hosts, or downloaded one, you will append it (as root) to /etc/hosts with
Code: Select all
# cat badhosts >> /etc/hosts
It will certainly happen later that you come across a URL that you need after all; in that case a quick edit with mousepad or vi (launched as root from a console) will let you find and remove the offending lines, and access the site.
In the same way, when you want to add one single URL to the file, a quick
Code: Select all
# echo "127.0.0.1 www.otherbadsite.com" >> /etc/hosts