0

Is there a tool, that allows an individual to temporarily switch between different etc/hosts configurations, without setting up a dns?

Example:

I would like to quickly change the etc/hosts config file, so that project1.com forwards to a local IP like 192.168.10.50 without changing information in our DNS server.

Why?

We are developing several bigger cms projects. The cms is developed inside a virtual machine. Sometimes we have to make bigger changes to a cms system that is already in production. A developer needs to access the productive version of the site and some minutes later he wants to redirect all requests to the local virtual machine.

A tool, that can easily swap between different etc/hosts configuration files would be ideal.

If possible don't want the users to manually edit the etc/hosts file.

JdeBP
  • 3,970
  • 17
  • 17
Richard
  • 201
  • 1
  • 4

2 Answers2

0

You could create batch file where user input then copies and replaces the hosts file.

Perhaps not ideal but a simple and quick solution.

Example in picture

Just create the hosts files and keep them somewhere on the machine, like C:\temp\hostfiles\

Then create a .bat file with content like:

[@echo off
:ask
@echo Select hosts file project
@echo 1 - Project 1
@echo 2 - Project 2
@echo 3 - Project 3
@echo 0 - Exit
set INPUT=
set /P INPUT=Type input: %=%
If /I "%INPUT%"=="1" goto 1 
If /I "%INPUT%"=="2" goto 2
If /I "%INPUT%"=="3" goto 3
If /I "%INPUT%"=="0" goto exit
goto ask
:1
COPY "C:\temp\hostfiles\project1" "C:\Windows\System32\drivers\etc\hosts" /y >nul
@echo Project 1 hosts file is now active
goto exit
:2
COPY "C:\temp\hostfiles\project2" "C:\Windows\System32\drivers\etc\hosts" /y >nul
@echo Project 2 hosts file is now active
goto exit
:3
COPY "C:\temp\hostfiles\project3" "C:\Windows\System32\drivers\etc\hosts" /y >nul
@echo Project 3 hosts file is now active
goto exit
:exit
@pause

Strongly recommend to backup the hosts file before testing this.

Uwe Keim
  • 2,370
  • 4
  • 29
  • 46
0

You could just write a batch job that could be run to swap the hosts file from one version to another when run.

Robert Swisher
  • 1,147
  • 7
  • 14
  • Wes, this wuld work. But I have multiple projects, so the batch file could not know which of the etc/hosts configurations it should take. – Richard May 25 '11 at 17:05
  • 1
    Make separate .bat-file for each project – gelraen May 25 '11 at 17:28
  • Or if you named the hosts file the same as the project name, you could use `%1` in the batch file, then set up multiple shortcuts to the same batch file, each with the target `sethost.bat project1`, `sethost.bat project2` and so on – DerfK May 25 '11 at 17:57
  • PowerShell maybe ... PowerShell Multiple Choice Menu – toofat May 15 '19 at 06:21