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.
In Linux, modify the/etc/hosts file.
For Windows, the hosts file is stored in the following locations:
Windows 95/98/me? ? ? ? ??? C: \ windows \ hostswindows NT/2000/xp pro ?? C: \ winnt \ system32 \ drivers \ etc \ hostswindows 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:
127.0.0.1 ???? Blocked website Domain Name
0.0.0.0 ?????? Blocked website Domain Name
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.