Windows Hosts File: Route a Website to a Different IP (Safe Testing)
Need to preview a site on a new server before DNS goes live? The Windows hosts file lets you override DNS on a single machine and resolve a domain to any IP you choose. Below is a precise, reversible workflow using Notepad++ and admin privileges. 🧪Prerequisites
- Windows 10/11 with local administrator rights
- Notepad++ installed (recommended)
- Target server IPv4 (and optionally IPv6) address
Where is the hosts file?
The hosts file is here:
Code:
C:\Windows\System32\drivers\etc\hosts
Step-by-step: Map a domain to a custom IP
- Run Notepad++ as Administrator. Right-click Notepad++ → Run as administrator. This is required to save changes under
System32. - Open the hosts file. In Notepad++: File → Open → paste the path
C:\Windows\System32\drivers\etc\hosts. If you don’t see it, set file type to All types (.). - Add your overrides at the end of the file. Use one entry per line in the format:
{IP_address} {domain}
Code:
78.XXX.XXX.7 www.jetto.net
78.XXX.XXX.7 jetto.net
78.XXX.XXX.7 with your server’s IP. Tabs or single spaces both work; keep one delimiter.- Save without changing the filename or extension. Ensure it remains exactly
hosts(no.txt). - Flush the DNS cache. Open an elevated Command Prompt and run:
Bash:ipconfig /flushdns - Restart your browser. Browsers keep their own DNS/connection caches; a quick restart avoids stale routes.
Verify the override
- Ping or curl the domain (these honor hosts overrides):
Bash:ping jetto.net curl -I https://jetto.net - nslookup won’t reflect hosts entries. It queries DNS directly. Prefer
ping/curlfor verification on Windows.
Real-world example (Jetto.net)
To previewjetto.net on a staging server bound to 78.XXX.XXX.7 only on your device, add:
Code:
78.XXX.XXX.7 www.jetto.net
78.XXX.XXX.7 jetto.net
78.XXX.XXX.7 while everyone else continues using public DNS. 🎯Reverting the change
- Open the hosts file as admin again
- Delete or comment the lines (prefix with
#):
Code:#78.XXX.XXX.7 www.jetto.net #78.XXX.XXX.7 jetto.net - Save →
ipconfig /flushdns→ restart the browser
Troubleshooting
- “Access denied” when saving: Notepad++ wasn’t started as Administrator. Close and reopen with elevated rights.
- Changes have no effect: Run
ipconfig /flushdns, restart the browser, and ensure there’s no typo in the domain. Tryping jetto.netand confirm it resolves to your custom IP. - Still seeing old server: Clear browser cache or try a private window. Some CDNs/proxies cache aggressively; verify with
curl -Ito check response headers. - File not visible in “etc” folder: Switch the file dialog filter to All files (.).
FAQ
- Does this affect other users? No. The override is local to your device only.
- Can I keep this for staging permanently? Yes, but remember it bypasses live DNS; remove or comment lines when done.
- Will VPN or custom DNS resolvers interfere? Hosts has higher priority on the local machine; it still wins for name resolution on that device.