Using the Hosts File to Block Content

Written by Barry Dysert (last updated February 8, 2021)

Your Hosts file is an important system file for network communications, and it can be used as a rudimentary method for blocking Internet sites. Given the fact that the IP address 127.0.0.1 always points to your local computer, you can modify your Hosts file so that a website that you want blocked is mapped to that IP address.

Say that you wanted to block "www.facebook.com". Modify your Hosts file so that it contains this line:

127.0.0.1     www.facebook.com

Now if you direct your Web browser to "www.facebook.com" you will instead be directed back to your local computer. The reason this happens is that in parsing the domain name (www.facebook.com) your computer looks to the Hosts file for resolving the DNS address instead of to an external system which would return the real IP address for Facebook.

The ability to use a Hosts file has led some folks to develop rather complete blocking solutions for individual computers. One popular one is available at the following page:

https://winhelp2002.mvps.org/hosts.htm

Basically, what is offered is a copy-and-paste way to block sites through your Hosts file, which can be simple and effective.

There is one caveat with using a solution such as the MVPS HOSTS file: It can have some unexpected results. One rather personal example is that the MVPS HOSTS file blocks anything related to a popular e-mail fulfillment service known as AWeber. It just so happens that WindowsTips (and other Tips.Net publications) utilizes AWeber for publishing newsletters. That means that on a system that includes, in its Hosts file, information copied and pasted from the MVPS HOSTS file, the user won't be able to click any of the links in the WindowsTips newsletter or any other Tips.Net newsletter. This occurs for reasons already discussed in this tip.

The moral of the story is that if you decide to use a Hosts-file-based solution provided by someone else, make sure that you understand what is actually being blocked. (You could use the MVPS HOSTS solution, but you'll want to search through the file for any entries containing the characters "aweber." Delete those lines—there should be two of them—and you can again access any links in Tips.Net newsletters, including the links in WindowsTips.)

As noted, using the Hosts file to block content is effective, but it is rather rudimentary because (1) you could always remove this line from your Hosts file, or (2) specify the IP address in your browser, thus bypassing your Hosts file altogether.

 This tip (12875) applies to Windows 7, 8, and 10.

Author Bio

Barry Dysert

Barry has been a computer professional for over 35 years, working in different positions such as technical team leader, project manager, and software developer. He is currently a software engineer with an emphasis on developing custom applications under Microsoft Windows. When not working with Windows or writing Tips, Barry is an amateur writer. His first non-fiction book is titled "A Chronological Commentary of Revelation." ...

MORE FROM BARRY

Changing Screen Resolution

Screen resolution is a key attribute of your monitor. You usually have choices for resolution, which provides you with a ...

Discover More

SyncToy

SyncToy allows you to keep multiple pairs of folders in sync. This means it can also serve as a decent file-backup ...

Discover More

Filtering a Folder's Content

If you have lots of files on your computer, it is helpful to filter the files to more easily find a specific one. When ...

Discover More
More WindowsTips

Creating a Desktop Shortcut for a Favorite Web Page

If you visit a certain Web page frequently, you may wish to create a desktop shortcut to take you there. This tip tells ...

Discover More

Moving Your Downloads Folder

If you're on the Internet a lot, chances are you do a lot of downloading. By default, your Downloads folder is on your C: ...

Discover More

Defining Words Quickly

When reading a webpage, e-book, or PDF, Microsoft Edge can quickly show you the meaning of a word that you might need to ...

Discover More
Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two more than 7?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


Newest Tips