Principle and application of system Hosts file

The concept of hosts

Hosts is a system file without an extension, which can be opened with tools such as Notepad. Its function is to establish a "database" associated with some commonly used URL domain names and their corresponding IP addresses. When the user enters a login in the browser When the URL is found, the system will first automatically find the corresponding IP address from the Hosts file. Once found, the system will immediately open the corresponding webpage. If it is not found, the system will then submit the URL to the DNS domain name resolution server for IP address resolution. Hosts have a higher request level than DNS.

Modify the hosts file

The next key issue is how to modify the hosts file, where the hosts file is stored:

Edit and modify the hosts file in the above directory. There are many forms of implementation at present, the most direct is to use the file manager to overwrite the obtained hosts file with the hosts file of the system.

Hosts file format

127.0.0.1  localhos
t127.0.0.1  www.baidu.com
192.168.1.1 test.com

Domain name resolution flowchart

Principle and application of system Hosts file

Hosts specific role

1. Virtual domain name

Many times, website builders need to set up a "soft environment" before uploading and debugging. However, similar to the mail service, you need to use a domain name to assist debugging. At this time, you can point the local IP address to a "virtual domain name" to achieve the desired effect without cost.

For example: 127.0.0.1 www.gg.com, then enter the corresponding website domain name in the browser address bar.

2. Speed ​​up domain name resolution

For websites that are frequently visited, we can increase the speed of domain name resolution by configuring the mapping between domain names and IP in Hosts. When we enter the domain name, the computer can quickly resolve the IP without requesting a DNS server on the network.

3. Block websites (domain name redirection)

There are many websites that install various plug-ins into your computer without user consent, some of which may be Trojan horses or viruses.

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 visit.

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 are in Hosts, write the following:

127.0.0.1 # Website A to be blocked

0.0.0.0 # website B to be blocked

Such as:

127.0.0.1  www.hao123.com
127.0.0.1  www.baidu.com

In this way, when the computer resolves the domain names A and B, it resolves to the local IP or the wrong IP, thus achieving the purpose of blocking the websites A and B.

4. Convenient for LAN users

In many organizations' local area networks, there will be servers for users to use. However, since DNS servers are rarely set up in LANs, when accessing these servers, enter an IP address that is difficult to remember.

This is quite troublesome for many people. You can give these servers an easy-to-remember name, and then establish an IP mapping in Hosts, so that when you visit later, just enter the name of the server.

5. Connect the system smoothly

For Lotus servers and some database servers, if you directly enter the IP address during access, it cannot be accessed. You can only access it by entering the server name. Then we configure the Hosts file so that the server name can be entered to connect successfully.

6. Mandatory domain name resolution to specify IP

For example, some websites have many server IPs, and some IPs may be harmonized, so we can add the IP and domain name we want in the hosts file.

Such as:

# google Start

# google End

Note: This article is reproduced from https://laod.cn/hosts/hosts-yuanli.html

Guess you like

Origin www.cnblogs.com/zhaoqingqing/p/12738156.html