Teach you step by step to modify the Windows local hosts file and easily modify the domain name pointing!

Introduction:

During the front-end development process, we often need to modify local hostsfiles to modify domain name pointing to facilitate local debugging and development. This article will introduce in detail how to use Windowsthe system to modify hostsfiles and modify the domain name pointing .


1. What is the hosts file?

hostsThe file is a plain text file with no extension that can be used to map domain names to IP addresses . When we access a domain name in the browser, the operating system will first check the hosts file. If there is a corresponding mapping relationship, it will resolve the domain name to the corresponding IP address.

2. Preparation work

Before you start, you need to make sure the following steps have been completed:

  1. Administrator rights: In order to modify the hosts file, you need to have administrator rights. Please make sure that the user you are currently logged in has administrator rights.

  2. Editor selection: You can use the system's built-in Notepad to edit the hosts file, but for a convenient and comfortable editing experience, we recommend using some professional text editors, such as Notepad++, Sublime Text, etc.

2. Locate the hosts file

First, we need to find hoststhe location of the file. In Windowsthe system, the hosts file is located in the following path:

C:\Windows\System32\drivers\etc\hosts

You can enter the above path directly into Explorer's address bar, or manually navigate to the directory.
Insert image description here

3. Modify the hosts file

  1. Open text editor: Open a text editor of your choice with administrator rights.

  2. Import the hosts file: In the text editor, select "File" -> "Open" and navigate to the location of the hosts file found in the previous step.

  3. Edit the hosts file: In the last line of the hosts file, add the domain name and corresponding IP address you need. For example, if you want to www.example.compoint to local 127.0.0.1, you can add the following content to the hosts file:

    127.0.0.1       www.example.com
    

    Each mapping relationship should occupy one line, and the IP address and domain name should be separated by tabs or spaces.

  4. Save the file: After editing is completed, save the hosts file.

4. Refresh DNS cache

For the changes to take effect, the DNS cache needs to be flushed. You can do this by following these steps:

  1. Open Command Prompt: Search for "Command Prompt" in the Start menu and open it with administrator rights.

  2. Execute the command: Enter the following command in the command prompt and press the Enter key:

    ipconfig /flushdns
    

This will clear the local DNS cache and make the modified hosts file take effect.

5. Verify the modification results

Now that you have completed the modification to the hosts file, you can verify whether it has taken effect.

  1. Open a browser of your choice.

  2. Enter your modified domain name in the address bar, for example www.example.com.

  3. If all goes well, the domain name will be resolved to the IP address you specified in the hosts file.

in conclusion

By modifying the Windows local hosts file, we can easily modify the domain name pointing to facilitate our front-end development and debugging work. I hope this article can help you, and I wish you better results in the development process! If you have any questions or concerns, please leave a message to communicate. Thanks for reading!

References:

Guess you like

Origin blog.csdn.net/weixin_55846296/article/details/131451501