12

Firefox does not honor the hosts file when browsing to an URL. For example;

My hosts file says 127.0.0.1 local.webdev.com and entering the local.webdev.com URL into the address bar sends me to the internet always, not localhost. Browsing to this URL in another browser works fine.

Maarten
  • 402
  • 5
  • 20

6 Answers6

8

There is a new feature in Firefox called "DNS over HTTPS" which you may have (accidentally) enabled. Having this option enabled sends your DNS request directly to your DNS server instead of to your OS, which is the default.

Go to Settings -> General -> Network Settings -> Enable DNS over HTTPS and disable this option.

This makes sure that your DNS request goes to your OS which will read the hosts file first before going to your DNS

Maarten
  • 402
  • 5
  • 20
  • This worked for me. For what it’s worth I’m almost completely certain I didn’t enable this manually, and that it became the default behavior. I’m in Firefox 81.0.1. – kevincoleman Oct 12 '20 at 23:21
  • You can continue to use "DNS over HTTPS" and use the /etc/hosts by setting "network.trr.excluded-domains" or "network.trr.exclude-etc-hosts" to False. – ThankYee Sep 26 '21 at 06:47
  • Er, `network.trr.exclude-etc-hosts` ([added in Firefox 83](https://bugzilla.mozilla.org/show_bug.cgi?id=1616252)) must be set to **true** (the default) for the `/etc/hosts` file to be used. The only gotcha is that you have to restart or flip the pref (twice) after changing the hosts file. – Nickolay Jan 30 '22 at 12:53
3

The solution for me was to enter "about:config" in Firefox address bar, then add a boolean value named:

browser.fixup.dns_first_for_single_words

and then set it to true.

(currently working on Firefox 78.0.2)

Niente0
  • 504
  • 3
  • 11
  • on Firefox 81.0 'DNS over HTTPS' seems to be disabled by default (?) however setting single word to true made my troubles go away (... those troubles regarding the scope of this question at least) – nuala Oct 13 '20 at 12:24
0

I had this same problem.

Not sure if it's a complete solution, but I noted the following in my case:

  • When I gave the page a normal refresh (F5, Ctrl+R, Refresh Button) it wouldn't respect the 'hosts' DNS.
  • When I used clear cache / reload (Ctrl+Shift+R, Ctrl+F5, Shift+Refresh Button), it worked fine every time.
Codesmith
  • 5,779
  • 5
  • 38
  • 50
0

In my case the problem was from the proxy I had set in:

Settings -> General -> Network Settings -> Settings

enter image description here

enter image description here

Mir-Ismaili
  • 13,974
  • 8
  • 82
  • 100
0

For me the issue was the website was being served over ipv6, but I had only changed the ipv4 address in my hosts file. Once I added an ipv6 line to the hosts file it started working as expected. If you go to about:networking#dns you can see whether or not the website is ipv4 or ipv6 in the "Family" of the table.

user146515
  • 43
  • 4
0

The issue in my case was fixed simply by prepending the HTTP protocol to the URL, for example:

http://
+
thetoppers.htb
→
http://thetoppers.htb
Boris
  • 22,667
  • 16
  • 50
  • 71