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 and the other browser directing the requests to the server at

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

  • Most people in your situation run a couple of WinXP or Ubuntu virtual machines with different HOSTS configs.
    – digitxp
    Dec 13, 2010 at 23:14
  • @digitxp - Yes, I'd already thought of that but i really don't want the overhead of multiple VM's and several entire OS's just to browse a couple of sites. Obviously, if there is no other choice that's what i'll probably have to do.. Dec 13, 2010 at 23:18
  • If all else fails: Fiddler Web Debugger (Windows) or GlimmerBlocker and Charles Web Debugging Proxy (Mac) can rewrite the requests on the fly...
    – Arjan
    Dec 13, 2010 at 23:30
  • @Arjan - Proxies will work to some extent, but I would have to have a seperate proxy instance for each browser instance, or change proxy settings each time which is even more annoying that changing host files. Dec 13, 2010 at 23:45
  • 1
    Perhaps a Web Proxy like squid, would let you redirect in a way that does what you want done from DNS resolution? (of course a web proxy can be configured on a per browser basis)
    – barlop
    Dec 15, 2010 at 11:15

9 Answers 9


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 :

  • Sorry about the late reply harrymc. Its not clear if the program allows one to provide per-sandboxed system files like %SYSTEM32%/Drivers/etc/hosts on Windows and /etc/hosts on Linux. Could you confirm? I'd prefer the Linux version because I did a quick security evaluation of Sandboxie a couple of years ago on Windows (it failed, and the reports to the author went unanswered).
    – jww
    Mar 21, 2014 at 1:06
  • if Sandboxie supports per-sandboxed system files like %SYSTEM32%/Drivers/etc/hosts, then the points are yours. The OS was underspecified, and its not fair to you to withhold them if Windows/Sandboxie works.
    – jww
    Mar 21, 2014 at 1:14
  • AFAIK Sandboxie creates a completely parallel file-system and registry. For Linux a simple sandbox program is arkose or maybe sandfox but I have no experience with them.
    – harrymc
    Mar 21, 2014 at 6:19
  • Thanks harrymc. I'm having trouble awarding you the points. I see a box with +50, but I can't click on it. Plus, I thought it was worth 100. Any ideas (or do I need to wander over to Meta)?
    – jww
    Mar 21, 2014 at 17:42
  • See the Bounty FAQ : Of the bounty of 100, one half was awarded automatically after 7+1 days without designated answer, one half was lost.
    – harrymc
    Mar 21, 2014 at 19:47

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
# localhost1 localhost2 localhost3
#==== Project 2
# localhost1
# localhost2
# 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

mkdir -p "$th"
export HOME="$th"
firefox -no-remote

Firefox 2

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.


I know this isn't what you're asking for, but a temporary solution could be to write a batch script to swap the hosts files and then claunch the browser.

At least it would minimize the the work you're doing.

Or you could just name these server something entirely different in the hosts file so you never have to switch it to begin with.

  • I can't rename them because the web applications depend on the host name to render the right content. Also, the reason I wish to do this is that i can run multiple browsers at the same time and have one go to staging and another to dev. You can't do that by swapping hosts files. Dec 13, 2010 at 23:26
  • @MystereMan: If you are talking about META BASE, just do browser detection server-side. You shouldn't have your own host name in any other URL... Feb 4, 2011 at 14:10
  • @TomWij - No, i'm not talking about META BASE. I'm talking about host based virtual hosting, not IP based. The hostname field determines which site is accessed. Feb 4, 2011 at 15:46
  • @MystereMan: Then your first comment on this answer doesn't make any sense. As you are talking about "the web application rendering the right content", I don't see what virtual hosts have to do with that? Feb 4, 2011 at 15:51
  • @TomWij - We have a multi-tennant CMS system that hosts multiple sites on a single server, with a single IP. To view any given site, you Must use a hostname, otherwise you only access the default instance. I need to switch between production, staging, and development versions of this server, which means changing the mapping of domain names to their IP addresses on the fly. I can do this in the hosts file, but that changes things globally so i can't open simultaneous copies of staging and production in two different browser instances. Feb 4, 2011 at 16:20

Privoxy can be used for this purpose.

  • How, exactly, would Privoxy work for this purpose? It looks like just another local proxy server, none of which work because with most browsers you can't define a proxy per instance.. you can only define the global proxy for all instances Feb 4, 2011 at 5:48
  • @MystereMan: It would proxy your requests and thus manipulate the requests into other requests, it's fairly easy to do that. You are talking non-sense about the proxy servers: Mirosoft Internet Explorer (GUI), Mozilla Firefox (GUI), Google Chrome (CLI --proxy-server=), Apple Safari (GUI), Opera (GUI) and any other browser (GUI or CLI) allows you to set your own proxy server... Feb 4, 2011 at 14:05
  • @TomWij - No. IE, Chrome, and Safari all use the global proxy server setting in "Internet Settings". That means, if you change it in one web browser, it changes in all of them. Firefox has its own settings for this, but unfortunately I can't use Firefox because it doesn't work with the CMS we use (everything else does). Feb 4, 2011 at 15:44
  • @Mystere Man: Incorrect. Stop repeating your thoughts and instead see what configuration each individual browser gives you. If you aren't spending the effort to actually read documentation then you will never get to solve your problem as you are asking something too specific that doesn't apply to the rest of the people. As I said before but you didn't seem to have read: Any browser allows you to set the proxy server for that browser. Google Chrome provides the CLI parameter --proxy-server=. Feb 4, 2011 at 15:46
  • 1
    Hmm, I might be wrong about Safari as I didn't use that for quite some time. But I think I misunderstood you, why would you want to have a different proxy server in every single browser? I'm getting confused as why something like "x.com = production; stage.x.com = staging; dev.x.com = development" wouldn't just work for you given a single IP and host header redirection on the server... Feb 4, 2011 at 18:16

Don't know if this is convenient enough for you, but one possible solution would be to install IIS on the machine with the browsers and provide server side scripts (like ASP.net, PHP, Ruby...) that change the hosts file and then redirect to the actual page. In your browsers, you then create a bookmark to that script, for example http://localhost/config_ie.rb which changes the hosts file (requires correct permissions on that file, of course) and then do a 302-redirct to the real page.

  • 1
    The part that most people fail to understand about this is that in order to work effectively, you need to be able to run multiple browsers simultaneously, using different host/ip mappings. For example, I need to have both my production and test and debug instances open in different browser instances. Each one has to use the same hostname (because HTTP 1.1 hostname mapping maps the correct site based on the hostname). If you just change the host file, then every instance of the browsers now maps to the new server, not just the single instance of it. Mar 16, 2014 at 20:20
  • @Erik Funkenbusch: Thanks for clarification. Well, my remaining ideas: a) One concept would be using something like filesystem virtualisation, which is called "Data Redirection" in Windows and is normally used for UAC to support legacy applications that write data to sensitive paths. Maybe there is some option that allows you to use that for your own purposes. Then you could have a custom hosts file for every process. b) DNS interception locally: Request from "iexplore.exe" etc. could be manipulated according to some list you supply. -- Is there some idea that you like? Mar 17, 2014 at 7:17

If a full VM is too much, a container-based solution might do.

If we are talking about linux here, lxc might be a feasible solution.

Apart from that - even a full VM with a minimal X11-linux is not that big (max 2 GB disk) and does not consume that many resources (max. 512 MB RAM) with nowadays hardware...

A Lubuntu VM might do here.

  • I find the RAM and the processing are OK. The shared disk is what cripples the system.
    – jww
    Mar 21, 2014 at 1:13

Unfortunately the OP can't use Firefox. For those people who can, this is a partial solution:

On both Chrome and Firefox there is an extension call LiveHosts which lets you map a domain to an IP just in the browser. There are some limitation to this, it is not perfect, but it does allow you to test the webpage for example.com at IP xx.xx.xx.xx on Chrome, while in Firefox if you visit example.com you will end up at IP yy.yy.yy.yy

Here are the links:

Chrome LiveHosts

Firefox LiveHosts


One relatively simple solution (but maybe a bit resource heavy) would be to have a few virtual machines running in your host. Each virtual machine having it's own host file.

So you would have one virtual machine for the staging environment, one for prod, etc.

  • Perhaps you should read the first two comments under the question. This was addressed 4 years ago. Mar 18, 2014 at 8:07
  • Actually I did see the comment, but not until after I posted this answer. But I still thinks it makes sense to have it as a separate answer (as opposed to just a comment), as it can help other people with the same type of problem.
    – Pete
    Mar 18, 2014 at 9:27
  • Two VMs would cripple most workstations due to the shared disk bottleneck. I mildly suffer with one VM open (one is modern Mac Mac Book Pro with dual quad cores; the second is a modern ASUS laptop with a single quad core). Two VMs would be painful.
    – jww
    Mar 21, 2014 at 1:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.