How to Restore the Hosts File in Windows 10 and Windows 11

The hosts file in Windows is used to map IP addresses to domain names. If this file is missing, you may encounter issues accessing certain websites or local resources. This guide will explain how to restore the hosts file in Windows 10 and Windows 11.

1. What is the Hosts File and Why is it Important?

The hosts file is a simple text file that allows users to manually configure IP address mappings for specific domain names. It can be used, for example, to redirect a specific domain to a local server or block access to certain websites. If the hosts file is deleted or corrupted, it can lead to network access issues.

2. Where is the Hosts File Located in Windows?

In Windows, the hosts file is typically located at:

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

If you find that this file is missing, you can recreate it by following the steps below.

3. Manually Restoring the Hosts File

You can create a new hosts file using a basic text editor like Notepad. To do this:

  1. Open Notepad with administrator privileges. Search for "Notepad" in the Start menu, right-click it, and select Run as administrator.
  2. Copy and paste the following basic template into Notepad:
# Copyright (c) 1993-2009 Microsoft Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

127.0.0.1       localhost
::1             localhost
  1. Save the file as hosts (without an extension) and place it in the C:\Windows\System32\drivers\etc folder.

4. Restoring the Hosts File Using Command Prompt

An alternative way to restore the hosts file is by using the Command Prompt:

  1. Open Command Prompt as an administrator. Press Win + X and select Windows PowerShell (Admin) or Command Prompt (Admin).
  2. Type the following command to create a new hosts file with basic settings:
echo 127.0.0.1 localhost > C:\Windows\System32\drivers\etc\hosts

This command creates a hosts file with a basic entry for localhost.

5. Testing the Hosts File

After restoring the hosts file, it's a good idea to test it. Open the Command Prompt and enter:

ping localhost

If the file is functioning correctly, you should see a successful response from the IP address 127.0.0.1.