You edited the hosts file. The line looks correct. The browser still opens the old site.
Do not rewrite the hosts file again yet. Walk the stack in order.
1. Confirm the file that actually loaded
macOS / Linux:
grep -n "example.com" /etc/hosts
Windows (Admin PowerShell):
Select-String -Path C:\Windows\System32\drivers\etc\hosts -Pattern "example.com"
Check for:
- a
#commenting the line out - a second line for the same hostname later in the file
- a typo in the hostname
If the terminal cannot see the line, the browser will not either.
2. Flush the OS DNS cache
macOS:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Windows (Admin):
ipconfig /flushdns
Linux with systemd-resolved:
sudo resolvectl flush-caches
3. Ask the OS, not the browser
# macOS / Linux
ping -c 1 example.com
getent hosts example.com
Windows:
ping example.com
nslookup example.com
If the terminal shows the wrong IP, stop. Fix hosts or flush again. Do not debug the app yet.
On some systems nslookup talks to a DNS server and can ignore hosts. Prefer ping / getent for hosts checks.
4. Clear browser DNS
Browsers cache names too.
- Quit the browser fully (not just the tab)
- Reopen and retry
- Chrome:
chrome://net-internals/#dns→ Clear host cache - Try a private window once, to rule out extensions
5. Watch for HTTPS and HSTS traps
Hosts can point www.client.com at staging, while the browser still forces HTTPS and an old certificate story.
Symptoms:
- certificate warnings
- redirects back to production
- cookies scoped to the real domain behaving oddly
For local-only work, prefer .test names. For cutover tests, expect TLS quirks and test with curl too:
curl -vI https://www.client.com
6. Docker and VPN layers
If the browser is on the host but the service is in Docker, your laptop hosts file may not be what the container uses.
If a VPN or corporate DNS is active, flush again after connect/disconnect. Some agents re-inject resolvers.
Short checklist
- Line present and uncommented in the real hosts file
- One active mapping per hostname
- OS DNS flushed
- Terminal resolves the expected IP
- Browser DNS cleared
- Only then debug the app, proxy, or TLS
Most "hosts is broken" reports die at step 3 or 4.
If you switch hosts a lot, a small desktop manager helps keep profiles and DNS flush in one place: Locahl.
Top comments (0)