/etc/hosts Not Working? Fixes for Windows, Mac & Linux
The hosts file is ignored or /etc/hosts changes do not take effect? Fix it on Windows, Mac and Linux: flush DNS, check syntax, IPv6, line endings, resolver caches and save permissions.
Locahl Team
Table of Contents
If the hosts file is "not working," the entry is almost always correct but something downstream ignores it β usually a stale DNS cache, a browser cache, a small syntax mistake, or another resolver overriding it. Work through the ordered checklist below; it applies to /etc/hosts on macOS and Linux and C:\Windows\System32\drivers\etc\hosts on Windows.
Quick checklist (most common first)
1. Flush the DNS cache. Edits do not apply until you flush β see how to flush the DNS cache on every OS. 2. Clear the browser DNS cache and open a fresh tab β chrome://net-internals/#dns. 3. Check the line syntax: IP<space-or-tab>hostname, no http://, no port, no trailing comment glued to the name. 4. Confirm it is not commented out (no leading #). 5. Add a trailing newline after the last entry and save again. 6. Confirm the file was saved with admin/root rights (no silent "access denied"). 7. Rule out another resolver (VPN, proxy, systemd-resolved, nscd) β details per OS below.
Syntax mistakes that silently break the file
# Wrong
http://127.0.0.1 myapp.test # no scheme allowed
127.0.0.1:3000 myapp.test # no port allowed
127.0.0.1 *.myapp.test # no wildcards (see dnsmasq)
# Right
127.0.0.1 myapp.test
127.0.0.1 myapp.test www.myapp.testThe hosts file matches exact hostnames only and ignores ports and schemes. For the full rules see the hosts file syntax guide. Wildcards need dnsmasq β see wildcard local domains with dnsmasq.
IPv6 vs IPv4
If a name resolves but the connection fails, the app may prefer IPv6. Map both:
127.0.0.1 myapp.test
::1 myapp.testBackground: 127.0.0.1 vs localhost. If localhost itself refuses to connect, see localhost refused to connect.
Windows: why hosts changes are ignored
- Not flushed / not elevated: save in an editor opened with Run as administrator, then
ipconfig /flushdns. - Antivirus "hosts protection": Norton, McAfee, Kaspersky and Controlled Folder Access can block or revert edits.
- Wrong file: confirm you edited
C:\Windows\System32\drivers\etc\hosts(no extension). See edit the hosts file on Windows.
macOS: why /etc/hosts is ignored
- System cache:
sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder. - .local names: these go through mDNS/Bonjour, not the hosts file β use
.testinstead. - Saved without sudo / wrong line endings: use
sudo nano /etc/hostsand keep Unix (LF) endings. Mac-specific deep dive: hosts file not working on Mac.
Linux: resolver caches and order
- systemd-resolved cache:
sudo resolvectl flush-caches(orsudo systemd-resolve --flush-caches). - nscd cache:
sudo systemctl restart nscdif installed. - NSS order: check
/etc/nsswitch.confβ thehosts:line should listfilesbeforedns(e.g.hosts: files dns), otherwise DNS can win. - Immutable flag:
lsattr /etc/hosts; remove withsudo chattr -i /etc/hostsif set. Then flush DNS on Linux.
Verify on the command line
# macOS / Linux
getent hosts myapp.test
ping myapp.test
# Windows
nslookup myapp.test
ping myapp.testIf these return the IP from your hosts file but the browser does not, the browser is the stale layer. If they return the wrong IP, the system layer (cache, syntax, resolver) is still the problem β not the browser.
Stop fighting the hosts file
Most "hosts file not working" cases are a forgotten flush or a malformed line. A hosts manager like Locahl validates each entry, keeps the file syntactically correct, and flushes DNS automatically after every change β so edits take effect the first time. To edit safely by hand, see how to edit the hosts file and how DNS resolution works.
_Last tested: June 2026 on Windows 11, macOS 26 Tahoe and Ubuntu 24.04._
Sources and further reading
- hosts(5) manual page (man7.org)
- How DNS works (Cloudflare Learning)
- The hosts file explained (Wikipedia)
Ready to simplify your workflow?
Stop wasting time with the terminal. Locahl lets you manage your hosts file in a few clicks, with automatic validation and no risk of errors.
- Intuitive visual interface
- Automatic DNS flush
- Multi-environment management
- Automatic backups
- JSON Import/Export
Reader Reviews
"My change was ignored because the line had no trailing newline. The syntax section caught it instantly."
June 21, 2026
"On Ubuntu it was systemd-resolved caching. The Linux resolver section was exactly what I needed."
June 20, 2026
"Solid cross-platform checklist. The CRLF line-ending tip saved me on a file copied from Windows."
June 19, 2026
Frequently Asked Questions
Why is my hosts file not working?
The most common reasons: the DNS cache was not flushed, the browser has its own cache, the line has a syntax error (wrong separator, no trailing newline, or http://), the entry is commented out, or another resolver (VPN, systemd-resolved, nscd) overrides it.
How do I make /etc/hosts take effect immediately?
Save the file with admin/root rights, then flush the DNS cache (ipconfig /flushdns on Windows, sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder on macOS, sudo resolvectl flush-caches on Linux) and clear the browser DNS cache.
Does the hosts file override DNS?
Usually yes β the hosts file is consulted before external DNS for most lookups. But a VPN, proxy, or a caching resolver can still intercept names, and the hosts file does not support wildcards.
Why does the hosts file work in terminal but not in the browser?
The browser keeps a separate DNS cache and may reuse a live connection. Clear it (chrome://net-internals/#dns) and open a fresh tab. If the terminal also fails, fix the system layer first.
Can wrong line endings break the hosts file?
Yes. On macOS/Linux, a file saved with Windows CRLF line endings (or missing a final newline) can cause the last entry to be ignored. Use a plain-text editor and ensure Unix (LF) endings.
Related Articles
How to Edit the Host File (Windows, Mac & Linux)
Edit the host file on Windows, macOS and Linux: file location, admin rights, syntax, DNS flush, and troubleshooting when changes do not apply.
Locahl Team
How to Flush DNS Cache (Windows, Mac, Linux & Chrome)
How to flush or clear the DNS cache on Windows, Mac, Linux and Chrome. Copy the exact command for your system, learn what flushing DNS does and whether it is safe.
Locahl Team
Developer tools team
How to Reset the Hosts File to Default (Windows, Mac, Linux)
Reset and restore the hosts file to its default contents on Windows, macOS and Linux. Copy the exact default file, back up first, then flush DNS so the reset takes effect.
Locahl Team
Developer tools team
Fix DNS_PROBE_FINISHED_NXDOMAIN (2026)
Fix DNS_PROBE_FINISHED_NXDOMAIN in Chrome and Edge: flush DNS, check the hosts file, reset DNS servers and clear the browser cache. Step-by-step solutions.
Locahl Team
Developer tools team
Clear DNS Cache in Microsoft Edge (2026)
Clear the DNS cache in Microsoft Edge with edge://net-internals/#dns, flush socket pools, and clear the Windows DNS cache so hosts changes take effect.
Locahl Team
Developer tools team