/etc/hosts file, creating a frustrating disconnect between system-level DNS overrides and browser behavior. This issue typically stems from Firefox’s strict adherence to its own internal network settings or cached data rather than a fundamental refusal to read the system host file. The most common culprit is the "DNS over HTTPS" (DoH) feature, which can bypass local DNS resolution if not configured correctly, or stale cache entries that prevent the browser from recognizing new host mappings.
When you modify /etc/hosts to redirect a domain to 127.0.0.1 or another local address, standard browsers like Chrome usually respect this immediately because they rely on the operating system’s resolver. However, Firefox has historically treated DoH as a separate resolution path. If DoH is enabled, Firefox sends queries directly to the provider’s servers, ignoring the local /etc/hosts file entirely. Additionally, even with DoH disabled, Firefox maintains an internal DNS cache that might persist old records, causing it to ignore updates to the hosts file until the cache is cleared or the application is restarted. Understanding these mechanisms allows users to restore expected functionality without compromising their security setup.
Understanding the Root Cause
To fix this issue, it is crucial to understand why Firefox behaves differently from other Chromium-based browsers. On macOS, the system DNS resolver reads /etc/hosts first before querying external servers. Most applications use this system resolver. Firefox, however, introduced DNS over HTTPS (DoH) to encrypt DNS queries. When DoH is active, Firefox attempts to resolve domains via encrypted channels provided by Mozilla or third-party providers. This process effectively bypasses the local system resolver, meaning any entries in /etc/hosts are invisible to the browser.
Another factor is Firefox’s internal caching. Browsers cache DNS responses to improve performance. If you recently added an entry to /etc/hosts but have already visited the site, Firefox might still hold the previous IP address in its memory. This leads to a situation where the browser loads the old content or fails to connect, even though the system itself correctly resolves the domain to the local address. Clearing this cache or restarting the browser often resolves simple instances of this problem.
Disabling DNS over HTTPS
The primary solution for ensuring Firefox respects your /etc/hosts file is to disable DNS over HTTPS. This forces Firefox to fall back to the standard system DNS resolver, which includes the hosts file. You can adjust this setting through the following steps:
- Open Firefox and click the menu button (three horizontal lines) in the top right corner.
- Select Settings from the dropdown menu.
- In the left sidebar, click on Privacy & Security.
- Scroll down to the bottom of the page under the Enhanced Tracking Protection section.
- Locate the Enable DNS over HTTPS option.
- Click the dropdown menu next to it and select Off.
Once set to Off, Firefox will no longer attempt encrypted DNS resolution. It will defer to the macOS system resolver, which will correctly apply any rules defined in /etc/hosts. Note that disabling DoH reduces privacy slightly by exposing your DNS queries to your ISP or network administrator, but it restores compatibility with local development environments and ad-blocking hosts files.
Clearing Cache and Restarting
If you have already disabled DoH and the issue persists, the problem likely lies within Firefox’s cached data. Browsers store DNS lookups to speed up subsequent visits. If you modified /etc/hosts after visiting a site, Firefox might still be using the old cached IP address. To force Firefox to re-read the system hosts file, you must clear these caches.
- Clear Site Data: Go to Settings > Privacy & Security > Cookies and Site Data > Manage Data. Search for the affected domain and remove it. This clears all stored data for that specific site.
- Hard Refresh: While viewing the blocked page, press
Cmd + Shift + Ron macOS. This forces the browser to reload the page from the server, bypassing the local cache. - Restart Firefox: Completely quit the application using
Cmd + Qand reopen it. This ensures that any lingering DNS cache entries in memory are flushed.
These steps ensure that Firefox does not serve stale data. In some cases, users find that they need to do both: disable DoH and clear the cache. This combination addresses both the resolution path and the storage of previous results.
Verifying System Hosts Configuration
Before assuming the fault lies with Firefox, verify that your /etc/hosts file is syntactically correct and accessible. macOS requires root privileges to edit this file. Use the Terminal to check the file’s contents by running cat /etc/hosts. Ensure there are no typos in the IP addresses or domain names. For example, a valid entry looks like 127.0.0.1 localhost or 127.0.0.1 example.com.
You can also test the system resolver independently of the browser. Open Terminal and run nslookup example.com. If this command returns the local IP address you specified in /etc/hosts, then the system configuration is correct. If it returns a public IP, there is an issue with your hosts file or network permissions, not Firefox. Correcting the hosts file syntax will resolve the issue across all applications, including Firefox.
Related Troubleshooting Steps
Occasionally, extensions or security software can interfere with Firefox’s network stack. If the above steps fail, consider temporarily disabling privacy-focused extensions that might manipulate network requests. Some ad-blockers or tracking protection scripts can conflict with local host redirections. Additionally, ensure that your macOS firewall or antivirus software is not blocking Firefox’s access to loopback addresses. If you frequently switch between local development and production, consider using a dedicated profile in Firefox to isolate these settings, preventing global changes from affecting your daily browsing experience.
Frequently Asked Questions
Does disabling DoH affect my internet speed?
No, disabling DNS over HTTPS generally does not impact internet speed. In fact, it may slightly improve latency for local sites because the query goes directly to the local resolver instead of traveling to a remote DoH server. The encryption overhead of DoH is minimal, so the difference in general web browsing speed is negligible.
Why does Chrome work but Firefox doesn't?
Chrome uses the system DNS resolver by default, which always checks /etc/hosts. Firefox, by contrast, offers DNS over HTTPS as a default or optional feature. When DoH is enabled, Firefox bypasses the system resolver entirely. Disabling DoH aligns Firefox’s behavior with Chrome’s, making it respect the hosts file.
Can I keep DoH enabled and still use /etc/hosts?
No, not reliably. If DoH is enabled, Firefox sends DNS queries to Mozilla or third-party servers, which do not know about your local /etc/hosts modifications. There is no built-in exception in Firefox to route specific domains through the system resolver while keeping DoH active for others. You must turn DoH off completely.
How do I revert to the default DoH settings?
To re-enable DoH, go to Settings > Privacy & Security > Enable DNS over HTTPS and select Default or Max Protection. This will restore encrypted DNS resolution, but remember that it will once again ignore any entries in your /etc/hosts file.
Is editing /etc/hosts safe on macOS?
Yes, editing /etc/hosts is a standard and safe practice for developers and power users. It simply maps domain names to IP addresses locally on your machine. However, you must use sudo to save changes, and you should avoid deleting existing critical entries to prevent breaking system services. Always backup the file before making edits.