A popular method used to block ads or domains in browsers is to use adblocking addons. An alternate method is by using the
hosts file of your operating system. This file has mappings of hostnames to IP addresses. By pointing domain names to the
0.0.0.0 IP address they cannot be resolved for access.
- A popular source for hosts file is provided by Steven Black. Clone that repository to your computer:
$ git clone https://github.com/StevenBlack/hosts.git $ cd hosts
- If you have any entries in your local
hostsfile, then add them to the
myhostsfile in this repository.
To update the adblocking domain files to their latest versions and to add the
myhostsentries to create a final
hostsfile run this command:
- Replace your
hostsfile with this one:
$ sudo cp /etc/hosts /etc/hosts.orig $ sudo cp hosts /etc/hosts
- Optionally, you can also restart your name service cache daemon to flush its cache:
$ sudo service nscd restart
That is it! You can use any browser or application and the domains in the hosts file will not be accessible from them.
Tried with: Ubuntu 16.04