Original hosts windows 7. Clean hosts file

The Windows operating system (OS) (like other operating systems) has the ability to accelerate the transition to the IP address you typed on the site without contacting the DNS domain name system - DomainNameSystem. For this, a special operating system file called hosts is used (used without any extension). The question arises: "The hosts file - what should be there?"

What is it for and what does the hosts file contain

If this file matches the site name with its actual IP address, then redirection occurs without contacting the DNS service of your provider. The hosts file is a plain text file that can be opened by anyone like Notepad (but requires administrator rights). By default, the file contains several lines of explanations (comments) in English or Russian and a single executable line that redirects calls to the localhost name to the IP address of the computer itself.

Where is the hosts file

You can usually find the hosts file:

  • in Windows versions 95/98/ME - in the WINDOWS directory;
  • in Windows versions NT/2000 - at WINNT\system32\drivers\etc;
  • Windows 7 hosts file (and Windows XP/2003/Vista/8 versions) - in the WINDOWS\system32\drivers\etc directory.

Other operating systems also have a hosts file with similar functionality. Where the hosts file is located in these OSes must be considered separately.

Why file is important for virus protection

The importance of addressing the issue of hosts, what should be there, is that the special properties of this file are used by some to protect against anti-virus programs and to block certain files from being called. After all, if you write redirection of anti-virus programs to a false IP address in the hosts file, then the computer will not be able to carry out the work of these programs, and, for example, anti-virus databases simply will not be updated.

Therefore, if your computer has problems with the operation of antivirus programs, one of the reasons may be an unauthorized change to the hosts file of your computer.

What can the hosts file be used for

Some users use it to prevent the use of certain sites, such as pornographic or annoying social networking sites. To implement such a task, you can simply enter at the end of the file for each site one line like: 127.0.0.1 "site name". In this case, the sites that users try to navigate to on this computer will simply not be called.
You can also do this trick: redirect those trying to call an unwanted site to a site, for example, the Mashkov library, by entering the string: 81.176.66.163 "site name".

Ad exclusion

Also, the question of hosts, what should be there, is important because by making some additions to it, you can avoid showing annoying contextual and / or banner advertising, which in some sites is added not only along the perimeter of the information content of the pages, but also interspersed in the middle of the texts articles. To do this, you need to redirect sites that host these types of ads to the address 127.0.0.1, as indicated above. And these are sites such as, for example, "Google" contextual advertising AdSense. To exclude its display, enter the following lines in the hosts file:

  • 127.0.0.1pagead.googlesyndication.com;
  • 127.0.0.1pagead2.googlesyndication.com.

On the Internet, you can find ready-made texts for inserting into the hosts file, containing many such lines that exclude unnecessary display. In addition, there are ready-made texts for setting up faster work with some search engines, for example, hosts google. However, such materials must be used with caution. It is undesirable that the size of the hosts file exceeds 10 KB. Otherwise, he himself will slow down the system. Although these 10 KB can accommodate many such redirect strings.

Possible difficulties

First you need to make sure that the file you want to edit. The fact is that some cunning creators of virus programs mask the hosts file used by the system by placing it in a different place where it is registered by default. The system accesses the Windows 7 hosts file, the path of which is specified in the registry in the DataBasePath parameter located at: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\.

The correct path value looks like: %SystemRoot%\system32\drivers\etc\hosts. You can check this by calling the registry editor regedit.exe from the Start menu - run.

If the specified variable contains a different value, you must restore the value that should be.

Another trick of malware is to place another file with a similar name, such as host, in the etc directory along with the hosts file. Be careful, make sure that you check and edit the exact file that is used by the system.

The third trick is to hide the file from view. They just state that it is hidden. In this case, it is simply not visible in the directory, although it is present there. To be able to view it, you must first set the item "Show hidden files". In Windows XP, this option is set in the "View" tab of the "Properties" panel of the "Control Panel" menu folder. After that, viewing hidden files will be possible, and it will be possible to reset the "hidden" attribute in the properties of this file. At the same time, check if the "Read Only" flag is set for this file. If set, you will not be able to edit it. It is necessary to uncheck the corresponding field of the file properties panel.

The next trick might be to use a proxy. If the manual proxy setting is set, then the hosts files do not work. To fix this shortcoming, check your browser settings. For example, for Firefox, you need to open "Settings", then "Advanced", then in the "Network" tab, select "Configure". In the menu that appears, if the item “Use system proxy settings” was selected, select the item “No proxy” and save the settings. But if the item “Manually configure the proxy service” was selected, and you did not set it, then you need to do more work. First you need to remember the set proxy server address, set the “No proxy” item, save the settings. Then you need to open the registry editor, call the search, insert the remembered address and search, deleting the value of your address assigned to them in the found keys.

Simple Defense

By the way, in order to prevent malicious programs from changing the settings of the hosts file of your computer, it is useful to set (after all your changes in it) the "Read Only" attribute in its properties.

Thus, in this article, we dealt with the question of Hosts, what should be there, and found out what kind of file it is, where it is located, what functions it performs, how it can harm a computer under the influence of malware, and how to use it in your purposes.

Using the Windows hosts file to prevent your computer from connecting to unwanted web addresses is a very old practice that is still used to increase security or block individual sites and cookies from third party sites. Experienced users have long been familiar with this file and have used it in practice more than once. But, if you are hearing about it for the first time, then this article will help you understand how to properly use the hosts file.

Where is the Windows 7 hosts file located and why is it needed

First of all, the hosts file is a plain text file that has no extension and allows you to match IP addresses and Url addresses of websites (we will talk about addresses a bit later). This means that you can edit it using any text editor, including Windows notepad. The second thing to know is that the hosts file can be used not only by you to block or redirect sites, but also by malware, for example, to redirect you from your favorite websites to malicious sites to steal your personal data. This means that most anti-virus programs watch for changes to this file. And with any changes, they can issue appropriate messages. The third thing to be aware of is that the hosts file is a system file and you will need administrator rights to edit it. This means that in order to correct it, you need to open a text editor as an administrator.

The Windows 7 hosts file is located at:

  • %windir%\system32\drivers\etc\hosts
    • Usually, %windir% is "C:\Windows", but you can also use %windir%.

Open a text editor with administrator privileges and then open the hosts file from the above path. A file should open in front of you, as shown in the picture:

Note: The file is opened in Notepad++, but as already mentioned, you can also do this with Windows Notepad

The file is filled based on three basic rules

  1. All comments start with # (pound sign) For example
    • # This is a line comment
  2. Each comparison of the IP address and the Url page is indicated on a separate line and there must be a space between them (space, tab)
    • 127.0.0.1 localhost
    • (127.0.0.1 is the address of your computer)
  3. The order is exactly as shown:
    • IP address first, then Url address

Taking into account the above rules, it is clear that by default in the hosts file for your computer (IP address 127.0.0.1) the name localhost is assigned, which can be used not only by browsers, but also by any programs.

Note: As a matter of fact, you can also match non-existing Url addresses with the IP addresses you need, but keep in mind that they will only be correct on your computer.

Let's move from theory to practice.

Use the Windows 7 hosts file to block and redirect sites?

First of all, open the Windows hosts file with administrative rights as shown above. And try adding two examples to the end of the file (one for blocking, one for redirecting)

# The following line will block any attempts to open a malicious site # named virus-attack-stole-your-data.ru 127.0.0.1 virus-attack-stole-your-data.ru # The following line will redirect the opening of a website # named mysite.data.info to IP address 10.10.10.10 10.10.10.10 mysite.data.info

In the first case, any attempt to open a malicious site with the name "virus-attack-stole-your-data.ru" will cause the browser or any other program to try to open the site on your computer (127.0.0.1). If there is none, then, for example, the browser will show you a message about the unavailability of the site. This is a convenient and often one of the fastest ways to block any website in Windows.

In the second case, any attempt to access the URL "mysite.data.info" will cause the browser or any other program to open the site at 10.10.10.10. As in the first case, if such an address does not exist, an error will be thrown. This method is especially convenient in cases where you want to use convenient names instead of numbers to access a site on a computer. You can also use your own abbreviations to refer to those sites that have their own dedicated IP, like most large projects.

Note: In addition to the fact that the specified Url-addresses can be used to open sites, you can also use addressing through ports. For example, a call to the address "mysite.data.info:8080" will be redirected to "10.10.10.10:8080", which is especially convenient when you have computers on the local network that have an IP address (servers, storages, etc.). .d.), but do not have a pretty URL.

Note: We remind you that all configured Url-addresses can be used in any programs on your computer. However, you must remember that such settings will only be correct on your computer.

There is one more question that may interest you, namely, when will the settings take effect? By default, the application time will depend on the current Windows settings and the presence of a dns cache. However, there is an easy way to clear the cache to apply hosts file settings.

Note: Read more about dns in the DNS Device review.

How to reset dns cache in windows 7 to apply settings in hosts file?

As already mentioned, in order for the settings of the Windows 7 hosts file to be applied, you must either wait until Windows updates the dns cache, or reset it manually. And here's how you can do it:

  1. Close all programs that use Internet connections, including browsers.
    • Footnote: If you need access only through browsers, then close them. Other programs will pick up the settings later.
  2. Enter the following command:
    • ipconfig /flushdns
  3. Press enter and wait until the phrase appears
    • DNS resolver cache cleared successfully

In most cases, this will be enough to update the dns cache.

Note: If for some reason the cache has not been updated, then restart the computer. If this does not help, then you need to start searching for the cause with the program that did not pick up the settings. For example, browsers also have their own dns cache and sometimes they may not immediately pick up the settings, although this should not be the case.

As you can see, there is nothing complicated in using the hosts file.

Now, you know how to use the Windows hosts file for security purposes to block and redirect websites.


  • RKill is a free program to clean an infected computer from malware

Technical Tips

  • File hosts establishes a correspondence between the server IP and the site domain. Requests to this file take precedence over requests to DNS servers. Unlike DNS, the content of the file is controlled by the computer's administrator.

    To date, a large number of malicious programs use the file hosts to block access to websites of popular portals or social networks. Often, instead of blocking sites, malware redirects the user to pages that look like popular resources (social networks, mail services, etc.), where an inattentive user enters credentials, which thus get to attackers. It is also possible to block access to the websites of anti-virus software companies.

    hosts file location

    Default file hosts located here C:\Windows\System32\drivers\etc The file has no extension, but it can be opened with notepad. To change the contents of a file in notepad, you must have administrator rights.

    To view a file hosts open the menu Start, select an item Run, enter the command

    and press the button OK

    This is what the file should look like hosts default.

    If the file contains entries like 127.0.0.1 odnoklassniki.ru 127.0.0.1 vkontakte.ru or the addresses of your sites that you cannot access, then first check your computer for "malware", and then restore the file hosts

    Restoring the contents of the hosts file to default

    • Open the menu Start, select an item Run, enter the command
      %systemroot%\system32\drivers\etc

      and press the button OK.

    • Rename the hosts file to hosts.old.
    • Create a new file hosts default. To do this, follow the steps below.
    1. Right click in an empty space in the folder %WinDir%\system32\drivers\etc, select an item Create, click an element Text Document, Enter your name hosts and press the key ENTER.
    2. Click the button Yes to confirm that the filename will not have an extension TXT.
    3. Open a new file hosts in a text editor. For example, open the file in the program " Notebook".
    4. Copy the text below into a file.
      # 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:
      #
      # 102.54.94.97 rhino.acme.com # source server
      # 38.25.63.10 x.acme.com # x client host

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

    Save and close the file.

    You can edit the file hosts and in Notepad, delete unnecessary lines, or add your own. To do this, you need to run Notebook in mode administrator.

    How to run standard Windows programs, see

    What is the Hosts file for?
    The purpose of this system file is to assign certain IP addresses to certain site addresses.
    This file is very fond of all kinds of viruses and malware in order to write their data into it or simply replace it.
    The result of these actions may be signs of "inserting" the site into browsers, which will ask to send SMS when the browser is opened, or blocking various sites, at the discretion of the creators of the virus.

    Where is the hosts file in windows?
    For different versions of Windows, the location of the hosts file is slightly different:

    Windows 95/98/ME: WINDOWS\hosts
    Windows NT/2000: WINNT\system32\drivers\etc\hosts
    Windows XP/2003/Vista/Seven(7)/8: WINDOWS\system32\drivers\etc\hosts


    And the ending hosts, this is already the target file, not the folder. He doesn't have .

    What should the correct hosts file look like?
    The "content" of the hosts file is also slightly different for different versions of windows, but not much. It is "written" in English for what it is needed and how to make exceptions with one example. All lines that begin with a # sign mean that they are commented out and do not affect the file.
    The contents of the original hosts file for Windows XP:


    #

    #




    #space.
    #


    #
    # For example:
    #



    127.0.0.1 localhost


    Contents of the original hosts file for Windows Vista:

    # Copyright (c) 1993-2006 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:
    #
    # 102.54.94.97 rhino.acme.com # source server
    # 38.25.63.10 x.acme.com # x client host
    127.0.0.1 localhost::1 localhost


    The contents of the original hosts file for Windows 7:

    # 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:
    #
    # 102.54.94.97 rhino.acme.com # source server
    # 38.25.63.10 x.acme.com # x client host
    # localhost name resolution is handled within DNS itself.
    # 127.0.0.1localhost
    # ::1 localhost


    The contents of the original hosts file for Windows 8:

    # 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:
    #
    # 102.54.94.97 rhino.acme.com # source server
    # 38.25.63.10 x.acme.com # x client host

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


    As you can see, there are no special differences in the content of the host file for different versions of windows.

    How to open and edit the hosts file?
    The hosts file can be found in standard Windows Notepad.
    This is probably the most interesting part of the article.
    First of all, you need to understand why change this file at all? Yes, in order to deny access to certain sites. Thus, by changing this file and writing the site address into it, the user will not be able to access it through any .
    In order to change the hosts file, it is advisable to open it as an administrator () by right-clicking on the file and selecting "Run as administrator". Or open Notepad in this way and open the file in it.

    For quick action, you can simply click the Start button and select Run ( win+r) () and enter in the line:

    notepad %windir%\system32\drivers\etc\hosts



    This will open the file in Notepad.

    In order to block access to the site(suppose it will be test.ru ), you just need to add a line with this site to the very bottom:

    127.0.0.1 test.ru


    As a result, the file will have the following content:

    # Copyright (c) 1993-1999 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:
    #
    # 102.54.94.97 rhino.acme.com # source server
    # 38.25.63.10 x.acme.com # x client host

    # This HOSTS file created by Dr.Web Anti-rootkit API

    # 127.0.0.1localhost
    # ::1 localhost
    127.0.0.1 test.ru


    Each new site that you want to block, you need to start on a new line and write, not forgetting the local IP address 127.0.0.1

    Also, to edit the hosts file, there is a program HOSTS EDITOR, which you can download and read the description from.
    The principle of her work is that she helps to edit the hosts file.
    From the screen below, the principle of its operation is clear, everything is done in a couple of clicks. Adding is done by clicking on + .


    After editing, do not forget to click on the save button (2 "Save changes" button to the left of the "+" button).

    You can also change this file for good purposes, for example speed up website loading.
    How it works?
    When you enter the site, you see its domain name, which has letters. But all sites on the Internet have an IP address, and the names are already assigned using DNS. I will not go into the details of this process, the article is not about that. But here you need to know that the hosts file has priority when accessing sites, and only after it is a DNS request.
    In order to speed up the loading of the site, you need to know its IP address and domain.
    The IP address of a site can be found using various services, for example, or.
    Domain is the name of the site.
    For example, let's speed up the loading of this site on which you are reading an article by explicitly specifying the IP address and domain for the file.
    Then the added line will be:

    91.218.228.14 site


    This speeds up the loading of the page in a couple of seconds, and sometimes it can give access if you cannot access the site using standard means.

    More with possible redirect to another site using the hosts file.
    To do this, you need to know the IP address of the site and its domain (as in the case described above), then the added line will be like this:

    91.218.228.14 test.ru


    And now, after entering the site test.ru into the address bar of the browser, you will be redirected to the site specified in the IP address..

    If you want to clean hosts file, then you can do this by simply deleting the content and inserting the original text into it, from the description above (under the spoilers).

    Some nuances in the hosts file:

  • Always make sure you have a scroll bar on the side and always scroll down the window. this is due to the fact that some viruses are registered in the area hidden outside the window.
  • In some cases, usually if you can't save the file, you need to log in with an Administrator account.
  • Sometimes, due to viruses, this file may be hidden. Read the article.
  • In the two methods described (redirection and acceleration), the desired result may not be obtained. The fact is that several sites can be located on one IP address, this is especially true for external IP addresses that provide services.
  • Due to the fact that viruses love this file, its attributes can be changed to Hidden and Read-only.
  • Check the file attributes if you cannot save the hosts file.

    Thus, you can easily and free of charge block access to sites in Windows by editing the hosts file.

  • After entering the desired site in the browser, suppose Google.com , the browser sequentially (according to priority) looks for a mapping of this domain name to an IP address (because network devices work with IP addresses).

    a) the specified site is checked in the hosts file, if it finds a match (suppose 1.1.1.1 Google.com is written in the hosts file), then the contents of IP - 1.1.1.1 will open accordingly, if there is no specified domain name, proceed to the next step;

    b) the dns cache is checked (if you previously opened Google.com, then most likely the IP of this site was stored in the DNS cache of your computer / laptop), if the IP of the site is indicated there, then the page opens for you, if not, it proceeds to the last stage;

    in) the request goes to the DNS server (it is registered manually in the network connection settings or issued via DHCP), if the specified site is not in the DNS server, it will "ask" another DNS server until it finds it (if, of course, it exists at all) and the site is successfully will open.

    The hosts file is located along the path C:\Windows\System32\Drivers\etc\hosts (if C is the system drive). You can open it with regular notepad. If you have not made changes to the hosts file, then the following will be written there:

    hosts file in Windows XP:
    # Copyright (c) 1993-1999 Microsoft Corp.
    #
    #


    #space.
    #

    #
    # For example:
    #

    127.0.0.1 localhost

    hosts file in Windows Vista:
    #
    # 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:
    #
    # 102.54.94.97 rhino.acme.com # source server
    # 38.25.63.10 x.acme.com # x client host

    127.0.0.1 localhost
    ::1 localhost

    hosts file in Windows 7:
    # Copyright (c) 1993-2006 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:
    #
    # 102.54.94.97 rhino.acme.com # source server

    # 38.25.63.10 x.acme.com # x client host

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

    hosts file in Windows 8

    # 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:
    #
    # 102.54.94.97 rhino.acme.com # source server
    # 38.25.63.10 x.acme.com # x client host

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

    As you can see, regardless of the version, the host file does not differ much, but if a virus "worked" on the hosts file, various sites and IP-shniks can be added there. For example:

    127.0.0.1 ftp.kasperskylab.ru
    127.0.0.1 ids.kaspersky-labs.com
    127.0.0.1 vk.com
    127.0.0.1 drweb.com

    Such additions to the file prevent you from accessing the specified sites.

    1.2.3.4 ftp.kasperskylab.ru
    1.2.3.4 ids.kaspersky-labs.com
    1.2.3.4 vk.com
    1.2.3.4 drweb.com

    Such additions to the file when opening the specified sites will redirect you to other sites, possibly infected with viruses (IP-1.2.3.4- are fictitious).

    If you find that the hosts file has changed, you need to fix it. In Windows XP, the file is simply opened in notepad, the necessary changes are made and saved (you must be logged in as an administrator). On other versions (Windows Vista, 7, 8) you need to give permission to modify the file. To do this, open the folder in which hosts is located C:\Windows\System32\Drivers\etc(if drive C is system). Right click on hosts and choose "Properties".

    Choose a tab "Safety", then select the user under which you work on a computer / laptop (in this example, this is a website) and press the button "Change". A window will open "Permissions for group "hosts"", select the user again and assign full rights to the file, click "OK", in the window "Properties: hosts", too "OK".

    After that, open hosts with Notepad and return the file to its original state, when finished, save the changes.