Hosts is a system file without extension, can be opened with Notepad and other tools, its role is to use some of the common URL domain name and its corresponding IP address to establish an association "database", when the user in the browser to enter a need to log in the URL, The system will automatically find the corresponding IP address from 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. A browser accesses a Web site by first resolving the domain name of the site to be accessed through a DNS server to a unique IP address, after which the browser can locate and access its data. The operating system stipulates that before a DNS request is made, check whether the domain name and IP mappings are in the system's own hosts file. If so, direct access to the network location specified by this IP address and, if not, a domain name resolution request to a known DNS server. In other words, the hosts have higher IP resolution precedence than DNS. The above contents are copied from the Baidu encyclopedia. File path: C:\WINDOWS\system32\drivers\etc. How to modify the Hosts file Hosts file the original content as follows:
# Copyright (c) 1993-2009Microsoft corp.## This was a sample HOSTS file used by Microsoft TCP/IP forwindows.## This file contains the mappings for IP addresses to host names. each# entry should is kept on a individual line. The IP address should# is placed in the first column followed by the corresponding host name.# the IP address and the host Name should is separated by at least one# space.## Additionally, comments (such as these) may is inserted on individual# Lines or following the machine name denoted by a‘#‘symbol.## for example:##102.54.94.97rhino.acme.com # source server#38.25.63.10x.acme.com # x client host # localhost name resolution is handled within DNS itself.#127.0.0.1localhost#::1 localhost
In the end, add the following:
127.0.0.1 www.163.com
Indicates that the domain name "www.163.com" points to an IP of 127.0.0.1, which is local. The contents of the modified file are as follows:
# Copyright (c) 1993-2009Microsoft corp.## This was a sample HOSTS file used by Microsoft TCP/IP forwindows.## This file contains the mappings for IP addresses to host names. each# entry should is kept on a individual line. The IP address should# is placed in the first column followed by the corresponding host name.# the IP address and the host Name should is separated by at least one# space.## Additionally, comments (such as these) may is inserted on individual# Lines or following the machine name denoted by a‘#‘symbol.## for example:##102.54.94.97rhino.acme.com # source server#38.25.63.10x.acme.com # x client host # localhost name resolution is handled within DNS itself.#127.0.0.1localhost#::1localhost127.0.0.1 www.163.com
When modified, accessing "www.163.com" with a browser is resolved to 127.0.0.1, which prevents the page from being displayed.
For further verification, use Tomcat to start a Web service locally. The Tomcat version is: apache-tomcat-8.5.4, other versions should operate similarly.
After downloading the extract tomcat, run Apache-tomcat-8.5.4\bin\startup.bat, and if Tomcat starts successfully, a Web service will be available locally.
Then visit "www.163.com:8080", you can see the page content:
Why add 8080, because this is the port number, the Tomcat-enabled Web service uses 8080 ports by default, and the default in the browser is 80 ports, so it is necessary to display the indicated. You can also modify 8080 in Config/server.xml in the Tomcat installation directory to 80 so that you do not have to explicitly specify a port on access.
This is the way to make the domain name point to an IP by modifying the Hosts file, and if you need to add more than one configuration, you will be given a new line of content.
Modify the window local Hosts file, modify the domain name to point to