Why do you need to know how to block websites? Maybe you want your kids to be safe online? Maybe you want to block distracting sites so you don’t have to procrastinate? It can also be used to block ad-embedded tracking sites.
Whatever the reason, you can simply block websites on Windows 10 using the so-called hosts file.
What is a Hosts file?
Have you heard the term DNS (Domain Name System)? It refers to a file system distributed over the Internet that helps translate domain names such as free-online-converters.com into its actual IP address, which turns out to be 184.108.40.206. This will help your computer know which server to talk to when you want to view this site.
Prior to DNS in 1984, this was done through a local file on your computer called the hosts file. At the time, computers were not linked to many other computers. At best, we could connect to several dozen. Keeping all this information in a plain old text file was easy. The host file is alive today.
How does the hosts file work?
The hosts file allows a computer to look for other computer names like localhost or domain names like free-online-converters.com and their IP address is next to the name in the file. It’s a bit like how your friends’ names are linked to their phone numbers on your phone. You don’t need to memorize or dial a number, just search for the person’s name.
Before going any further, it’s important to understand that some IP addresses are reserved for local use. This means that they can only be used to point to your computer and devices on your immediate network. This means anything before your message connects to the Internet.
For example, the IP address 127.0.0.1 always means the computer you are working on, also known as localhost. Try entering this into your web browser. Most likely, a blank page will open.
Also keep in mind that www.website.com and website.com are not the same thing. For both of them to take us to the same website, both must use the same IP address.
- Open Notepad as administrator.
Block Websites Using the Hosts File
- Open Notepad as Admin .
- Click File> Open.
- Navigate to C: Windows System32 Drivers etc
- Once there, change the file type from Text Documents (* .txt) to All Files (*. *).
- You can now see the hosts file. Open it up.
- Go to the last line of the page and add your line. Let’s say we block Facebook.
Enter the localhost IP address 127.0.0.1. Press the tab key and enter facebook.com. Press Enter to move to the next line. Create a second line similar to the one above, but use www.facebook.com instead of facebook.com.
Is the website blocked?
Open a command prompt and ping facebook.com, then ping www.facebook.com. You should see that the IP address it is trying to check is 127.0.0.1.
Now open your web browser and go to facebook.com. It can still load! Why? Facebook’s real IP address may still be in the browser cache and the browser will use that IP address first. Clear your browser cache and try Facebook again. You should now see an error page.
I don’t want to see an error page
You can try redirecting the site to a different IP address, but this won’t work these days. Malicious editing of the hosts file has been a frequent attack by hackers. Web browsers now carefully check for certificates to prevent this. But you can still try.
Another way not to see the error page is to install and configure a web server on your computer and point the hosts file to it. Maybe it will display a page that says “Get back to work!” or lists some of your goals as motivation to stay away from social media.
What else can I do with the Hosts file?
You can use the same technique, but paste the URLs of various malware and tracking ads. There is a pre-created hosts file for malware and ad sites that you can copy and paste into your hosts file. At the time of writing, it was last updated in March 2020.