• Reset the hosts file. Contents of the hosts file. Where is the hosts file located?

    Windows is far from Linux in terms of the systematic use of configuration files to customize the functionality of the operating system. First of all, because Windows uses the registry for this.

    But still, there are such files in Windows, and it is sometimes useful to know their purpose. An important repository of configuration options includes a file called Hosts. The file name does not have an extension, so you do not need to specify it during automatic search.

    In the course of the presentation, we will focus on the seventh version of the OS, as the most widely used by consumers (Microsoft's tricks in the G8 failed to convince users that Metro is cool).

    Essentially, we are dealing with a repository of domain names, similar to DNS server names. The benefit of using it is that the computer owner is able to regulate the priorities of domains when translating them into real network addresses when accessing Internet resources.

    File domains have priority over any external DNS addresses, even those specified in the network connection settings. The default storage location in 7 looks like this: %SystemRoot%\system32\drivers\etc\hosts. However, this path is not possible. The system administrator can override it by changing the registry key named HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\DataBasePath. Files with the same name and purpose are included not only in the Windows system environment; they can be found in Unix-like operating systems, Mac-OS and even on the Android platform.

    Internal structure of Hosts records and storage manipulation

    Although Hosts does not have an extension, from the inside it looks like a regular test file with entries in approximately the following format: 127.0.0.1 localhost. That is, with a structure consisting of a domain's IP address and its symbolic name, separated by spaces or a tab character.

    The example given is a mandatory entry in any such file. It corresponds to the address and name of the user's machine itself. All other entries look similar to this one. With the help of the information placed here, a variety of problems can be solved. For example:

    • You can associate the name localhost not with the address of the local machine, but with the address of any computer on the enterprise intranet. This is often done by system administrators of enterprises and organizations.
    • Similar associations can be used to optimize access to external hosts. If you create a record with a range of IP addresses corresponding to the real addresses of the desired sites, then their pages will load faster than when accessing the provider’s DNS database.
    • Another useful option is the ability to organize blocking of unwanted domains (for example, domains of advertising sites). To do this, all such domains are assigned a local machine address – 127.0.0.1

    In principle, hosts is an outdated technology, supported for reasons of backward compatibility.

    In addition, it has a serious drawback: if the network connection uses an intermediate proxy server, then all storage entries are simply ignored. There are also security concerns.

    The fact is that many viruses like to dig into the contents of a file and change it at their discretion. One of the recommendations given in the event of a virus attack is to open the file in Notepad and delete from it all entries located below the localhost entry.

    The hosts file is responsible for establishing a correspondence between the domain and the site's IP address. Contacting the host takes precedence over sending a request to the DNS server, and the file is stored on the computer and controlled by the administrator, which makes it an important element of the secure operation of Windows. In some cases, users are faced with the need to restore the hosts file to its original state. You can delete unnecessary entries from it in two ways: manually and automatically, using special software.

    Manual recovery

    Typically, restoration of the hosts file is required after malicious applications add new entries to it. A typical attack looks like this: you open Odnoklassniki or VKontakte, and the site informs you that your account is blocked and asks you to send an SMS to confirm your login. As a result, money is withdrawn from the phone, and you later find out that instead of VKontakte, the hosts file redirected you to a fake page.

    But the host has nothing to do with it: it only turned out to be a tool in the hands of malicious software. Therefore, after cleaning Windows with an antivirus, you need to start restoring hosts.

    Another option is to go to C:\Windows\System32\drivers\et and simply open hosts via Notepad. Inside you will see a lot of text in English. You need to make sure there are no extra entries in the host. By default, the text should end with the line "# ::1 localhost". Everything after it should be deleted, especially if you yourself did not enter anything into the file.

    However, this cleaning may not be complete, so we strongly recommend that you match the contents of your host with the information provided on the support page at https://support.microsoft.com/ru-ru/kb/972034. On Windows 7, the contents of hosts should look like this:

    To make sure there are no extra entries, delete the old host and create a new file:


    Now the old host will not function, and there will definitely be nothing unnecessary inside the new one, so you don’t have to worry about the safety of your money and personal data.

    Automatic recovery

    If manual recovery seems difficult, you can fix the host using special utilities. For example, Microsoft technical support, in an article about fixing the hosts file on different versions of Windows, suggests downloading the Fix It utility, after running which unnecessary entries will be deleted without user intervention.

    Another way is to use the AVZ antivirus program. This is a powerful Windows research and recovery tool, but we will only look at one of its functions - cleaning the hosts file.

    The article covers the following questions: where is the hosts file in Windows 7, Windows 8, Windows 10; contents of the hosts file, how to edit it; how to save the hosts file if access is denied.

    Hosts file - what is it, what is it for?

    What is this

    hosts - a file containing a database of IP addresses and domain names corresponding to them. For example, for the popular site VKontakte the correspondence will be as follows:

    87.240.131.118 vk.com

    The hosts file on Windows is opened using the application Notebook.

    What is it for?

    Letter website addresses were invented exclusively for people, since it is easier for a person to remember. Computers find sites by numbers. Using the same VKontakte as an example: vk.com is a letter address (or they say URL), and 87.240.131.118 is a digital address (or IP address).

    Check my words. Enter in the address bar of your browser
    87.240.131.118
    You must go to the site https://vk.com/.

    All matches between IP addresses and URLs are stored on DNS servers, which the browser contacts and opens to us the desired site.

    But before contacting the DNS server, the browser always checks the hosts file. In it we can prohibit the opening of sites, or replace the correspondence between the IP address and the URL.
    This is what viruses do on the computer, replacing matches, adding other lines to this file, etc. For information about the lines that need to be entered into such a file, see the chapter “How commands that need to be entered

    What should the hosts file look like? Contents of the hosts file

    The hosts file should have the following:

    For Windows XP:

    # Copyright (c) 1993-1999 MicrosoftCorp.
    #

    #




    #space.
    #


    #
    # For example:
    #

    127.0.0.1 localhost

    For Windows Vista:


    # Copyright (c) 1993-2006 MicrosoftCorp.
    #
    # 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

    For Windows 7, 8, 8.1, 10:

    # 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.1 localhost
    # ::1 localhost

    Where is the hosts file located in Windows 7, Windows 8, Windows 10

    The hosts file is located in all versions of Windows at
    See screenshots:

    How to open the hosts file

    This file can be opened using Notepad. Find this application in the start menu. Right-click. In the menu that appears, select “Run as administrator.” In the Notepad window that opens, through the “File” → “Open…” menu, open the hosts file, writing the file address in the address bar of the window that opens or moving from folder to folder until we find it.

    How to edit the hosts file

    1. Recovery

    To restore a file you need:
    1. Open the file using Notepad as administrator.
    2. Copy the contents of the file from this article, paste with replacement and save.
    Attention!
    The file should only be opened through Notepad running as administrator. Otherwise, you will not be able to save the changes. When we save the .txt extension in the file name, we remove it.

    Tricks of a modified hosts file

    1. Some viruses disguise their changes after lines
    127.0.0.1 localhost
    ::1 localhost

    They leave a lot of spaces and only then add lines.

    Therefore, when replacing content, select all content (hot keys CTRL+A).

    2. The file is hidden
    If there is no file in the specified package, then it may have been hidden and assigned the “Hidden” attribute.
    In the menu View → Options → View, check the “Show hidden files, folders and drives” checkbox.




    Now that the file has appeared, in the file properties, uncheck the “Hidden” checkbox.

    3. Cannot be edited
    The file has been assigned the Read Only attribute. In the file properties, uncheck the corresponding box.


    To folder C:\Windows\System32\drivers\etc place a file with the name hosts, but with the extension .txt(hosts.txt file) or without an extension, like the hosts file, but with a different name, for example, host.

    2. Change

    To block access to a certain site, you need to enter the lines at the end of the content
    (Skip line)
    127.0.0.1 (several spaces) (Domain name to block)
    127.0.0.1 (several spaces) (Name of the blocked domain from www.)

    Using the example of the same VKontakte and Odnoklassniki:


    Let's save. We check our work by entering the URL of these sites into the address bar of the browser. Sites do not open. Bingo!

    In this way, you can block computer gaming sites, casino sites, pornographic sites, etc.

    To redirect, we do everything as before, but we give the desired URL a different IP.

    Example. Let the site https://vk.com/ open when you log in to VKontakte and Odnoklassniki
    We write the lines:
    (Skip line)
    87.240.131.118 vk.com
    87.240.131.118 www.vk.com
    87.240.131.118 ok.ru
    87.240.131.118 www.ok.ru

    2.3. Popular sites and their IP addresses

    87.240.131.118 https://vk.com/
    213.180.193.3 https://ya.ru
    5.61.23.5 https://ok.ru/

    The Internet is full of services to determine the IP addresses of any websites. Google it.

    hosts access denied - what to do

    If you cannot save the file and access is denied. We do it in order, trying to save the file after each item.
    1. Open in Notepad as administrator.
    2. Copy the file to your desktop. Change it. The hosts file remaining in the folder C:\Windows\System32\drivers\etc rename it to hosts.old. Copy the hosts file you edited on your desktop to the folder C:\Windows\System32\drivers\etc.
    3. Turn off antivirus. Antivirus programs often ensure that no changes are made to this file. Add the file to Windows Defender exceptions. Starting from version 8, Windows makes sure that no one changes this file.
    4. We set access rights to the file in its properties on the “Security” tab.
    5. If you still can’t remove it, go to Safe Mode and try to remove it from under it.

    What happens if you delete the hosts file

    Nothing will happen. Unless there are problems with your Internet connection. During connection, the IP address 127.0.0.1 will have to be specified manually. It's possible that some programs will ask for localhost instead of 127.0.0.1, which will create another problem.

    This is exactly the question asked by users who are trying to unblock access to Odnoklassniki and VKontakte. In fact, it may turn out that only the visible hosts file is empty, but there is also a hidden hosts file, which blocks access to the most popular sites.

    Let's look at a specific example. You are unsuccessfully trying to log into Odnoklassniki and VKontakte, but you are unable to do so.

    When I try to log into Odnoklassniki, a message appears Incorrect login and/or password.

    When you try to log in to VKontakte, a message appears This email address is not registered or the password is incorrect.

    Then you find information on the Internet that you need to check the hosts file.

    The hosts file is located at C:\Windows\System32\drivers\etc. We go to the etc folder in which we find the hosts file.

    We open the hosts file using Notepad and find that the file is empty.

    We open the hosts file and find that it is empty

    What to do if the hosts file is empty?

    Recently, cases have become more frequent when another hosts file appears in the etc folder, but it has the attributes of a system file, i.e. is hidden. In order to see it, you need to enable the option. After enabling the option to display hidden files, it turned out that there are not one, but two hosts files in the ets folder.

    There are foreign entries in the hidden hosts file

    Can the hosts file be empty?

    I will say right away that, in principle, in Winows 7 the hosts file can be empty, since in the standard hosts file all lines begin with the # sign, i.e. are comments. The hidden hosts file can be safely deleted.

    To delete a file, you will need administrator rights.

    After deleting the hidden hosts file, access to Odnoklassniki and VKontakte should be restored.

    Attention! Even if you managed to restore access to sites after deleting the hidden hosts file, be sure to

    Evgeny Mukhutdinov

    Hosts is a text file containing a database of domain names and used when translating them into network addresses of hosts. A request to this file takes precedence over calls to DNS servers. Unlike DNS, the contents of the file are controlled by the computer administrator. All of the above means that with the help of this file you can very easily and simply set up access to any of the existing Internet resources. Let's say you wanted to block access to one of the popular social networks, for example. To do this, you will have to write just a few lines in hosts and save the changes. After this, any user who uses your computer will simply not be able to get into VK, since access will be denied. Of course, with a set of minimal knowledge, this prohibition is easily circumvented.

    An ordinary user should theoretically know nothing about the hosts file, since it simply has no use for him. Alas, modern realities are such that we have to learn a lot of new things. The fact is that in the last few years a lot of fraudulent organizations have appeared that use hosts to steal personal information, as well as to take money from a person by redirecting him to other sites for the purpose of extortion. So that you understand what I'm talking about, I'll give you an example. Let's say you decide to go to the same VK. Only instead of your page, you see a warning in which you are asked to send an SMS to a short number in order to make sure that you are a real person and not a robot. There may be other reasons, in this case it does not matter. You send a message, after which money begins to be debited from your account. This is the fraud of which you have become a participant. You must immediately call your telecom operator, explain the situation and ask for a refund to your account. Most likely, you will have to write a written statement, after which the funds will be returned to you, since they were withdrawn from the account illegally.

    How could this happen? Using the hosts file, you are automatically redirected to a fraudulent site, which only in appearance resembles the usual VKontakte, while the address in the line may be real (that is, vk.com). However, this is not VK. To verify this, you can open hosts and see extra lines like 111.222.333.333 vk.com, with the help of which the redirection occurs.

    Another question arises - how can the hosts change? Yes, it’s very simple: to do this, you just need to install a Trojan on your PC, which will carry out the entire operation without your knowledge. And you can pick it up on almost any website.

    So, now let's move on to the main question, namely: what does the file look like? Let me say right away that it varies slightly depending on the operating system.

    Windows XP

    # Copyright (c) 1993-1999 Microsoft Corp.
    #

    #




    #space.
    #


    #
    # For example:
    #

    127.0.0.1 localhost

    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

    Windows 7 and 8

    # 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 handle within DNS itself.
    # 127.0.0.1 localhost

    As you can see, the files are practically no different from each other, with some differences. However, I recommend using your own hosts for each operating system. Just copy the specified data.

    By the way, the files are located in the following sections:

    • In Windows XP/2003/Vista/7/8 C:\WINDOWS\system32\drivers\etc\hosts
    • On Windows NT/2000: C:\WINNT\system32\drivers\etc\hosts

    If you do not have the ability or desire to change this file yourself, you can use a utility called, which I recently talked about - it automatically changes the contents of hosts if it contains extra characters.