Redirect or Block Web Sites Using HOSTS File

You can redirect or block one or more web sites using the HOSTS file in Windows (and other operating systems). The HOSTS file is located in the folder %windir%\System32\drivers\etc in Windows XP, Vista, 7, 8, 8.1 and 10. It is basically a text file with two columns : the first column consists of a target IP address and the second column consists of the respective source site address. When you access a site listed in the second column, you are redirected to the respective site in the first column. The two columns should be separated at least by a single space. A typical HOSTS file is shown below :

Block website using HOSTS

Because localhost is in the second column and the corresponding entry in the first column is 127.0.0.1, when you type localhost in your browser’s address bar, it will be redirected to 127.0.0.1. You can use this technique to block or redirect some undesirable sites, for example, inappropriate sites, phishing sites or malware sites.

1. Blocking a Web Site in Windows XP

For editing the HOSTS file in Windows XP, you must be logged in with an administrator level account. Lets assume that you want to block a site www.gooogle.cn, you can edit your HOSTS file using the following steps :

  1. Open Start Menu → Run and type notepad %windir%\system32\drivers\etc\hosts and press Enter as show in the picture :

    Block website using HOSTS

  2. This would open your hosts file in Windows’ Notepad. Start editing at the end of the file : Press Enter to start a new line. Type 127.0.0.1. Press TAB key once. Then type the name of the site you want to block, in this case, gooogle.cn. You do not have to type the http:// or www. part of a web site. Then end result will look like this :

    Block website using HOSTS

  3. Save the hosts file. Now when you type gooogle.cn in your browser, it will be redirected to 127.0.0.1 and is effectively blocked for all programs.

This way you can block phishing sites, infected sites, inappropriate sites etc. Actually, this is a popular way of blocking Paltalk (http://www.paltalk.com) advertisements. Just block advertising.paltalk.com in your hosts file and you won’t see most of the advertisements in Paltalk basic.

2. Blocking a Web Site in Windows Vista and 7

The process of blocking sites in Windows Vista and 7 is a little different from Windows XP. This is due to the presense of User Account Control (UAC) system in these versions of Windows. Again, lets assume that you want to block a site www.gooogle.cn, you can edit your HOSTS file using the following steps :

  1. First of all you have to open an elevated command prompt. To do this, click on the start menu button (blue orb at the lower-left corner of your screen). Type in cmd in the search box, right-click on cmd.exe when it appears and choose Run as administrator as shown. You may have to click Yes in the UAC dialog.

    Block Websites using HOSTS file

  2. In the elevated command prompt window, type in the following command and press Enter:
    notepad %windir%\system32\drivers\etc\hosts

    Block Websites using HOSTS file

  3. This would open your hosts file in Windows’ Notepad. Start editing at the end of the file : Press Enter to start a new line. Type 127.0.0.1. Press TAB key once. Then type the name of the site you want to block, in this case, gooogle.cn. You do not have to type the http:// or www. part of a web site. Then end result will look like this :

    Block Websites using HOSTS file

  4. Save the hosts file by pressing Ctrl + S hotkey or using File → Save. Now when you type gooogle.cn in your browser, it will be redirected to 127.0.0.1 and you will not be able to access it. This site or domain is now blocked for each and every program in Windows.

3. Blocking a Web Site in Windows 8/8.1/10

The process of blocking sites in Windows 8, 8.1 or 10 is very similar to the one for Windows 7. The only difference is the way we open an elevated command prompt in Windows 8. Once again, we are going to assume that you want to block a site www.gooogle.cn, you can edit your HOSTS file using the following steps :

  1. First, you have to open an elevated command prompt. In Windows 8, 8.1 and 10), this is very easy. Press the hotkey Win + X and select Command Prompt (Admin) from the menu that pops up. You may have to click Yes in the User Account Control dialog.

    Block Websites using HOSTS file

  2. In the elevated command prompt window, type in the following command and press Enter:
    notepad %windir%\system32\drivers\etc\hosts

    Block Websites using HOSTS file

  3. This would open your hosts file in Windows’ Notepad. Start editing at the end of the file : Press Enter to start a new line. Type 127.0.0.1. Press TAB key once. Then type the name of the site you want to block, in this case, gooogle.cn. You do not have to type the http:// or www. part of a web site. Then end result will look like this :

    Block Websites using HOSTS file

  4. Save the hosts file by pressing Ctrl + S hotkey or using File → Save. Now when you type gooogle.cn in your browser, it will be redirected to 127.0.0.1 and you will not be able to access it. This site or domain is now blocked for each and every program in Windows.

4. Redirecting a Web Site

You can redirect a web site to another site using the same method as described above for blocking, except replace 127.0.0.1 by the target site’s IP address. For example, suppose you want to redirect your browser to www.google.com whenever someone types www.facebook.com in the browser address bar, then follows these steps :

  1. Open hosts file in Windows’ Notepad as described in the blocking section step 1 for your version of Windows (see above).
  2. Find out IP address of www.google.com using this article : Find the IP Address of a Website. (IP address is found out to be 74.125.53.100)
  3. Start editing at the end of the HOSTS file : Press Enter to start a new line. Type 74.125.53.100, press TAB key once followed by facebook.com. Save the hosts file.

Now whenever you (or someone else) types in your browser’s address bar www.facebook.com, he/she will be redirected to www.google.com. You can follow the same technique on any other websites.

5. Readymade HOSTS file for Blocking Malicious Sites

Some clever people have prepared a hosts file which blocks thousands of sites linked to parasites, malware, adware and spywares. This is a very useful way to stay safe on the internet, as with such a hosts file, all known malicious sites will be blocked. You can download this readymade HOSTS file and read instructions on how to install it on http://www.mvps.org/winhelp2002/.

  • swordish

    how can I block some/most of the major/popular porn sites?

    with a lazy LAZY teen attempted circumvention is unlikely.

  • swordish

    you can try $0 pfSense

  • swordish

    perhaps you misunderstand the nature of links?

  • swordish

    the only “risk” is lagginess if there is not a local application to answer on the address used in HOSTS (usually 127.*)

  • swordish

    does your OS use DNS caching? have you disabled it?

  • swordish

    Or have you been tinkering with registry control of name resolution?

  • Youcef Dz25

    sometimes you need to clean history and reboot
    and other times you need to ping site by using Cmd just Google it

  • Youcef Dz25

    Wait this filter is free | Golden Filter Premium
    and you can copy one file host to 1000000 new computer 🙂

  • Youcef Dz25

    No at all

  • Youcef Dz25

    x)

  • Youcef Dz25

    sometimes you need to clean history and reboot
    and other times you need to ping site by using Cmd just Google it

  • Pingback: Prevent Windows 10 from Tracking You and Dialing Home()

  • Pingback: Fixing "The server stumbled" Windows Store Error in Windows 10()