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 255.255.255.255.
Now you can configure the port proxy to forward ports.
Use netsh portproxy to forward ports to the new server (192.168.14.3). 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 192.168.14.3.
netsh interface portproxy add v4tov4 listenport=3306 connectport=3306 connectaddress=192.168.14.3 protocol=tcp netsh interface portproxy add v4tov4 listenport=9090 connectport=9090 connectaddress=192.168.14.3 protocol=tcp netsh interface portproxy add v4tov4 listenport=8983 connectport=8983 connectaddress=192.168.14.3 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 192.168.14.3 3306 * 9090 192.168.14.3 9090 * 8983 192.168.14.3 8983
And voila, all hardcoded connections will be forwarded to their new home.