Migrating Windows (legacy) environments

Ofcourse everybody knows that application configuration needs to be in the web.config, application.config, registry or whatever. But sometimes that is not the case and in hardcoded connection strings you have to choose between updating the codesource, recompile and deploy or updating the intermediate language. But there is also an other option, using the Loopback adapter and netsh.

Using this technique nothing will change for the application.

In this case we'll let the server listen on the destination ip address and forward ports to their new server. So how will we do that?

  • add loopback adapter and configure the ip addresses
  • use netsh to forward the ports to the new server

The loopback adapter can be added using Add legacy hardware in the device manager.

Select the Microsoft KM-Test Loopback adapter and add the device. Now you need to configure the ip addresses. All ip addresses of the services you need to forward shoud be added. Use subnet mask

Now you can configure the port proxy to forward ports.

Use netsh portproxy to forward ports to the new server ( You can use listenaddress (with the ip address of the old server) also, but remember that ipv6 needs to be configured also for v4tov4 to work.

The following sample will forward all ports to new server

netsh interface portproxy add v4tov4 listenport=3306 connectport=3306 connectaddress= protocol=tcp

netsh interface portproxy add v4tov4 listenport=9090 connectport=9090 connectaddress= protocol=tcp

netsh interface portproxy add v4tov4 listenport=8983 connectport=8983 connectaddress= protocol=tcp

Now you can use interface portproxy show all to show the current configuration:

netsh interface portproxy show all

Listen on ipv4:             Connect to ipv4:

Address         Port        Address         Port
--------------- ----------  --------------- ----------
*               3306   3306
*               9090   9090
*               8983   8983

And voila, all hardcoded connections will be forwarded to their new home.