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 use batch bat to change hosts

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article will explain in detail how to use batch bat to change hosts. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

What is Hosts:

Hosts is a system file without an 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 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 specific functions of Hosts files are:

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

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

Change the batch processing of hosts files with bat

@ echo offecho "Please pay attention to your antivirus software tips Be sure to allow "@ echo # # @ xcopy C:\ Windows\ system32\ drivers\ etc\ hosts C:\ Windows\ system32\ drivers\ etc\ hosts.bak\ / d / c / I / y @ echo # # @ echo hosts file backup completed Start modifying hosts file @ echo @ echo 117.79.149.116 search.b2b.cn > > C:\ Windows\ System32\ drivers\ etc\ hosts@echo 117.79.149.116 news.search.b2b.cn > > C:\ Windows\ System32\ drivers\ etc\ hostsecho "hosts file modification completed" @ ipconfig / flushdns@echo "refresh DNS completed" echo hosts file modification completed Press any key to restore the original state of the system @ echo@echo # # @ pause > nul@copy C:\ Windows\ System32\ drivers\ etc\ hosts.bak\ hosts C:\ Windows\ System32\ drivers\ etc\ hosts / y@echo @ echo offecho hosts, press any key to exit @ echo@ pause > nul@exit

Set up a local test environment:

@ echo offecho set up the local test environment echo.c:cd\ if not exist lmhy-test\ con md lmhy-testif exist lmhy-test\ hosts.bak goto backup_existsecho is creating a backup. Cd\ windows\ system32\ drivers\ etccopy / y hosts\ lmhy-test\ hosts.bak > nullecho complete! The echo.goto backup_start:backup_existsecho backup file already exists and no backup is required. Echo.:backup_startecho is writing test data... Echo 127.0.0.1 localhost > hostsecho 192.168.1.170 lmhy.com > > hostsecho 192.168.3.170 www.lmhy.com > > hostsecho 192.168.3.170 php.lmhy.com > > hostsecho 192.168.3.170 test.lmhy.com > > hostsecho complete! Echo.echo completes the establishment of lmhy local test environment. Press any key to exit. Pause > null

Uninstall the local test environment:

@ echo offecho uninstall the local test environment echo.c:cd\ if not exist lmhy-test\ hosts.bak goto backup_not_existsecho is restoring the backup. Copy / y\ lmhy-test\ hosts.bak\ windows\ system32\ drivers\ etc > nullcd\ windows\ system32\ drivers\ etcif exist hosts del / Q hostsren hosts.bak hostsecho complete! Echo.echo is removing backups... Cd\ rmdir / sUnip Q\ lmhy-test\ echo complete! The echo.goto backup_done:backup_not_existsecho backup file does not exist and cannot be restored.

(note: if 360 is installed, an alert box will appear when running changes. Just click run.)

On "how to use batch bat to change hosts" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

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

Development

Wechat

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

12
Report