2

A common way to test an existing website on a new server before switching it to production by updating the DNS record is to change the hosts file on a development machine (/etc/hosts on *NIX systems, and %windir%\system32\drivers\etc\hosts on Windows), to have the OS resolve the hostname of the server to the new server. The developer can thus test the new server in real conditions before the actual deployment.

Now, changing the hosts file also has some downsides, among which:

  • the developer might forget to remove the change, with possibly undesired effects on the long term
  • the change requires administrative access on the machine

Hence the question: is there a way to do this change only within the browser (for Firefox, Chrome, and/or MSIE)? Looking for Firefox, I've found two or three add-ons, but they all do the same: modifying the OS-wide hosts file.

I'm looking for a self-contained lightweight solution working on both MS Windows and Linux, that does not require administrator privileges (so I can for example have students do that on their lab PCs), and without any external hardware/services (e.g. a router doing DNS spoofing or a proxy server doing the same).

Ale
  • 1,703
  • 17
  • 25

2 Answers2

2

I found a solution here that works for one IP on a per-Firefox-profile basis.

  1. Navigate to about:config.
  2. Set network.dns.forceResolve to e.g. 127.0.0.1

screenshot of network.dns.forceResolve parameter in about:config of Firefox

Stefan_EOX
  • 121
  • 3
2

In Chromium, you can use the --host-resolver-rules option to specify a list of mappings.

For example:

$ chromium \
  --user-data-dir=/tmp/some-temp-dir \
  --host-resolver-rules='MAP host1.example.com 127.0.0.1, MAP host2.example.com 127.0.0.1'
mmoya
  • 284
  • 2
  • 8
  • That's interesting! Although I'd prefer a solution within the browser... I think I'll write a WebExtension for this at some point, it doesn't seem very complicated. – Ale Jun 14 '19 at 09:00
  • Actually writing a WebExtension doing this is not 100% possible with the current APIs... I found this one (https://addons.mozilla.org/en-US/firefox/addon/livehosts/), but it uses some tricks that can break some sites (in particular CORS requests). Still using the `host-resolver-rules` at this day :) – Ale Jun 05 '20 at 13:43