Monthly Archives: June 2016

Enable Port Forwarding in Windows 7

When working from home, I need to access the company network using a VPN software which works on Windows only.  However, all my tools are in Linux, thus working in Windows (dual-boot) or in a Windows virtual machine is very tedious and inefficient.

The solution is to create a Windows virtual machine.  Use it to run the VPN software.  Then, my linux OS will connect to the virtual machine and go into the office network via the VPN connection created by the virtual machine.  This is how to do it:

  1. Create a virtual machine with Windows 7 (I’m using Virtual-box).
  2. Create two network adapters for the virtual machine.  The first one uses NAT.  The second one uses Host-only Adapter.  To configure a Host-only Adapter, you will have to create a Host-only Network in the virtual-box (File > Preferences > Network > Host-only Network).
  3. Start up Windows 7 virtual machine.  Make sure VPN is working fine (can connect to the office network from within the Windows 7 virtual machine).
  4. Make sure the second adapter can be reached from the host Linux OS.  You can simply ping the IP address of the second adapter from the host Linux OS.  You will have to disabled the firewall in the Windows 7 virtual machine.

Now is the port forwarding.  Click the Windows start button and type cmd.  Right-click on the search result and choose Run as administrator.  In the command prompt, type the following command:

netsh interface portproxy add v4tov4 listenaddress=x.x.x.x listenport=xx connectaddress=x.x.x.x connectport=xx

My Windows 7 virtual machine has its 2nd network adapter configured with the IP address  I would like to connect to my office server with IP address  The office server is listening at port 22 (SSH).  My final command becomes:
netsh interface portproxy add v4tov4 listenaddress= listenport=22 connectaddress= connectport=22

The listenport=22 can be set to any other number as long as you specify it when connecting from your Linux OS to the Windows virtual machine like the following:

ssh -oPort=<listenport> user@

The effect is like running the following command

ssh -oPort=<connectport> user@

from the Windows 7 virtual machine.

To show all port forwarding configurations:

netsh interface portproxy show all

To clear all port forwarding settings:

netsh interface portproxy reset

If the forwarding does not work, you may want to clear all settings and re-add them.

More info here: