Blog

Blocking Websites With The Hosts File

Blocking Websites With The Hosts File
Cybersecurity

Blocking Websites With The Hosts File

Why Block Websites

Maliciousness: Avoid places that may not have your best interests at heart. This could be anything from tracking you to taking over the browser to installing ransomware.

Content: Things you don’t want to see or don’t want others to see. For example: blocking porn.

Productivity: You wish to work on your business, or write that novel you always said you would. Block time wasting, distracting websites.

Disinterest: Some pages could come your way but aren’t of interest to you so block them in case you are to quick to click.

What Is The Hosts File

The names of websites need to translated to IP addresses. The hosts file allows the user to control how this mapping is done. In this way it is possible to redirect traffic. For example, if you enter “google.com”, this file could say “No, go to twitter.com”.

How To Change The Hosts File

In Windows 10

Open the file explorer and go to the following location, either by navigating to it or by pasting the address in the address bar: C:\Windows\System32\drivers\etc

File explorer Hosts file

Copy and paste the “hosts” file to a temporary location. The desktop will do fine. Optional: keep a backup of the original “hosts” file somewhere safe.

Copy

On the desktop, open the “hosts” file. Double click on it, drag it into a text editor, or right click on it and select “Open with”.

Open with

If you double click on it or chose “Open with”, then select a text editor to open the file with. Notepad and Wordpad are usually available options.

Notepad

Add redirects to the bottom of the file. Usually their is a comment in the file on how to format the redirects. It looks like this: 127.0.0.1 localhost

The first part, the IP address, says where to go. In this case, 127.0.0.1, which is the local machine.

The second part is the location we want to redirect. In this case, localhost.

A practical example: Let’s say you want to redirect facebook.com because you are on a device that you use for focused work and you don’t want to get distracted by the ability to scroll on facebook. Entering the following two lines will redirect facebook.com to the local machine. When you surf to facebook in the browser, instead of displaying facebook, it will tell you it can’t connect. In effect, the website is blocked.

127.0.0.1 www.facebook.com
127.0.0.1 facebook.com

Hosts file

Save the file and exit.

Cut the file from the desktop and replace the file in the “etc” folder. You will need Administrator rights to complete this.

Replace

Test if the redirecting/blocking works. Open a browser, suft to the blocked website (here is was facebook.com). The browser should display an error message.

Unable to connect

In a linux system

Go to: /etc/hosts file

Modify the file in the same way as for Windows. Your favorite text editor can probably do the job.

Suggestions Of Websites To Block

Add this list if you want to block browser-based crypto mining: https://github.com/hoshsadiq/adblock-nocoin-list/

This list aims to block malware, adware and other irritants: https://github.com/StevenBlack/hosts

User Agreement

Welcome to Modern Samurai.

An important part of establishing a contract is meeting of the minds. Where many websites hide their user agreement (a.k.a. terms of use, terms of service) at the bottom of their pages, we prefer to be upfront and honest about what you’re getting into. Please download our User Agreement and review it. If you agree, click “Agree” to continue to this Site. If you do not agree, click “Decline” to move away from this Site.