30

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

user9371654
  • 1,297
  • 4
  • 16
  • 24

9 Answers9

20

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

Search for "dns" and change network.dns.offline-localhost to false.

about:config settings page on firefox

Matt
  • 432
F.Rahamim
  • 362
11

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

Erpallo
  • 129
4

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
  • 141
3

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

1

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
  • 121
1

I had the same problem under Windows, I tested all the solution above without success, and finally, by chance I saw that Docker add lines in the hosts with the .internal extension. Like this:

127.0.0.1 kubernetes.docker.internal

So I used the .internal extention for my local alias

127.0.0.1 app1.internal 

It works

0

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.

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.

0

ff -> about:config -> network.dns.localDomains - write local domain names comma separated