Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to block domains using hosts file

📅 2016-Aug-12 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ hosts ⬩ 📚 Archive

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.

$ git clone https://github.com/StevenBlack/hosts.git
$ cd hosts
$ ./makeHosts
$ sudo cp /etc/hosts /etc/hosts.orig
$ sudo cp hosts /etc/hosts
$ 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


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧