Opening and editing the hosts file in Windows

The hosts file is a small text file on your computer in which you decide which IP address a domain name points to. Windows checks this file first and only then asks DNS. That lets you test a new website before changing DNS, point a server name to a test environment, or block a website on one computer. This article explains where the hosts file is, how to edit it in Windows 11 and Windows 10 with Notepad, PowerShell or PowerToys, and what to do when your change does not work.

Where is the hosts file?

In Windows 11 and Windows 10 the hosts file is always here:

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

The file has no extension: it is called hosts, not hosts.txt. You can also write the path as %WINDIR%\System32\drivers\etc\hosts.

Method 1: Notepad as administrator

The hosts file lives in a system folder. Without administrator rights you can open it, but not save it.

  1. Click Start and type Notepad.
  2. Click Run as administrator and confirm with Yes.
  3. In Notepad choose File > Open and paste C:\Windows\System32\drivers\etc into the address bar.
  4. Set the file type at the bottom right to All files (*.*), otherwise the file is not shown.
  5. Open hosts, add your line at the bottom and choose File > Save (Ctrl + S).
Running Notepad as administrator in Windows
Opening the hosts file in C:\Windows\System32\drivers\etc

Method 2: PowerShell

Open PowerShell as administrator. This command opens the hosts file in Notepad with administrator rights:

Start-Process notepad "$env:windir\System32\drivers\etc\hosts" -Verb RunAs

Add a line without an editor (handy in scripts):

Add-Content -Path "$env:windir\System32\drivers\etc\hosts" -Value "`r`n10.0.0.25`tintranet.contoso.local"

Show the contents:

Get-Content "$env:windir\System32\drivers\etc\hosts"

On Windows 11 24H2 or later with sudo enabled, this works too: sudo notepad C:\Windows\System32\drivers\etc\hosts.

Method 3: PowerToys Hosts File Editor

Edit the hosts file often? Microsoft PowerToys includes a free Hosts File Editor with a clear list: add entries, switch them off temporarily, filter, and spot duplicates. Install PowerToys from the Microsoft Store or with winget install Microsoft.PowerToys, open PowerToys and launch Hosts File Editor as administrator.

How to write a hosts file entry

Each line contains an IP address, at least one space or tab, and one or more host names:

# This is a comment: Windows ignores everything after a #
127.0.0.1       localhost
10.0.0.25       intranet.contoso.local
203.0.113.10    www.yoursite.com yoursite.com
0.0.0.0         ads.example.com

Change not working? Clear the DNS cache

Windows and your browser remember DNS answers for a while. After a change:

  1. Open Command Prompt and type ipconfig /flushdns.
  2. Close the browser completely and open it again.
  3. Check with ping www.yoursite.com that the name resolves to the right IP address.

Note: nslookup queries the DNS server directly and ignores the hosts file. Use ping, or Resolve-DnsName www.yoursite.com in PowerShell, to test your change.

Common errors

Restoring the default hosts file

A default hosts file in Windows 10 and 11 only contains comment lines that explain the format. To start over, remove all your own lines (everything without a # in front), save and run ipconfig /flushdns. localhost works without a line in the hosts file.

Read also

Run Command Prompt as administrator in Windows 11 and 10: 6 ways
Turn Windows features on or off in Windows 11 and 10: 4 ways
Find and delete large files in Windows 11 and 10: 5 ways

Nederlandstalige versie: Het hosts-bestand aanpassen in Windows 11 en Windows 10


More in English