If Firefox appears to be ignoring local hosts file entries, such as those used for development or to block intrusive (or addictive) services, there are several things to verify on macOS (but the true fix is described last).

Here is an example mapping:

# Hosts
127.0.0.1 dev.me
::1       dev.me

Use dscacheutil

Use dscacheutil to verify local settings:

$ dscacheutil -q host -a name dev.me
name: dev.me
ipv6_address: ::1

name: dev.me
ip_address: 127.0.0.1

This shows a correct mapping.

Flush DNS

sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder

This flushes the cache and forces a restart of the service.

At this point if the domain resolves correctly in Firefox, then the problem is solved, but the problem more than likely is:

Firefox settings (as of v79.0)

  1. Access Firefox Preferences from the Firefox menu, or shortcut cmd+,
  2. Search for ‘dns’, which should point to Network Settings
  3. Under ‘Connection Settings’ scroll to the bottom, searching for ‘Enable DNS over HTTPS’
  4. Uncheck this setting, and try again

This should correct the problem. Firefox is using DNS over HTTPS, so hosts isn’t followed.

Another solution

Another solution to avoid disabling DNS over HTTPS completely, is to use a config setting:

  1. Enter about:config in a Firefox tab to access config settings.
  2. Search for ‘network.trr.excluded-domains’
  3. A single domain or comma-delimited list of domains may be entered here, but not many
  4. Add the target domain here, for example ‘localhost’ or ‘dev.me’ in this case
  5. Close and reopen the browser for this change to take effect

(Also tested and confirmed working on Firefox v79.0, credit to this Reddit response for the last solution.)