Hosts file to block websites - rajivkanaujia/alphaworks GitHub Wiki

TL/DR

Use this hosts file

Background

I would like to block various websites using hosts files. This options exists since the early 1980s. For high level understanding of the same, visit https://en.wikipedia.org/wiki/Hosts_(file)

Why Block certain websites?

  1. Don't like their contents and they are peddling ads, malware and embedding tracking cookies; aka doing all sort of annoying/bad behavior.
  2. Block certain sites.

How to do it?

This approach is very straightforward and simple. Modify the hosts file to make such websites localhost and your computer then resolves them to your local machine. What you need to know is the websites IP address. And there are few braves ones who keep such list handy.

Sites I used to build my list

  1. https://github.com/jmdugan/blocklists
  2. https://pgl.yoyo.org/adservers/
  3. http://www.malwaredomainlist.com/hostslist/hosts.txt
  4. http://winhelp2002.mvps.org/hosts.txt
  5. https://someonewhocares.org/hosts/zero/hosts

I merged them into one, removed the duplicates as well.

What I did on my mac?

Since I use Mac, the hosts file is located at /etc/hosts You can use any of your favorite editor to edit it. I use Visual Studio Code.

$ open -a /Applications/Visual\ Studio\ Code.app/ /etc/hosts

Add the sites to block after the default localhost settings

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost

##
# Add sites to block after this
##


Note: If you like the instructions here, please refer it on your posts/documentation. Contact me if there are corrections needed.