sodcalculator

10 Tech How-To

Fix Firefox Can’t Access Localhost (Chrome & Edge Work)

Guide 10-22414 · Updated · Step by step

If Firefox cannot access localhost but Chrome and Edge can, the cause is almost always Firefox’s built-in DNS-over-HTTPS (DoH) or Enhanced Tracking Protection blocking the loopback address. The fix is to disable DoH for localhost or add an exception, which takes about 30 seconds and does not affect your other browsers.

Why Firefox Treats Localhost Differently

Firefox has shipped with DNS-over-HTTPS (DoH) enabled by default for users in the US since 2020, and later rolled out to other regions. DoH sends your DNS queries to a secure resolver (like Cloudflare or NextDNS) over an encrypted HTTPS connection, which protects against eavesdropping and DNS spoofing. However, this also means that Firefox may resolve localhost or 127.0.0.1 via the remote resolver instead of the local hosts file or system resolver. In some configurations, the remote resolver does not return the expected loopback address, or Firefox’s security policies block the connection because the certificate doesn’t match the loopback IP. Chrome and Edge use the system’s DNS settings by default, so they resolve localhost correctly.

Another common culprit is Firefox’s Enhanced Tracking Protection (ETP) in Strict mode. ETP can block certain requests to localhost if it considers them cross-site trackers, especially when you are testing a web app that uses cookies or localStorage. Since Chrome and Edge have different tracking protection defaults, they may not block the same requests.

How to Fix: Disable DoH for Localhost

  1. Open Firefox and type about:config in the address bar. Press Enter and click “Accept the Risk and Continue” if prompted.
  2. Search for network.trr.mode. The default value is usually 0 (system DNS) or 2 (DoH with fallback). If it is 2 or 3, change it to 0 to disable DoH entirely, or 5 to disable DoH only for localhost and other loopback addresses.
  3. If you prefer to keep DoH for most sites, set network.trr.mode to 5 and also set network.trr.excluded-domains to include localhost and 127.0.0.1 (comma-separated).
  4. Restart Firefox and try accessing http://localhost:3000 or whatever port your local server uses.

If you are using a custom local domain like myapp.test, add that domain to the exclusion list as well.

Check Your Hosts File and Proxy Settings

If disabling DoH doesn’t fix it, the problem may be in your system’s hosts file or Firefox’s proxy settings. First, verify that localhost resolves to 127.0.0.1 by opening a terminal and running ping localhost (Windows) or ping localhost (macOS/Linux). If it returns something other than 127.0.0.1, check your hosts file at C:\Windows\System32\drivers\etc\hosts (Windows) or /etc/hosts (macOS/Linux) and ensure there is a line 127.0.0.1 localhost.

Also, Firefox has its own proxy settings separate from the system. Go to Firefox Settings → General → Network Settings. If you have a proxy configured, try setting it to “No proxy” and see if localhost works. Some proxy extensions (like FoxyProxy) can interfere with localhost traffic.

Disable Enhanced Tracking Protection for Local Sites

If DoH is not the issue, try disabling Enhanced Tracking Protection for the localhost site. Click the shield icon in the address bar when you are on the localhost page, and toggle off “Enhanced Tracking Protection” for that site. If that fixes it, you can either leave it off for that site or switch ETP to Standard mode globally (Settings → Privacy & Security).

In Strict mode, Firefox may block cookies, localStorage, and even some requests to loopback addresses if they are considered cross-site. This is a common issue when developing with frameworks like React or Vue that use hot-reloading and WebSocket connections.

Other Common Causes and Quick Fixes

  • IPv6 vs IPv4: If your local server is listening only on IPv4 (127.0.0.1) and Firefox is trying IPv6 (::1), you may get a connection refused. Try accessing http://127.0.0.1:port instead of http://localhost:port.
  • Firewall or antivirus: Some security software blocks loopback connections for browsers. Temporarily disable your firewall or add an exception for Firefox.
  • Cache and cookies: Clear Firefox’s cache and cookies for localhost. Go to Settings → Privacy & Security → Cookies and Site Data → Manage Data, search for localhost, and remove it.
  • Browser extensions: Disable all extensions (especially privacy or VPN extensions) and try again. You can do this by going to about:addons and disabling them one by one.

Comparing Firefox, Chrome, and Edge DNS Behavior

Chrome and Edge use the operating system’s DNS resolver by default, unless you explicitly enable “Secure DNS” in their settings. Even when enabled, they typically still respect the hosts file and loopback addresses. Firefox, however, has its own DoH implementation that can bypass the hosts file in some cases, especially when the mode is set to 2 or 3. This is why you see the issue only in Firefox. If you want to keep DoH enabled in Firefox but avoid localhost problems, the exclusion list is the best solution.

Frequently Asked Questions

Why does localhost work in Chrome but not Firefox?

Because Chrome uses the system DNS and does not have DoH enabled by default, while Firefox may route localhost queries through a remote DoH resolver. Disabling DoH or adding localhost to the exclusion list fixes it.

What is the network.trr.mode setting?

It controls Firefox’s Trusted Recursive Resolver (DoH) behavior. Mode 0 disables DoH, 2 uses DoH with fallback, 3 uses DoH only, and 5 disables DoH for localhost and other excluded domains.

I changed the setting but still can’t access localhost. What else?

Try accessing http://127.0.0.1:port directly, disable Enhanced Tracking Protection for the site, check your hosts file, and disable proxy extensions. Also ensure your local server is actually running and listening on the correct port.

Will disabling DoH make me less secure?

DoH protects against DNS snooping and spoofing. If you disable it, your DNS queries are sent in plaintext to your ISP or configured resolver. For most users, this is a minor risk, but if you are on a public Wi-Fi, consider keeping DoH enabled and only excluding localhost.

Does this affect other browsers?

No, the fix is specific to Firefox. Chrome and Edge will continue to use their own DNS settings, so you can change Firefox without affecting them.

Can I use a custom local domain like myapp.test with Firefox?

Yes, add the domain to network.trr.excluded-domains in about:config. Also ensure your hosts file maps that domain to 127.0.0.1.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →