Home  >  Article  >  Computer Tutorials  >  How to restore the deleted hosts file

How to restore the deleted hosts file

WBOY
WBOYOriginal
2024-02-22 22:48:031150browse

Title: How to restore the hosts file after deletion

Abstract: The hosts file is a very important file in the operating system and is used to map domain names to IP addresses. If you accidentally delete the hosts file, you may be unable to access certain websites or have other network problems. This article will introduce how to recover accidentally deleted hosts file in Windows and Mac operating systems.

Text:
1. Restoring the hosts file in the Windows operating system
The hosts file in the Windows operating system is located in the driversetc folder under the system folder. The specific path is C:WindowsSystem32driversetc. Follow the steps below to recover accidentally deleted hosts file.

1. Start Windows Explorer and navigate to the C:WindowsSystem32driversetc folder.
2. Right-click a blank area in the folder, select "New" > "Text Document", and name it hosts.
3. Double-click the newly created hosts file and select "Notepad" or other text editor to open it.
4. Paste the following content in the hosts file:

# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost

Note: The above content is the basic content in the default hosts file. If you have customized the hosts file before, you need to copy and paste the backup contents line by line into the newly created hosts file to ensure that the previously performed domain name mapping still takes effect.

5. Save and close the hosts file.
6. Restart the computer.

2. Restore hosts file in Mac operating system
The hosts file in Mac operating system is located in the /private/etc folder and can be restored according to the following steps.

1. Open the "Terminal" application. You can find it in the Applications folder, or search for and open it using Spotlight (press Command Space and then type Terminal).
2. Enter the following command in the terminal window and press Enter:

sudo nano /private/etc/hosts

3. Enter your administrator password and press Press the Enter key to confirm.
4. In the editor that opens, copy and paste the following content into the hosts file:



Host Database

# # localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.

## 127.0.0.1 localhost

Note: The above content is the basic content in the default hosts file. If you have customized the hosts file before, you need to copy and paste the backup content line by line into the hosts file to ensure that the previously performed domain name mapping still takes effect.


5. Press "Control X" to exit the editor, then press the "Y" key to save the changes, and finally press the Enter key to confirm the saved file name.

6. Restart your Mac computer.


Summary:

Whether it is a Windows or Mac operating system, after accidentally deleting the hosts file, you can restore it by creating a new file and pasting the default or backup content into it. However, in order to avoid problems caused by deleting or tampering with the hosts file, it is recommended to back up the hosts file before making any changes so that it can be restored if needed. In addition, if you are not familiar with the use and editing of hosts files, it is best to avoid changing the contents at will to avoid unnecessary trouble. ###

The above is the detailed content of How to restore the deleted hosts file. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn