The path of the hosts file is "C:\Windows\System32\drivers\etc". Hosts is a system file without an extension. Its function is to establish an associated "database" between some commonly used URL domain names and their corresponding IP addresses. When the user enters a URL that needs to be logged in in the browser, the system will first automatically start from Find the corresponding IP address in the Hosts file and open the corresponding web page; if not found, the system will submit the URL to the DNS domain name resolution server for IP address resolution.
The operating environment of this tutorial: Windows 7 system, Dell G3 computer.
Hosts is a system file without extension, which can be opened with Notepad and other tools. Its function is to establish an associated "database" between some commonly used URL domain names and their corresponding IP addresses. When the user opens the browser When you enter a URL that needs to be logged in, the system will first automatically search for the corresponding IP address in the Hosts file. Once found, the system will immediately open the corresponding web page. If not found, the system will submit the URL to the DNS domain name resolution server for IP Address resolution.
It should be noted that the mapping configured in the Hosts file is static. If the computer on the network changes, please update the IP address in time, otherwise you will not be able to access it.
Working Principle
When a browser accesses a website, it must first resolve the domain name of the website to be accessed into its designated IP address through the DNS server. After that, the browser can Locate this website and access its data.
The operating system stipulates that before making a DNS request, first check whether there is a mapping relationship between the domain name and IP in your own Hosts file. If there is, then directly access the network location specified by this IP address. If not, then make a domain name resolution request to a known DNS server. In other words, the IP resolution priority of Hosts is higher than that of DNS.
The storage location under windows
The location of the hosts file is different in different operating systems (or even different Windows versions). The address under windows is :
C:\Windows\System32\drivers\etc
##Opening method:
##Windows version original host file content:
# 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
If you suspect that your hosts file has been modified by a virus or Trojan, you can copy the above content to repair the hosts file.
It is worth mentioning that # is followed by comments, so clearing the hosts file has no impact on the normal operation of the system.
The role of Hosts file1. Speed up domain name resolution
For websites that we want to visit frequently, we can configure the domain name and IP in Hosts Mapping relationship to improve domain name resolution speed. Due to the mapping relationship, when we enter the domain name, the computer can quickly resolve the IP without requesting the DNS server on the network.
2. Convenient for LAN users
In the LAN of many units, there will be servers available for users to use. However, since DNS servers are rarely set up in local area networks, when accessing these servers, you have to enter IP addresses that are difficult to remember. This is quite troublesome for many people. You can give these servers names that are easy to remember, and then establish IP mapping in Hosts, so that when you visit in the future, you only need to enter the name of the server.
3. Block websites (domain name redirection)
There are many websites that install various plug-ins into your computer without the user’s consent. Some of them may be Trojan horses or Virus. For these websites, we can use Hosts to map the domain name of the website to the wrong IP or the IP of the local computer, so that there is no need to access it. In the WINDOWS system, it is agreed that 127.0.0.1 is the IP address of the local computer, and 0.0.0.0 is the wrong IP address.
If we write the following content in Hosts:
127.0.0.1要屏蔽的网站A的域名 0.0.0.0要屏蔽的网站B的域名
In this way, when the computer resolves domain names A and B, it will resolve to the local IP or the wrong IP, thus blocking the website The purpose of A and B.
4. Smooth connection to the system
For Lotus servers and some database servers, if you directly enter the IP address during access, you cannot access it. You can only access it by entering the server name. Then we configure the Hosts file so that we can connect smoothly by entering the server name.
5. Virtual domain name
Many times, website builders need to build the "soft environment" before uploading and debugging. But similar to the mail service, you need to use a domain name to assist debugging. In this case, you can point the local IP address to a "virtual domain name" to achieve the required effect without any cost. For example:
127.0.0.1 网站域名
and then enter the corresponding website domain name in the browser address bar.
For more related knowledge, please visit the
FAQThe above is the detailed content of What is the path to the windows hosts file. For more information, please follow other related articles on the PHP Chinese website!