Advertisement

Block Websites Using Hosts File in Windows 10

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.

Advertisеment


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.

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,

  1. Open the Start menu, and go to Windows Accessories.
  2. Right-click the Notepad app and select More - Run as Administrator.Run Notepad Elevated
  3. In Notepad, click the File menu - Open, or press the Ctrl + O keys.
  4. Navigate to the folder C:\Windows\System32\drivers\etc.
  5. Select "All Files" from the drop-down menu.
  6. Double-click the hosts file.Notepad Open Hosts
  7. 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).
  8. 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.
  9. Save the file(Ctrl + S).Windows 10 Edit Hosts File

You are done!

Note: Use one entry per line. Entries should look as follows:

127.0.0.1 google.com
127.0.0.1 www.facebook.com

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.

Windows 10 Test Hosts File

 

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,

  1. Open the Start menu, and go to Windows Accessories.
  2. Right-click the Notepad app and select More - Run as Administrator.Run Notepad Elevated
  3. In Notepad, click the File menu - Open, or press the Ctrl + O keys.
  4. Navigate to the folder C:\Windows\System32\drivers\etc.
  5. Select "All Files" from the drop-down menu.
  6. Double-click the hosts file.Notepad Open Hosts
  7. 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.Windows 10 Block Unblock WebSites Using Hosts
  8. Save the file(Ctrl + S).

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.

Support us

Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:

If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!

Advertisеment

Author: Sergey Tkachenko

Sergey Tkachenko is a software developer who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Telegram, Twitter, and YouTube.

7 thoughts on “Block Websites Using Hosts File in Windows 10”

  1. I’ve been using a premade hosts file for years. Get it at “http://winhelp2002.mvps.org/hosts.htm&#8221;.

    I find it easiest to copy the file to the desktop then delete the old one. Do my editing and then move it back to it’s original location as many security options block modification of this file.

    Important Note: The HOSTS file now contains a change in the prefix in the HOSTS entries to “0.0.0.0” instead of the usual “127.0.0.1”.
    This was done to resolve a slowdown issue that occurs with the change Microsoft made in the “TCP loopback interface” in Win8.1.

    This change in the prefix should not affect everyday users. I’ve had some feedback that COMODO antivirus, and System Mechanic seems to have issues with the “0.0.0.0” prefix … to resolve this issue:

    You can use the “Replace” function in Notepad to convert the entries, or either of these freeware utilities (see below) has an option for converting the entries from “0.0.0.0” to “127.0.0.1.

    1. Win8 doesn’t ‘phoning home’ directly to ‘microsoft.com’ it uses a number of other domains with different names, all owned by Microsoft.

  2. I did all the recommendations with updating the hosts file, and it’s still not working. Using windows 10

    1. @Timur – It would help if you list the sites blocked. Here’s the list I’m using.
      ########################
      # Block windows update
      ########################
      127.0.0.1 *.download.windowsupdate.com
      127.0.0.1 *.microsoft.com
      127.0.0.1 *.update.microsoft.com
      127.0.0.1 *.windowsupdate.com
      127.0.0.1 *.windowsupdate.microsoft.com
      127.0.0.1 download.microsoft.com
      127.0.0.1 download.windowsupdate.com
      127.0.0.1 ntservicepack.microsoft.com
      127.0.0.1 test.stats.update.microsoft.com
      127.0.0.1 windowsupdate.microsoft.com
      127.0.0.1 wustat.windows.com

      It seems complete, but I’ve also shut off every Windows 10 update switch I can find in the registry, so this is just my back-up plan. Good luck.

      If anyone can add to the list, that would be great.

  3. There are applications out there to help edit hosts; so you don’t have to go through the rigmarole of searching it out and then remembering you needed to open notepad with admin privs. Not only that, certain apps allow you to work with multiple hosts files (ie, if you are a web dev, etc). Happy blocking!

Leave a Reply

Your email address will not be published.

css.php
Using Telegram? Subscribe to the blog channel!
Hello. Add your message here.