Browser with its own hosts file?

I have a number of staging and test servers that I need to constantly modify my hosts file to access (they depend on the domain name, so I have to change the hosts file to get them to work).

I find this annoying. I'd like to setup a portable browser of some kind for each kind of site I want to work with. Is there any version of any graphical web browser (including browsers based on the rendering engines of other browsers) that will do this?

This way I can simply launch the instance that's already configured to work with staging if I want to test staging.

Any ideas?

EDIT: The important feature is the ability to run two browsers concurently, both browsing to some-address.com, but with one browser directing the reqests to the server at 1.2.3.4 and the other browser directing the requests to the server at 5.6.7.8.

EDIT: (3/16/14)

This question was asked several years ago, and I still don't know of a decent way to do this. Let me try to explain further, because people seem to misunderstand the problem. It's not something that can be easily fixed just by using a proxy server. I suppose it might be possible to write extensive rules in a proxy server to solve the problems, but that's a huge complex solution to what should be a simple problem.

So to clarify:

There are three web servers. Production, Test, and Development. Each runs a multi-tenant application that customizes itself based on the hostname used to access it. Conceptually, this is similar to a Content Management System or blog engine that allows multiple sites to be run off the same server instance. You just point the hostname to the server, and whichever hostname is used to access it via HTTP 1.1 hostname mapping, is the site it displays.

Any solution which simply rewrites the host file doesn't work because of the requirement to run multiple browser windows at the same time to the different sites, production, development, test, etc... So simply constantly altering the host file doesn't work because it affects all browser instances. If you change the mapping for one browser, then the other browsers are also now mapped to that server so any subsequent requests will go to the wrong server.

All i'm looking for is a way to force this browser instance to use this host file, and that browser instance to use that host file, such as through a command line parameter. I don't even care if I need to install multiple copies of the browser.

This may be doable with firefox portable, since I think it uses its own config files per installed copy, but the problem is that the third party software used to administer the sites does not work with firefox (the sites themselves do, but the admin tools do not, they work fine with chrome and IE and Opera, however.. and I have no access to the source for this to fix it).


Squid solved the problem for me. I think many proxy servers could do the same.

Specifically, I had to install Squid. Then change the squid.conf so that it accessed an alternate hosts file. This is the line you want to change:

#hosts_file /etc/hosts

In my case I used hosts_file /etc/hosts-squid. I created the /etc/hosts-squid file and changed the hosts-squid file so that it would give me access to the new IP addresses that I wanted for the given URL. That was all I needed to do to configure the Squid proxy server.

I then created a command to launch my browser with the proxy settings. I used:

chromium-browser --proxy-server=localhost:3128

Running that command effectively give me a running instance of chromium which can access the domains setup in the hosts-squid file that I created.

I was also able to setup more proxy servers using multiple instances of Squid to access a production, development and local website all on the same computer. Instructions on how to run multiple Squid instances is here. I also wrote a blog post explaining the problem and solution in a little bit more detail.


I believe that you are asking to setup a virtual environment for each browser that includes its own hosts file.

One solution might be to use Sandboxie to set up a separate sandbox, each containing its own hosts file. The browser need not be installed into the sandbox to use the hosts file, just started from inside that sandbox. Desktop shortcuts can be created for launching the browser from within the sandbox.

The disadvantage will be that the browsers are going to be isolated from the real file system for example when downloading files from the Internet, but Sandboxie includes mechanisms for copying such files outside of the sandbox.

Unfortunately, the feature of running programs in more than one sandbox at the same time is only available in the paid version of Sandboxie (15 euros plus tax for one year license for personal use at home). Feasibility testing can be done using the free version. (Edit: Sandboxie is now freeware.)

For Linux users, similar products are :

  • Sandfox
  • Arkose

You can automate the process of changing host file with firefox + HostAdmin

HostAdmin is a Firefox Addon , that helps you modify the Hosts file , switch domain-ip mapping. HostAdmin can understand your Hosts file via a enhanced Hosts file syntax. In additional, HostAdmin refresh your DNS cache automaticlly whenever you change your Hosts file, even manually.

Example config

#==== Project 1
# 127.0.0.1 localhost1
127.0.0.1 localhost2
127.0.0.1 localhost3
#====
#==== Project 2
# 127.0.0.1 localhost1
# 127.0.0.1 localhost2
# 127.0.0.1 localhost3  

More info at https://addons.mozilla.org/en-US/firefox/addon/hostadmin/

Multiple instance

To run two instance of firefox browser concurently and independently in linux create multiple launchers with following script. Also install the plugin in all firefox.

Firefox 1

#!/bin/bash
th="/home/$USER/tmp/p1"
mkdir -p "$th"
export HOME="$th"
firefox -no-remote

Firefox 2

#!/bin/bash
th="/home/$USER/tmp/p2"
mkdir -p "$th"
export HOME="$th"
firefox -no-remote  

You may use the profile option (firefox -P ) in a browser to use native profiles for different setting and may use concurrently.