mercoledì 14 dicembre 2011

Port forwarding

For configuring port forwarding on any VirtualBox VirtualMachine, entering the following three commands for each and every rule you wish to setup will get you the results you're looking for. Be sure to remove the underscored words (and their underscores) and replace them with the settings for your individual VM.

From Host Machine:

VBoxManage.exe setextradata "<VMNAME>" "VBoxInternal/Devices/<CARDNAME>/0/LUN#0/Config/<RULENAME>/Protocol" <protocol>

VBoxManage.exe setextradata "<VMNAME>" "VBoxInternal/Devices/<CARDNAME>/0/LUN#0/Config/<RULENAME>/HostPort" <port_num>

VBoxManage.exe setextradata "<VMNAME>" "VBoxInternal/Devices/<CARDNAME>/0/LUN#0/Config/<RULENAME>/GuestPort" <port_num>


LEGEND:

<VMNAME>    = name of VM from VirtualBox main window

<CARDNAME>  = name of virtual network adapter - pcnet for PCnet-FAST III, e1000 for Intel PRO/1000 MT Desktop, and so on

<RULENAME>  = name you want want the rule to be stored as

<PROTOCOL>  = TCP, or UDP - if you want to do both, you have to have a **second** set of rules with a **different** rulename (eg. SSH1 for TCP and SSH2 for UDP)

<GUESTPORT> = the destination port - for example, this could be "80" for a webserver

<HOSTPORT> = the external port - for example, this could be "8080" for a webserver if your ISP does not allow personal web servers on port 80

If you want to verify your settings:

VBoxManage.exe getextradata "<VMNAME>" enumerate



Port forwarding SSH – Example

VBoxManage.exe setextradata "<VMNAME>" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP

VBoxManage.exe setextradata "<VMNAME>" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222

VBoxManage.exe setextradata "<VMNAME>" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22

Adesso per collegarci alla macchina virtuale che ospita il server SSH dobbiamo contattare la porta 2222 in ascolto sul computer host:

ssh localhost 2222


Per cancellare le regole appena create: 


VBoxManage.exe setextradata "<VMNAME>" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol"

VBoxManage.exe setextradata "<VMNAME>" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 

VBoxManage.exe setextradata "<VMNAME>" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort"

Nessun commento:

Posta un commento