ToggleHosts
/etc/hosts Not Working? Fixes for Windows, Mac & Linux

/etc/hosts Not Working? Fixes for Windows, Mac & Linux

4 min read

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.

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

TEXT
# 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.test

The 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:

TEXT
127.0.0.1 myapp.test
::1 myapp.test

Background: 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 .test instead.
  • Saved without sudo / wrong line endings: use sudo nano /etc/hosts and 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 (or sudo systemd-resolve --flush-caches).
  • nscd cache: sudo systemctl restart nscd if installed.
  • NSS order: check /etc/nsswitch.conf, the hosts: line should list files before dns (e.g. hosts: files dns), otherwise DNS can win.
  • Immutable flag: lsattr /etc/hosts; remove with sudo chattr -i /etc/hosts if set. Then flush DNS on Linux.

Verify on the command line

getent hosts myapp.test
ping myapp.test

If 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

Also readHow to edit the hosts file (all platforms)
Also readHow to flush the DNS cache (Windows, macOS and Linux)
Share this article

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