Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the working principle and function of Hosts files in operating system

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to understand the working principle and function of Hosts files in the operating system". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

What is a Hosts file?

Hosts is a system file without extension, and Hosts file is a file used to store node information in computer network. It can map the host name to the corresponding IP address and realize the function of DNS. It can be controlled by computer users. You can open it with notepad and other tools, and its function is to establish an associated "database" between some commonly used URL domain names and their corresponding IP addresses. When a user enters a URL that needs to be logged in in the browser, the system will first automatically look for the corresponding IP address from the Hosts file. Once found, the system will immediately open the corresponding web page, if not found. Then the system will submit the URL to the DNS domain name resolution server for IP address resolution.

The storage location of Hosts files varies from operating system to operating system, even to different Windows versions:

Windows NT/2000/XP/2003/Vista/win7: the default location is% SystemRoot%\ system32\ drivers\ etc\, but you can also change the location of the hosts file:

Location of the windows XP system: C:\ WINDOWS\ system32\ drivers\ etc

Contents of hosts file:

The code is as follows:

# 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

127.0.0.1 localhost

II. The working mode of Hosts files

We know that to access a website on the network, the computer can only access the network domain name (XXXX.com) through the DNS server after the IP address of the XXX.XXX.XXX.XXX is resolved.

If we have to wait for the domain name server to resolve and return IP information for each domain name request, the efficiency of accessing the network will be reduced, because it takes time for DNS to do domain name resolution and return IP.

In order to improve the resolution efficiency of frequently visited network domain names, we can achieve this goal by establishing the mapping relationship between domain names and IP in Hosts files. According to the policy of the Windows system, before making a DNS request, the Windows system will check whether there is this network domain name mapping relationship in its Hosts file. If so, call the IP address mapping, and if not, submit the domain name resolution to the known DNS server. In other words, Hosts has a higher request level than DNS.

Third, the specific function of Hosts file

1. Speed up domain name resolution

For websites that you want to visit frequently, we can improve the speed of domain name resolution by configuring the mapping between domain name and IP in Hosts. Because of the mapping relationship, when we enter the domain name, the computer can quickly parse the IP without having to request the DNS server on the network. It is important to point out that the mapping configured by the Hosts file is static, and if the computer on the network changes, please update the IP address in time, otherwise it will not be accessible.

2. Convenient for local area network users

In the local area network of many units, there are servers for users to use. However, because DNS servers are rarely set up in the local area network, it is necessary to enter difficult IP addresses when accessing these servers. This is quite troublesome for many people. You can now give each of 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.

3. Block websites

There are many websites that install a variety of plug-ins into your computer without the user's consent, some of which may be Trojans or viruses. For these sites, we can use Hosts to map the domain name of the site to the wrong IP or the IP of the local computer, so we don't have to visit it. In WINDOWSX systems, the convention 127.0.0.1 is the IP address of the local computer, and 0.0.0.0 is the wrong IP address.

If, in Hosts, we write the following:

The code is as follows:

127.0.0.1 www.XXXX.com # blocked website A

0.0.0.0 www.XXXX.com # blocked website B

In this way, when the computer resolves the domain names An and B, it resolves to the native IP or the wrong IP, thus achieving the purpose of blocking website An and B.

4. Connect the system smoothly

For Lotus servers and some database servers, if you enter the IP address directly when accessing, you can't access it, you can only enter the server name. So let's configure the Hosts file so that we can connect smoothly by entering the server name.

4. How to manually check and kill the virus that hijacked the HOSTS table

If you suspect that your hosts file has been modified by a virus Trojan, you can copy the above content to repair the hosts file. However, the fundamental measure is to find and delete virus files in the system. Here are the repair steps:

First of all, you have to enter safe mode.

.

Secondly, run regedit to delete the following items and look for HKEY_LOCAL_MACHINE\ SOFTWARE\ Microsoft\ Windows\ CurrentVersion\ Run

There are many possibilities behind, and two have been found so far! Name is R or A

1.R=C:\ Windows\ System32\ rundll32.exe ctfmon.dll s

2.A=C:\ WINDOWS\ system32\ rundll32.exe msad.dll s

If you find one of these two, delete the item directly.

Then find C:\ Windows\ System32\ ctfmon.dll or C:\ Windows\ System32\ msad.dll

Delete the file

Repair the HOSTS file (in fact, if you install and run the security guard in safe mode, it can already be repaired. The manual repair method is described here). Please do the following:

1. Search for the hosts file in the system, or you can find it according to the following path:

The code is as follows:

Windows 98 system, file path\ Windows directory

Windows XP system, file path\ Windows\ System32\ Drivers\ Etc directory

Windows 2000 system, file path: WINNT\ System32\ Drivers\ Etc directory

WIN7 system, file path: WINNT\ System32\ Drivers\ Etc directory

two。 Back up this file first

3. Right-click the hosts file, select {Open method}, and select notepad

4. Delete the contents of notepad, or simply delete the hosts file! (does not affect the normal use of the system)

Note: please do not directly use notepad and other text tools to modify professional editors such as UltraEdit will not cause garbled and other problems.

This is the end of the content of "how to understand the working principle and function of Hosts files in the operating system". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report