23

I'm using Firefox browser in Ubuntu 18.04. I made an experiment where I want some domain names to be resolved to another IP address than their actual one. Firefox seems to ignore the IP in the hosts file.

1) Is this expected behavior from Firefox?

2) If yes, how to make Firefox honor the hosts file?

3) If not possible, are there alternative browsers that honor the hosts file?

I use Linux Ubuntu 18.04

CaldeiraG
  • 2,536
  • 7
  • 18
  • 33
user9371654
  • 1,147
  • 3
  • 12
  • 21
  • I use the hosts file to direct well known adds sites to 127.0.0.1 as a cheap add-blocker and it works very well. So the answer is **no**, firefox (as all other browser I've tried) honors `/etc/hosts`. You should double check your hosts file content. – Zeitounator May 05 '19 at 19:53
  • 1
    Windows 10 itself will ignore *hosts*, e.g. when used to block telemetry. See https://www.petri.com/windows-10-ignoring-hosts-file-specific-name-resolution – DrMoishe Pippik May 05 '19 at 22:50
  • 1
    I don't know much about Linux but in Windows browsers don't consult the hosts file. That is done at a lower level in the system and the browser has no choice whether it is used or not. I suspect a problem in the hosts file. – LMiller7 May 06 '19 at 01:11
  • 3
    The browser (on PC operating systems) _always_ has a choice to not use the system-provided mechanisms in the first place. It can send its own UDP packets or make TCP connections. – u1686_grawity May 06 '19 at 13:49
  • ipv6 was the problem for me. Solution here: https://superuser.com/a/753863/77247 – Eddie Nov 19 '20 at 19:45

7 Answers7

15

I had the same problem. Write about:config in the address bar.

Search for dns and change network.dns.offline-local to false.

about:config settings page on firefox

suspectus
  • 4,735
  • 14
  • 25
  • 34
F.Rahamim
  • 312
  • 1
  • 9
  • 1
    After switching this, I just needed to close Firefox entirely and reopen and it started to honor the hosts file. Thanks. – Nick Woodhams Jul 24 '19 at 09:51
9

I fixed it by disabling the "DNS Over HTTPS" Firefox Network option.

Erpallo
  • 109
  • 1
  • 1
  • +1. By design, DNS Over HTTPS ignores hosts files. See https://bugzilla.mozilla.org/show_bug.cgi?id=1453207#c2 – Brian Apr 03 '20 at 19:08
  • 3
    Firefox still ignores the hosts file after following this and the other answers, even after restart. I noticed if I create a new Firefox profile, it works there. – Lubo Kanev Feb 13 '21 at 13:38
  • Firefox 83+ [honors /etc/hosts](https://stackoverflow.com/questions/58842319/firefox-not-honoring-hosts-file#comment125364198_58842320) with the default settings, but you do need to restart after making changes to the hosts file. – Nickolay Jan 30 '22 at 12:54
3

All of the high-scoring answers here are not fine-grained. You can bypass individual domains with Trusted Recursive Resolver exceptions using the network.trr.excluded-domains setting in about:config. Set its value to a comma-separated list of domains like 'localhost,local,foo.com'

tombh
  • 131
  • 3
2

If the domain that is not working either in Firefox or Chrome ends as following:

.dev
.localhost
.test
.example
.app

The problem is that, both browsers in certain distributions don't like domain ending like that, in my case changing the domains from *.localhost to *.local solved the issue.

As I mention in a comment in this post where I found the solution, only happens in certain distributions, e.g. I don't have this issue in my Ubuntu 20.04 installation, but I got the error in Xubuntu 20.04 (both browsers).

Mariano Ruiz
  • 121
  • 4
0

Funny when I checked I found I already had it set to false from my last visit to this thread, so that I could get a straight answer when there were issues with dns or I wanted entry's in the host file to be recognized.

But today I discovered one entry that others may or may not be able to recreate, that is ignored by Firefox regardless. www.siteplug.com I have the entry for the non www, the www, the ww4 as well as the *. (pointed at 127.0.0.1) and all browsers return a 404 except firefox, as it arrives at the site successfully, so firefox does in fact ignore the host file if FF chooses to.

I use the hosts file regularly for many things for many years as it is the best way to test new sites on servers at different ip's or even FQDN on servers on the lan.

Sad really, firefox became the browser they did listening to the users, but those days are long gone at mozilla. Would really like to see a solution but I may have to switch browsers in the end.

  • On what operating system did you run your tests? – RockPaperLz- Mask it or Casket Jan 03 '20 at 00:47
  • Windows 10 Firefox 71.0 As I stated I have used the hosts file for MANY years for many reasons such as test sites of live domains in a different ip, or servers on my lan etc. the recent few revisions of firefox made some sort of change the last year or so that just seems to drive me into brick walls ina number of places that may force me to change but I would rather conquer the underlying reasons and continue to use my preferred browser – Universal4 Jan 03 '20 at 01:02
0

Fixed it by selecting "Auto-detect proxy settings for this network" in the Network settings. Windows 10, Firefox Version 77.0.1 (64-bit)

Temega
  • 111
  • 4
-1

Windows does not ignore the host file and can be verified easily by a test. I do know that older versions of Firefox did not ignore the host file, but mine seems to ignore the host file even after setting the flag for network.dns.offline-localhost

I ended up here after a search because I did not understand why I saw this behavior and even after changing the above suggestion, my firefox 71.0 is still ignoring the host file.

I made a change in my host file Verified with a ping it answers the way I want Flushed the dns at the command line Closed and opened the browser a few times to be sure Internet explorer, Microsoft Edge and Opera all land on the page I want after the change, and Firefox continues to ignore the host file, so there is likely another flag that needs changed.