
/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.
Manage hosts files without the terminal
ToggleHosts helps you manage environments visually on Windows, macOS, and Linux, with automatic DNS flush and backups.
One-time payment
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)
- Flush the DNS cache. Edits do not apply until you flush, see how to flush the DNS cache on every OS.
- Clear the browser DNS cache and open a fresh tab,
chrome://net-internals/#dns. - Check the line syntax:
IP<space-or-tab>hostname, nohttp://, no port, no trailing comment glued to the name. - Confirm it is not commented out (no leading
#). - Add a trailing newline after the last entry and save again.
- Confirm the file was saved with admin/root rights (no silent "access denied").
- 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
getent hosts 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 ToggleHosts 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)
Frequently Asked Questions
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.
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.
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.
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.
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 Flush DNS Cache on Windows, macOS & Linux (2026)Flushing DNS & cache
How to Flush DNS Cache on Windows, macOS & Linux (2026)
8 min read
Fix EACCES: permission denied on /etc/hosts (2026)Troubleshooting
Fix EACCES: permission denied on /etc/hosts (2026)
3 min read
Fix getaddrinfo ENOTFOUND in Docker and Node.js with Hosts File (2026)Troubleshooting
Fix getaddrinfo ENOTFOUND in Docker and Node.js with Hosts File (2026)
3 min read