The hosts file is a file used in an operating system to point hostnames to IP addresses. It is a text file like any other text file with name hosts but without any extension to file. The Hosts file located in every OS at different locations in Windows NT, 2000, and 32/64-bit versions of XP, 2003, Vista, 7 it is located in %systemdrive%/windows/system32/drivers/etc, in Mac OS X 10.2 and newer it is located in /private/etc/hosts
In Windows when Windows Start up it load the hosts file in to cache memory, then Windows checks the Hosts file before it queries any DNS servers, which enables it to override addresses in the DNS and by redirecting any IP or hostname to local IP(127.0.0.1) we can block any website or server to load.
By this way, you can block websites ads, banners, 3rd party Cookies, 3rd party page counters, web bugs, and even most hijackers. It is also very useful trick when you want to block some websites in your home PC to protect your kids from porn or other inappropriate websites.
Adding entry 127.0.0.1 ad.doubleclick.net in hosts site will block ads from ad server Doubleclick.net,
adding entry 127.0.0.1 facebook.com will block Fcebook.com on all browsers in a system.
You can use this pre-configured hosts file containing all major ad-servers & suspicious websites [Link to the file]. Download this file by clicking & selecting Save As & Replace with your system’s hosts file.
Step by step tutorial of Blocking a website with hosts file in Windows:
- Go to Start Menu and click on Run, Paste %systemdrive%/windows/system32/drivers/etc and hit Enter.
- Now in folder you will see some files as shown in image below, Copy hosts file and Paste on desktop.
- Now, Open pasted hosts file on desktop with Notepad.
- Add 127.0.0.1<space>hostname or IP of the website you want to block eg.facebook.com, see image below for more info. or Download this pre-configures hosts file, Copy the content from downloaded file & Paste it in pasted file on desktop.
- Now, Click on Save in file menu(not Save as), Now Replace the edited file with the original one in %systemdrive%/windows/system32/drivers/etc.