The hosts file is a configuration file in the computer system, used to map domain names and IP addresses. By modifying the hosts file, we can implement some network-related functions, such as blocking websites, accelerating access, etc. This article will introduce how to modify the hosts file.
1. Find the hosts file
The hosts file is located in the system directory of the operating system. The specific path is as follows:
Windows system: C:WindowsSystem32driversetchosts
Mac system: / etc/hosts
Linux system:/etc/hosts
2. Back up the hosts file
Before modifying the hosts file, it is recommended to back up the original hosts file to prevent modifications. An error occurred and recovery was required. You can copy the hosts file to another directory, or rename it to "hosts.bak", etc.
3. Use a text editor to open the hosts file
After finding the hosts file, use a text editor to open the file. You can use Notepad, a text editor, or any other application that supports opening plain text files.
4. Add or modify the mapping between domain names and IP addresses
In the hosts file, one line represents the mapping relationship between a domain name and an IP address. The format of each line is: IP address space domain name.
If you want to add a new mapping relationship, just add a line at the end of the file and fill in the IP address and domain name according to the above format. For example:
127.0.0.1 www.example.com
If you want to modify the existing mapping relationship, find the corresponding line and modify the IP address.
5. Save the file modification
After completing the modification to the hosts file, save the file. Before saving, make sure the format of the file has not changed and is still in plain text format.
6. Refresh the DNS cache
After modifying the hosts file, you need to refresh the DNS cache to make the new mapping relationship effective. In Windows systems, you can press the Win R key to open the run window, enter the command "ipconfig /flushdns" and press Enter to execute. In Mac or Linux systems, you can use the command "sudo killall -HUP mDNSResponder" to refresh the DNS cache.
7. Verify the modification results
After modifying the hosts file, you can open the browser and enter the corresponding domain name to check whether it takes effect. If you can successfully access the website, it means the modification is successful; if you cannot access the website, it may be an error in the modification, please check again.
8. Notes
Summary: By modifying the hosts file, we can flexibly map domain names and IP addresses to achieve some specific network functions. However, it should be noted that you must be careful when modifying the hosts file to avoid affecting the normal operation of the computer system.
The above is the detailed content of How to edit hosts file. For more information, please follow other related articles on the PHP Chinese website!