To map an IP address to a domain on Windows, open Notepad as administrator, open C:\Windows\System32\drivers\etc\hosts, add a line such as 203.0.113.10 example.com at the bottom, save it, and run ipconfig /flushdns. From then on your PC sends that domain to that IP address, whatever the public DNS says. It works the same on Windows 10 and Windows 11, and it only affects your computer.
We use this every week at dijitul. When we move a client’s website onto our hosting, we check it on the new server before touching the live DNS, and the hosts file is how we do it. This guide walks through it step by step, with a PowerShell shortcut, how to prove it is working, and what to check when it is not.

What the hosts file does
Before Windows asks a DNS server where a domain lives, it checks a small plain-text file on your own machine: the hosts file. Any domain listed there gets the IP address next to it, and DNS is never asked. If DNS is new to you, our plain-English DNS explainer covers the background.
Because the hosts file wins, you can point a domain at any server you like, for your PC only. Common reasons to do that:
- Previewing a website on new hosting before you change the DNS, so you can check every page, form and checkout while customers still see the old site.
- Testing a staging or development server under the real domain name, so cookies, redirects and absolute links behave as they will in production.
- Local development, giving a project on your own machine a friendly name such as
mysite.test. - Blocking a site by pointing it at
0.0.0.0, so it simply fails to load.
The examples below use addresses and domains reserved for documentation (203.0.113.x, 198.51.100.x, example.com). Swap in your own server IP and domain.
How to edit the hosts file in Windows 10 and 11
Step 1: Open Notepad as administrator
The hosts file is protected, so a normal Notepad window can open it but cannot save it. Press the Windows key, type Notepad, right-click it and choose Run as administrator. Click Yes when Windows asks for permission.
Step 2: Open the hosts file
In Notepad choose File → Open and paste this into the file name box, then press Enter:
C:\Windows\System32\drivers\etc\hosts
If you would rather browse to the folder, change the file type filter in the bottom right from Text Documents (*.txt) to All Files (*.*), otherwise the file stays hidden because it has no extension.
Step 3: Add your mapping
You will see some explanatory lines starting with #. Those are comments and are ignored. Go to the very bottom and add a new line with the IP address, at least one space or tab, then the domain:
203.0.113.10 example.com
203.0.113.10 www.example.com
Add both the plain and the www version. They are separate names as far as Windows is concerned, and forgetting one is the most common reason a preview “half works”. You can also put several names on one line after the IP address.
Step 4: Save the file
Press Ctrl + S. If Notepad offers a “Save as” dialog or complains about permissions, it is not running as administrator; go back to step 1. Make sure it saves as hosts and not hosts.txt.
Step 5: Flush the DNS cache
Windows remembers recent lookups for a while, so clear that memory. Open Command Prompt (or PowerShell) and run:
ipconfig /flushdns
You should see “Successfully flushed the DNS Resolver Cache.” Then close every browser window, not just the tab, and open it again.
Example hosts file entries
| Line in the hosts file | What it does |
|---|---|
203.0.113.10 example.com www.example.com | Sends both versions of the domain to a new web server, e.g. to preview a migration. |
198.51.100.24 staging.example.com | Points a single subdomain at a staging or test server. |
127.0.0.1 mysite.test | Gives a project running on your own PC a local name. |
0.0.0.0 ads.example.net | Blocks a domain: it resolves to nowhere and fails to load. |
# 203.0.113.10 example.com | Disabled. The # turns the line into a comment. |
The faster way: PowerShell
If you do this often, one command adds the line for you. Right-click the Start button, choose Terminal (Admin) or Windows PowerShell (Admin), and run:
Add-Content -Path "$env:windir\System32\drivers\etc\hosts" -Value "`r`n203.0.113.10 example.com www.example.com"
ipconfig /flushdns
The `r`n at the start adds a line break first, so your entry cannot get glued onto the end of the last line if the file did not finish with one. To see what is in the file now, run Get-Content $env:windir\System32\drivers\etc\hosts.
How to check it is working
Do not trust the browser first; ask Windows directly. In Command Prompt run:
ping example.com
The first line shows the IP address Windows resolved. If it says 203.0.113.10 (or whatever you set), the hosts file is working. It does not matter if the replies time out; plenty of servers ignore ping. What matters is the address in brackets.
Watch out for nslookup: it talks straight to a DNS server and skips the hosts file, so it will always show the public address and make you think your change failed. ping and PowerShell’s Resolve-DnsName example.com both respect the hosts file.
When previewing a migrated website, a quick visual check also helps: make a tiny, harmless change on the new server only (a test page, or a word in the footer) so you can be sure which copy you are looking at.
Hosts file not working? Check these
- Saved as hosts.txt. Open the folder in File Explorer with file extensions shown. There should be a file called
hostswith no extension. - A typo or a stray #. The line must start with the IP address, and nothing before it.
- Only one of www or non-www added. Add both, and any subdomains the site uses.
- Browser cache. Close every window and reopen. In Chrome or Edge you can also clear the browser’s own lookup cache at
chrome://net-internals/#dnsoredge://net-internals/#dns. - VPN, proxy or work network. Some VPNs and corporate proxies resolve names on their side, so your hosts file is never consulted. Disconnect and test again.
- Secure DNS in the browser. If one browser ignores the change but
pingshows the right IP, try turning off “Use secure DNS” in that browser’s privacy settings while you test, or use a different browser. - Security software. Microsoft Defender and some antivirus tools watch the hosts file and may revert or block certain changes, particularly for well-known domains. Check the protection history if your line keeps disappearing.
- Certificate warnings. If the new server has no SSL certificate for the domain yet, you will get a security warning. That is the server, not the hosts file; it usually means the certificate cannot be issued until the DNS really moves.
Remember to remove it
A hosts file entry never expires. Once a website has moved for real, delete the line (or put a # in front of it), save, and flush DNS again. We regularly meet people who left a preview entry in place and spent months looking at an old server while everyone else saw the new site. The same goes for blocking entries you no longer need.
Mac and Linux
Same idea, different location. On macOS and Linux the file is /etc/hosts. Edit it with sudo nano /etc/hosts, add the same kind of line, save, and on a Mac flush the cache with sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder.
Moving your website? We do this part for you
Every website we move onto dijitul hosting gets checked on the new server before the DNS changes, so there is no downtime and no surprises on launch day. If you would like to preview it yourself we send you the exact hosts file line to add. Managed hosting is £1 a day (£365 + VAT a year) with the migration included; see our web hosting or hosting support pages, get in touch, or call 01623 650333.
Frequently asked questions
Where is the hosts file in Windows 10 and Windows 11?
It is at C:\Windows\System32\drivers\etc\hosts on both Windows 10 and Windows 11. The file is called hosts with no extension, so it does not show up in Notepad’s Open dialog unless you change the file type filter to All Files.
Why can I not save changes to the hosts file?
Windows protects the file, so the editor has to be running as administrator. Close Notepad, search for it in the Start menu, right-click it, choose Run as administrator, then open the file again. If it still will not save, check whether your antivirus is locking it or the file has been set to read-only.
Do I need to restart my PC after editing the hosts file?
No. Run ipconfig /flushdns in a Command Prompt and fully close and reopen your browser. Windows reads the hosts file again straight away.
Does the hosts file change affect anyone else?
No. It only affects the computer you edit it on. Everyone else, including other devices on the same Wi-Fi, still uses normal DNS. That is exactly why it is useful for previewing a website on a new server before the switch-over.
Why is my browser ignoring the hosts file?
Usually because the browser has cached the old address, a VPN or proxy is doing the lookup somewhere else, or the line has a typo or a # at the start. Close every browser window, flush DNS, and test with ping in a Command Prompt to see what Windows itself is resolving.
How do I undo a hosts file change?
Open the file as administrator again and either delete the line or put a # at the start of it, then save and run ipconfig /flushdns. Always remove preview entries once a website has moved, or you will keep seeing the old server long after everyone else has moved on.
dijitul is a web design, hosting and SEO studio at The Bungalow, 11 St John St, Mansfield, working across the East Midlands since 2006. Photo by Oluwaseun Duncan via Pexels.

Leave a Reply