Theme editor

Guide Windows Windows Hosts File: Route a Website to a Different IP (Safe Testing)

  • Thread starter Thread starter CL4Y
  • Start date Start date
  • Views 343

CL4Y

Keyboard Ninja
Administrator
Thread owner

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
jetto-windows-hosts-file-edit.webp


Step-by-step: Map a domain to a custom IP​

  1. Run Notepad++ as Administrator. Right-click Notepad++ → Run as administrator. This is required to save changes under System32.
  2. 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 (.).
  3. Add your overrides at the end of the file. Use one entry per line in the format: {IP_address} {domain}
jetto-windows-hosts-file-edit-2.gif


Code:
78.XXX.XXX.7 www.jetto.net
78.XXX.XXX.7 jetto.net
Replace 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.
jetto-windows-hosts-file-edit-3.gif

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/curl for verification on Windows.
jetto-windows-hosts-file-edit-4.gif

Real-world example (Jetto.net)​

To preview jetto.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
After flushing DNS and restarting the browser, your PC will load Jetto.net from 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. Try ping jetto.net and 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 -I to 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.
 
Thread owner
Editing the Windows hosts file is the fastest, safest way to preview a site on an alternate server without touching DNS. Add the IP-domain pairs, flush DNS, restart the browser, validate with ping/curl, then revert when finished. Simple, targeted, and production-safe. ✅
 
Back
Top