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 IP address they cannot be resolved for access.

$ git clone
$ 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 • 🐘📧