The Windows Hosts file consist of and allows us to define IP address linked to domain names(Websites). We can use Hosts file to block websites.

Hosts File Editing :-
To edit hosts file, we’ll need to open Notepad as Administrator. To do so follow the below steps:-
  • click Start
  • type Notepad into the Start Menu
  • right-click the Notepad icon & select Run as Administrator
notepad
  • then click on File and Open in Notepad
  • then browse to “C:\Windows\System32\drivers\etc folder”.
  • click the Text Files box at the bottom right corner of the window, select All Files, and double-click the hosts file.
notepad1

Changes made to the file will take effect immediately without rebooting, each entry should begin in the new line, when adding multiple entries to your hosts file, ensure each is on its own line.

How to block a website :-
To block a website, we need to add a line in the hosts file, which will consist of ip address and a domain name.
facebook
facebook1
facebook2

What this line does is it’s trying to link the domain name with the mentioned ip address – 127.0.0.1 is the localhost(IP address of your local computer). When we navigate to www.facebook.com, our computer will try to connect to itself(127.0.0.1), computer won’t find a web server running locally(on itself), so the connection will fail resulting in blocking the website.