Skip to main content

Block a website on Windows(Hosts file)

Ever wondered how a website in a local Internet Cafes is blocked? Ever been a victim of a prank where an irrelevant website is opened when you open Facebook? Stop wondering and read further to know how to block a website.

Why would you want to block a website?

1) You own a business and want to prevent your employees from wasting time. Of course there are different and more secure solutions for these.

2) Protecting your children from certain websites.

3) You have a limited internet connection and want to block certain websites to prevent over downloading.

4) Play a prank on someone.

5) Show people that you can now actually block websites.

How do you block a website?

1) Using hosts file.

2) Using your router

3) Using third party applications

4) Browsers

Block a website using hosts file

Hosts file maps hostnames to IP addressesHosts file has no extension. It is a simple plain text file. Hosts file can be edited using simple text editors like Notepad.

It is located in C:/Windows/System32/Drivers/etc.

Block a website using hosts file

Hosts file location

NOTE: Here I assume that your Windows is installed in C drive. If not, just navigate to the drive letter which contains your Windows Installation.

Let’s block a website using the hosts file.

Navigate to the path mentioned to locate the hosts file.

Just to be on the safer side let’s create a backup of the file. Just copy the file and paste it again. Give whatever name you want.

Now open Notepad as an administrator.

# Copyright (c) 1993-2009 Microsoft Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
# For example:
# # source server
# # x client host

# localhost name resolution is handled within DNS itself.
# localhost
# ::1 localhost

You will get something like this. The ‘#’ symbol represents comments. To block a website, just go to the end of the file and in a new line add something like this:

Here represents the IP which you want to redirect your to-be-blocked-website. For this example, I am blocking “” Sorry Google, no offense to you.

Save the file and you are done. I have installed apache on my localhost and hence I get a result like this when I try to open


block a website using hosts file


Similarly, you can also play a prank on your friends by simply replacing the “” part by any website you want to be displayed when a particular website is opened.


Harsh Shah

A highly motivated individual with a hunger to learn and share as much as I can about everything. Masters in Interaction Design with a Bachelors in Computer Science. I have worked with clients across the globe on various design and tech projects. I believe in giving back and that's how ReadMeNow was founded.

Leave a Reply