How To Block Websites On Windows Using The Hosts File

Protect your kids, stop trackers, eliminate distractions

Why would you want to know how to block websites? Maybe you want to keep your kids safe on the Internet? Maybe you want to block distracting websites so you don’t procrastinate? It can also be used to block tracking sites that are embedded in ads.

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 followYouTube videofirst.

What Is The Hosts File?

Have you heard the termDNS(Domain Name System)? It refers to a system of files distributed around the Internet that help resolve domain names likehelpdeskgeek.cominto its actual Internet Protocol (IP) address which happens to be13.225.198.106. That helps your computer know what server to talk to when you want to view this site.

Before DNS came into being in 1984, this was done through a local file on your computer called the hosts file. Back then computers weren’t connected to many other computers. At most, we may have connected to a few dozen. It was easy to keep all that information in a plain old text file. The host file lives on today.

How Does The Hosts File Work?

The hosts file allows the computer to look up other computer names, likelocalhost, or domain names, likehelpdeskgeek.comand the IP number for them is right beside the name in the file. It’s a bit like how your friends’ names are associated with their phone numbers in your phone. You don’t need to remember or punch in the number, just find the person’s name.

Before we go further it’s important to understand that some IP addresses are reserved for local use. That means that they can only be used to point to your computer and devices within your immediate network. That means anything before your communication connects to the Internet.

For example, the IP address127.0.0.1always means the computer you’re working on, also known aslocalhost. Try typing that in your web browser. It will likely bring up a blank page.

Also understand thatwww.website.comandwebsite.comare not the exact same thing. For both of them to take us to the same website both must resolve to the same IP address.

Blocking Websites With The Hosts File

Enter the localhost IP of127.0.0.1. Press the tab key and enterfacebook.com. Press Enter to go to the next line. Create a second line like the one above, but usewww.facebook.cominstead of just facebook.com.

Is The Website Blocked?

Open the command prompt and runping facebook.comthen runping www.facebook.com. You should see that the IP address it’s trying to ping is 127.0.0.1.

Now open your web browser and go to facebook.com. It might still load! Why? Facebook’s real IP may still be sitting in the browser cache and the browser will use that IP first. Delete your browser’s cache and try Facebook again. You should now see an error page.

I Don’t Want to See an Error Page

You could try redirecting the site to another IP address, but these days that won’t work well. Maliciously editing the hosts file used to be a common attack by hackers. Now, web browsers check carefully for certificates to prevent this. But, you can still try.

Another way to not see an error page is toinstall and set up a web server on your computerand have the hosts file point to that. Maybe have it display a page that says, “Get back to work!” or lists some of your goals as motivation to stay off social media.

What Else Can I Do With The Hosts File?

You can use the same technique but paste in the URLs of various malware and tracking ad sites. There is apre-made hosts file of malware and ad sitesthat you can copy and paste into your hosts file. As of writing this, it was last updated in March, 2020.

Guy has been published online and in print newspapers, nominated for writing awards, and cited in scholarly papers due to his ability to speak tech to anyone, but still prefers analog watches.Read Guy’s Full Bio

Leave a Reply

Your email address will not be published.Required fields are marked*

Comment*

Name*

Email*

Website

Welcome to Help Desk Geek- a blog full of tech tips from trusted tech experts. We have thousands of articles and guides to help you troubleshoot any issue. Our articles have been read over 150 million times since we launched in 2008.

HomeAbout UsEditorial StandardsContact UsTerms of Use

Copyright © 2008-2024 Help Desk Geek.com, LLC All Rights Reserved