Modify the hosts file to resolve the Domain Name

Source: Internet
Author: User

Sometimes, we need to bind a domain name to test some network systems locally (some systems only support domain name access), but because it is a testing machine, it is not a real server, and there is no need to resolve the real domain name to the IP address of the test machine.

At this time, we do not need to modify the domain name resolution record, but modify the hosts file of the machine where the browser is located, pointing to the IP address of the machine where your Apache is located, which can accomplish the task well.

For Linux, modify/Etc/hostsFile.

For Windows, the hosts file is stored in the following locations:

Windows 95/98/me c: \ windows \ hosts
Windows NT/2000/xp pro c: \ winnt \ system32 \ drivers \ etc \ hosts
Windows XP Home c: \ windows \ system32 \ drivers \ etc \ hosts

For example, if you want to resolve the domain name localhost. localdomain to the IP address 10.67.6.54 of your intranet server, you just need to add this sentence to the hosts file:

10.67.6.54 localhost. localdomain

According to the regulations of Windows and Linux systems, before a DNS request is made, the system will first check whether there is a ing relationship between the domain name and address in its hosts file. If yes, this IP address ing is called. If no domain name resolution is provided to a known DNS server. That is to say, the request level of hosts is higher than that of DNS.

This hosts file can be used flexibly for the following purposes:

1) Accelerate domain name resolution

For websites that require frequent access, we can configure the ing between the domain name and IP address in hosts so that when we enter the domain name, the computer can quickly resolve the IP address, instead of requesting DNS servers on the network.

2) Facilitate LAN users

In the LAN of many organizations, servers are provided for users. However, because DNS servers are rarely set up in Lan, it is quite troublesome for many people to access these services to enter hard-to-remember IP addresses. Now we can give these servers an easy-to-remember name, and then create an IP ing in hosts. In this way, we can enter the name of this server for future access.

3. Website Blocking

Many websites install various plug-ins on your computer without your consent. Some may be Trojans or viruses. For these websites, we can use hosts to map the Domain Name of the website to the wrong IP address or the IP address of our computer. In this way, the website cannot be accessed. We will write the following content in hosts:

Domain Name of the website blocked by 127.0.0.1

Domain Name of the website blocked by 0.0.0.0

In this way, the computer resolves the domain name to the local machine or the wrong IP address, to achieve the purpose of blocking.

4. Smooth system connection

For Lotus servers and some database servers, if you enter an IP address directly during access, it cannot be accessed. You can only enter the server name to access the server. Then we configure the hosts file and enter the server name to connect smoothly.

Finally, it should be pointed out that the hosting configured in the hosts file is static. If the computer on the network changes, update the IP address in time; otherwise, the IP address cannot be accessed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.