How to Block Websites Using the Hosts File in Windows 10
Every Windows version comes with a special Hosts
file which helps resolving DNS records. In addition to your network configuration, the file can be used to define a domain=IP address pairing which will have priority above the value provided by the DNS server. Using this trick, you can block certain web sites from opening in the web browser on your computer.
This trick is also useful in many other situations. For example, web devs can make their computer resolve a domain to a localhost address. If you have a home LAN, mapping a network device name to its IP address with the Hosts file will allow you to open the device by its name from File Explorer. This is useful when your network devices run a bareboned Linux distro which doesn't provide names Windows can recognize over the network.
The Hosts file is just a regular text file which can be modified using any text editor. The only catch is that the editor app should be started elevated (as Administrator). The hosts file is located in the system directory, so non-elevated apps will fail to save it.
If the Hosts file is still locked or not editable, try turning off Kaspersky to see if it’s the source of the issue. Symantec Application and Device Control Application Control De-select rule: 'Block modifications to hosts file'. It might be necessary to reboot after these modifications. Allow Applications To Modify the Windows Hosts File. Whatever your reason, you can simply block websites on Windows 10 using something called the hosts file. The text below can get a bit technical, especially if you have never gotten into the nuts and bolts of Windows system files. If you want a quick overview, be sure to check out our short and easy to follow YouTube video first.
The Hosts file consists of lines of text. Each line must include an IP address in the first text column followed by one or several host names. Text columns are separated from each other by white space. For a historical reason, <Tab> is often preferred, but spaces will also do the trick. Lines started with a hash character (#) are comments. Windows ignores blank in the hosts file.
To Block Websites using Hosts File in Windows 10,
- Open the Start menu, and go to Windows Accessories.
- Right-click the Notepad app and select More - Run as Administrator.
- In Notepad, click the File menu - Open, or press the Ctrl + O keys.
- Navigate to the folder C:WindowsSystem32driversetc.
- Select 'All Files' from the drop-down menu.
- Double-click the hosts file.
- On a new line in the hosts file opened in Notepad, type
127.0.0.1
. This is your localhost address (the default local address of the PC). - Press Tab or add spaces after you localhost address, and type the web site address (e.g. google.com or www.facebook.com) you want to block.
- Save the file(Ctrl + S).
You are done!
Note: Use one entry per line. Entries should look as follows:
How to test the changes
To test the changes you have made, open a command prompt and use the ping command to see the address in the output.
In my case, the remote address of the google.com domain will be resolved to my local computer.
Block Host File Windows 10
Finally, you might want to unblock a blocked web site. Here's how it can be done.
To Unblock Websites Blocked in the Hosts File,
- Open the Start menu, and go to Windows Accessories.
- Right-click the Notepad app and select More - Run as Administrator.
- In Notepad, click the File menu - Open, or press the Ctrl + O keys.
- Navigate to the folder C:WindowsSystem32driversetc.
- Select 'All Files' from the drop-down menu.
- Double-click the hosts file.
- Add the comment symbol
#
at the beginning of the line that contains the blocked web site you want to unblock. Or, delete the whole line. - Save the file(Ctrl + S).
Block Host File On Android
Note: Adding the comment symbol is useful when you want to temporarily unblock an web address, or block/unblock it on demand.
That's it.
Advertisment
Since Windows 8, Microsoft has moved to a new commercial strategy: in addition with traditional selling of OS licenses, started got revenues from searches, apps and games.
But to do this, MS has started the collection of “telemetry” data, considered by many users as privacy-relevant.
What is Windows 10 telemetry?
According with a ZDNet article [4]:
Microsoft defines telemetry as “system data that is uploaded by the Connected User Experience and Telemetry component,” also known as the Universal Telemetry Client, or UTC service. (More on that shortly.)
Microsoft uses telemetry data from Windows 10 to identify security and reliability issues, to analyze and fix software problems, to help improve the quality of Windows and related services, and to make design decisions for future releases.
Telemetry features aren’t unique to Microsoft and there’s nothing particularly secret about them. They’re part of a larger trend in the software industry to collect and analyze event data as part of a shift to data-driven decision making.
To the delight of privacy conscious users, there are a lot of tutorials [5] and suggestions focused on avoid (or rather, reduce) the gathering of informations collected from Windows 10, using tools like PeerBlock[1], personal firewalls, network devices (like a Pi-Hole[2]).
In my opinion, a good trade-off may be a simple change on the “hosts” file.
What is “hosts” file?
The hosts file is used to map hostnames to IP addresses, and its data overrides the results of DNS queries.
It’s a plain text file, located in the Windows folder, at the following path:
A customized hosts file
Usually i use a custom hosts file created by encrypt-the-planet.com[3]: the file was realized analyzing with wireshark a dump of outgoing traffic of a brand-new Windows 10 installation.
Obviously, this is not a final solution.
According with ETP’s notes:
You should also be aware: this hosts file will block certain functions and services like Bing search, Cortana and One Cloud. Windows updates will still be able to download.
Windows 10 does communicate directly to IP addresses which bypass the hosts file. You would also have to block Microsoft’s IP addresses Windows 10 communicates with.
How to install the custom file?
Just four simple steps:
- Open this link, and copy the whole text
- Start (with administrative rights) a Notepad (but Notepad++ is better) and open the hosts file in C:WindowsSystem32driversetchosts.
- Replace the original hosts content with the text copied at step 1
- Save the file and restart your system.