Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / security

Blocking Particular Website in Computer

5.00/5 (1 vote)
11 Sep 2012CPOL2 min read 9.3K  
How can I block some website permanently like (facebook.com) and more social site on my employees computers

Introduction

Many times while answering on community forums and surfing on the Internet, I have a question about how to block a particular website on the computer. This is from sensible parents who care for their child, administrators who manage Office and Office Network at work. This is really a great problem in case of social networking sites. I have searched and tried almost all softwares, Windows Features like parental security, content adviser, etc. But some of them throw annoying messages or some pop-ups and graphical disturbance.

So finally, I tried hosts file which is a threat according to Microsoft Security Essential. But it does not harm your system in any manner and does not install any third party software on the computer.

Background

I have tried to block access to those sites from Router Configuration, but at some point I need to enable them in particular PCs which is really difficult and a hard task. So I am here to tell you the method of blocking websites using hosts file.

How to Change Setting

I am going to tell you about changing the setting. To do so:

  • Open Notepad with Administrator Rights.
  • Ctrl+O to Open File. Choose File Path Below.
  • Windir:(C: )\Windows\System32\drivers\etc
  • Change File Type to All Files from Right Bottom Corner.
  • Choose hosts file and open it.
  • You will see the below lines at the end of the page:
    #127.0.0.1       localhost
    #::1             localhost

    Now just add this code to block a website named domainname.com and an IP address.

    Using IPv4:

    127.0.0.1 www.domainname.com
    
    127.0.0.1 domainname.com
    127.0.0.1 258.258.258.258 (Sample IP - So Invalid)

    Using IPv6:

    ::1 www.domainname.com
    ::1 domainname.com
    ::1 258.258.258.258 (Sample IP - Used Invalid)

    Now save this file. If you are using antivirus, this may disinfect it, so disable Real Time Protection for some time and after saving changes, enable those settings of antivirus.

You are done, open any browser and enter the blocked URL in address bar and click navigate button. See the result.

Note

This will block access to the mentioned website in your system in all applications. So you don't need to worry about Browsers, Chatting Applications, Desktop Programs, even a link to Website or IP address.
You have to change some setting in individual PCs for doing so.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)