How to block websites using hosts file

Redmond, WA, USA - April 15, 2017: The Microsoft headquarters campus in Redmond. Microsoft is one of the world’s largest computer software, hardware and video gaming companies.

Sometimes we may want to block websites directly from a computer, which can be achieved using the hosts file both in Windows and Linux/Mac computers.

The location of the file in a windows computer is C:\Windows\System32\drivers\etc. Similarly, the location of the said file in the linux/mac computer is /etc/hosts which can be modified using a nano editor – sudo nano /etc/hosts

Below we are blocking google.com

127.0.0.1             www.google.com

Hosts-file maps an IP address to hostname. When we search for a website, the computer first looks up to the file for the IP address, and if it cannot find, it does a DNS lookup. In this case, we are mapping the localhost-127.0.0.1 to google.com and thus it is unable to resolve.

Note: In a hosts-file always use a tab for space.

Check Our

Related Posts