Wednesday, August 19, 2009

NAT mode and port forwarding

I am runnig Debian as guest in my VirtualBox in Windows and i want to ssh to Debian.

How ?

run debian in NAT mode and do port forwarding

go to C:\Program Files\Sun\xVM VirtualBox and run


VBoxManage setextradata "debian 5 Lenny" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol" TCP
VBoxManage setextradata "debian 5 Lenny" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort" 22
VBoxManage setextradata "debian 5 Lenny" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort" 22

restart your guest

run the below to see what u have done:
VBoxManage getextradata "debian 5 Lenny" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol"
VBoxManage getextradata "debian 5 Lenny" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort"
VBoxManage getextradata "debian 5 Lenny" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort"

The info is actually stored in C:\Users\who am i\.VirtualBox\Machines\debian 5 Lenny\debian 5 Lenny.xml

here is part of the xml file:



name="VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort" value="22"/>

name="VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort" value="22"/>




debian 5 Lenny is the name of your guest, it is case sensitive.


from the Help:

The above example assumes a PCNet virtual network card; if you have configured the guest to use the Intel PRO/1000, replace

"pcnet" with "e1000" in the above commands. Similarly, if you want to configure a different interface instance replace the /0/

with the appropriate index. pcnet and e1000 are counted separately in this respect, and counting starts at 0 for both types.

The name guestssh is an arbitrary one chosen for this particular forwarding configuration. With that configuration in place, all

TCP connections to port 2222 on the host will be forwarded to port 22 on the guest. Protocol can be either of TCP or UDP (these

are case insensitive). To remove a mapping again, use the same commands, but leaving out the values (in this case TCP, 22 and

2222).

It is not possible to configure incoming NAT connections while the VM is running. However you can change the settings for a VM

which is currently saved (or powered off at a snapshot).


remember u need to restart your guest...


from windows: ssh to 127.0.0.1:22

No comments: