HOWTO redirect TCP connections on Windows

Recently I needed to redirect TCP connections and data streams to another PC.

It is useful when you have PC1 and PC2 visible on the same LAN and can only see PC1 from outside.  In these cases, you have to use PC1 to reach PC2.

Open a Command Prompt with administrative access rights and type the following:

netsh interface portproxy add v4tov4 listenaddress=<local address/name> listenport=<localport> connectaddress=<target address/name> connectport=<target port>

 

To remove it, type:

netsh interface portproxy delete v4tov4 listenaddress=<local address/name> listenport=<localport>

Note that you shall change argument v4tov4 in these commands according to the address types you are using (ie v4tov6, v6tov4, v6tov6).

 

Since these settings are permanent (ie they will survive to system reboots), you can query the existing ones by typing the command below:

netsh interface portproxy show all