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

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

Updated 7 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.

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.test
How many times will you retype this command this month?Automate it with ToggleHosts

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.

Characters you cannot see

A line that looks right can still contain a character the resolver does not accept. This happens most when you paste from a web page, a chat or a document:

  • a non-breaking space instead of a normal space or a tab
  • a typographic quote or dash
  • a byte order mark at the start of the file
  • Windows line endings (CRLF) in a file edited on macOS or Linux

Retype the line by hand rather than pasting it. To reveal hidden characters, show them:

cat -A /etc/hosts

A ^M at the end of a line is a carriage return left by Windows line endings, and $ marks each line end. Any M- sequence is a non-ASCII byte that should not be there.

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.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.

Other layers that bypass the hosts file

Sometimes the entry is perfect and the traffic never reads it:

  • A proxy. With an HTTP or HTTPS proxy configured, the proxy resolves the name, not your machine, so your hosts entry is never consulted. Exclude the domain from the proxy, or turn the proxy off to test.
  • Secure DNS in the browser. Chrome, Edge and Firefox can resolve names through their own DNS-over-HTTPS setting. If a name works in the terminal and in one browser but not another, check that browser's secure DNS option and test with it off.
  • A VPN or a local DNS filter. Some clients take over DNS entirely. Disconnect it, flush DNS, and test again.
  • Another machine. A container, a virtual machine and WSL each keep their own hosts file. Editing the host's file does not change what runs inside them.
  • Long-running programs. A server, a JVM application or a Node.js process may keep addresses it already resolved. Restart the program after changing the file.

The entry works but the page still looks wrong

If the verification commands return your IP, the hosts file is doing its job. What you see next is a different problem:

  • The server answers with the wrong site. Apache and Nginx pick a site from the requested hostname. Without a virtual host or server_name for myapp.test, you get the default site. Add one and reload the server.
  • A certificate warning on HTTPS. The certificate must cover the name you typed. For local work, see local HTTPS with mkcert. A real domain redirected to your machine cannot present a valid certificate, and sites that force HTTPS (HSTS) refuse to continue past the warning.
  • The port is missing. The hosts file maps a name to an address only. If your app runs on port 3000, open http://myapp.test:3000.
  • Two lines for the same name. The first matching line normally wins. Keep one line per hostname.

Verify on the command line

Check with a tool that goes through the same lookup your applications use:

dscacheutil -q host -a name myapp.test
# Windows (PowerShell)
[System.Net.Dns]::GetHostAddresses("myapp.test")
ping -n 1 myapp.test

Do not use nslookup or dig for this. They query DNS servers directly and never read the hosts file, so they report the public answer even when your entry is correct.

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.

Still stuck after the checklist? Reset the file to its default content and add your entries back one at a time. If the browser reports a redirect loop instead, see ERR_TOO_MANY_REDIRECTS and the hosts file.

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. Compare the options in the best hosts file editors for Windows, Mac and Linux. 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

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.

Related Articles

© 2026 ToggleHosts · All rights reserved[email protected]