What are Hosts:
Hosts is a system file without an extension. It can be opened with tools such as Notepad. Its function is to establish a "database" for some commonly used URL domain names and their corresponding IP addresses. When the user enters a URL that needs to be logged in to the browser, the system will first automatically find the corresponding IP address from the Hosts file. Once it is found, the system will immediately open the corresponding web page. If it is not found, the system will submit the URL to the DNS domain name resolution server for IP address resolution.
The specific functions of the Hosts file:
Now let’s take a look at how the Hosts file works and what role it plays in specific use.
1. Speed up domain name analysis
For websites that you want to visit frequently, we can improve the domain name resolution speed by configuring the mapping relationship between domain names and IPs in Hosts. 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 LAN users
In many units' local area networks, there will be servers provided to users. However, since DNS servers are rarely set up in LANs, when accessing these servers, you need to enter a difficult IP address. This is quite troublesome for many people. Now you can give these servers a name that is easy to remember, and then establish an IP map in Hosts. In this way, when accessing in the future, just enter the name of the server.
3. Block the website
Nowadays, many websites install various plug-ins on your computer without the user's consent, some of which may be *s 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 we don't need to access it. In the WINDOWS system, it is stipulated that 127.0.0.1 is the IP address of the local computer and 0.0.0.0 is the wrong IP address.
Use bat to change hosts file batch processing
@echo off echo "Please pay attention to your antivirus software prompts, be sure to allow it" @echo ######################################## @xcopy C:\Windows\system32\drivers\etc\hosts C:\Windows\system32\drivers\etc\\ /d /c /i /y @echo ######################################## @echo hostsFile backup completed,Start modifyinghostsdocument @echo @echo 117.79.149.116 search. >>C:\Windows\System32\drivers\etc\hosts @echo 117.79.149.116 . >>C:\Windows\System32\drivers\etc\hosts echo "Hosts file modification completed" @ipconfig /flushdns @echo "Refresh DNS Completed" echo hostsdocument修改完毕,Press any key to restore the original system state @echo @echo ######################################## @pause > nul @copy C:\Windows\System32\drivers\etc\\hosts C:\Windows\System32\drivers\etc\hosts /y @echo @echo off echo hostsdocument恢复完毕,Press any key to exit @echo @pause > nul @exit
Build a local test environment:
@echo off echo Build a local test environment echo. c: cd \ if not exist lmhy-test\con md lmhy-test if exist lmhy-test\ goto backup_exists echo Creating a backup…… cd \windows\system32\drivers\etc copy /y hosts \lmhy-test\ > null echo Finish! echo. goto backup_start :backup_exists echo The backup file already exists,No backup required。 echo. :backup_start echo Writing test data…… echo 127.0.0.1 localhost > hosts echo 192.168.1.170 >> hosts echo 192.168.3.170 >> hosts echo 192.168.3.170 >> hosts echo 192.168.3.170 >> hosts echo Finish! echo. echo Establish lmhy 本地测试环境Finish。Press any key to exit…… pause > null
Uninstall the local test environment:
@echo off echo Uninstall the local test environment echo. c: cd \ if not exist lmhy-test\ goto backup_not_exists echo Restore backup…… copy /y \lmhy-test\ \windows\system32\drivers\etc > null cd \windows\system32\drivers\etc if exist hosts del /q hosts ren hosts echo Finish! echo. echo Removing backup…… cd \ rmdir /s/q \lmhy-test\ echo Finish! echo. goto backup_done :backup_not_exists echo The backup file does not exist,Unable to recover。
(Note: If 360 is installed, a warning box may appear when running the modification. Click Run)