Page 1 of 1

VirtualBox Port Forwarding

Posted: 23. Oct 2009, 18:00
by d3v1ous
Hello i have ran virtualbox on my Debian Lenny NetInstall server. Guest OS is same Debian Lenny Netinstall, i have success setup port forwarding to guest box, my xml file look like this:

Code: Select all

      <ExtraDataItem name="VBoxInternal/Devices/pcnet/0/LUN#0/Config/SSH/Protocol" value="TCP"/>
      <ExtraDataItem name="VBoxInternal/Devices/pcnet/0/LUN#0/Config/SSH/GuestPort" value="22"/>
      <ExtraDataItem name="VBoxInternal/Devices/pcnet/0/LUN#0/Config/SSH/HostPort" value="10022"/>
so i can ssh to my virtualbox with external ip address and 10022 port of the realbox, but this only works when i'm not at home. If i try ssh to virtualbox when im in same LAN which is virtualbox i receive "Server Unexpectedly closed network Connection" this without loggin promt. (this with external ip of the realbox)

When i try to do same with internal ip address of the realbox and port 10022 i receive: Timed Out

Re: VirtualBox Port Forwarding

Posted: 23. Oct 2009, 19:48
by Sasquatch
The VM must run first, but I think you are already running it. Next, if you use the Host to connect to the machine, point the SSH client to localhost instead. There is no reason why it would block connections when you connect from a different machine on the network to the IP of the Host.

Re: VirtualBox Port Forwarding

Posted: 23. Oct 2009, 21:55
by d3v1ous
I'm using NAT, and the local ip of the virtual box is 192.168.0.2, when i try ssh to hit from real box (192.168.0.1) i get:

Code: Select all

root@debian:~# ssh 192.168.0.2 -p 10022
ssh: connect to host 192.168.0.2 port 10022: No route to host
root@debian:~#

Re: VirtualBox Port Forwarding

Posted: 23. Oct 2009, 23:46
by Sasquatch
What, you gave the VM a different IP than DHCP? Why did you do that? It should stay on DHCP, else forwarding won't work.

Re: VirtualBox Port Forwarding

Posted: 24. Oct 2009, 11:12
by d3v1ous
I received ip address from DHCP server from the real box, and i have setup fixed ip address on the virtual box to DHCP server config. Then DHCP server aways give fixed address: 192.168.0.2 to my virtual box.

I have internet connection but local lan not work on me.

Re: VirtualBox Port Forwarding

Posted: 24. Oct 2009, 12:03
by Sasquatch
Please note all the VM settings and the IP addresses of the whole network that you have.

Re: VirtualBox Port Forwarding

Posted: 26. Oct 2009, 10:45
by d3v1ous

Code: Select all

Name:            Debian Lenny
Guest OS:        Other/Unknown
UUID:            57717d0c-8b0f-4f01-82eb-2ad6bbf7d17a
Config file:     /root/.VirtualBox/Machines/Debian Lenny/Debian Lenny.xml
Memory size:     256MB
VRAM size:       8MB
Number of CPUs:  1
Boot menu mode:  message and menu
Boot Device (1): DVD
Boot Device (2): DVD
Boot Device (3): HardDisk
Boot Device (4): Not Assigned
ACPI:            on
IOAPIC:          off
PAE:             off
Time offset:     0 ms
Hardw. virt.ext: on
Nested Paging:   off
VT-x VPID:       off
State:           running (since 2009-10-23T20:20:38.604000000)
Monitor count:   1
3D Acceleration: off
Floppy:          empty
SATA:            disabled
IDE Controller:  PIIX4
Primary master:  /home/virtual-box/Debian-Lenny.vdi (UUID: 671d897e-f539-46eb-bdbc-0b0b30a9b8b6)
DVD:             empty
NIC 1:           MAC: 080027A22A7C, Attachment: NAT (192.168/16), Cable connected: on, Trace: off (file: none), Type: Am79C973, Reported speed: 0 Mbps
NIC 2:           disabled
NIC 3:           disabled
NIC 4:           disabled
NIC 5:           disabled
NIC 6:           disabled
NIC 7:           disabled
NIC 8:           disabled
UART 1:          disabled
UART 2:          disabled
Audio:           disabled
Clipboard Mode:  Bidirectional
Video mode:      720x400x0
VRDP:            disabled
USB:             disabled

USB Device Filters:

<none>

Available remote USB devices:

<none>

Currently Attached USB Devices:

<none>

Shared folders:  <none>

VRDP Connection:    not active
Clients so far:     0

Guest:

Statistics update:                   disabled

Code: Select all

eth1      Link encap:Ethernet  HWaddr 00:00:b5:c4:64:09
          inet addr:192.168.0.1  Bcast:192.168.0.255  Mask:255.255.255.0

Code: Select all

root@debian:~# cat /etc/dhcp3/dhcpd.conf
option domain-name "home.lan";
option domain-name-servers 192.168.0.1;
authoritative;

# subnet declaration
subnet 192.168.0.0 netmask 255.255.255.0 {
        # ?????? ?? DHCP ??????? ?????? ?? ? ??-????? ?? 50,
        # ??? ????? ?? ??????? 50-?? ??. ??-?? ????? ???? ??????
        # ????? ?? ?????????? ?? ?????? ???? STATIC IP.
        range 192.168.0.3 192.168.0.32;

        # Gateway, ????? ?? ??????? ?????????.
        option routers 192.168.0.1;

        # ?????, ????? ?? ??????? ?????????, ??? ? ????? ?? ? 255.255.255.0
        option subnet-mask 255.255.255.0;

        # Broadcast , ????? ?? ??????? ?????????.
        option broadcast-address 192.168.0.255;
        # default-lease-time 600;
        # max-lease-time 7200;
}
VirtualBox:

Code: Select all

root@nighthawk:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:a2:2a:7c
          inet addr:192.168.0.15  Bcast:192.168.255.255  Mask:255.255.0.0
          inet6 addr: fe80::a00:27ff:fea2:2a7c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1927 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1297 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:155443 (151.7 KiB)  TX bytes:171255 (167.2 KiB)
          Interrupt:11 Base address:0xd020

root@nighthawk:~# ping google.bg
PING google.bg (74.125.91.104) 56(84) bytes of data.
64 bytes from qy-in-f104.1e100.net (74.125.91.104): icmp_seq=1 ttl=63 time=502 ms
64 bytes from qy-in-f104.1e100.net (74.125.91.104): icmp_seq=2 ttl=63 time=503 ms
64 bytes from qy-in-f104.1e100.net (74.125.91.104): icmp_seq=3 ttl=63 time=504 ms
^C
--- google.bg ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 502.051/503.382/504.125/1.107 ms
root@nighthawk:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
0.0.0.0         192.168.0.2     0.0.0.0         UG    0      0        0 eth0
root@nighthawk:~# ping 192.168.0.1
PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
From 192.168.0.15 icmp_seq=2 Destination Host Unreachable
From 192.168.0.15 icmp_seq=3 Destination Host Unreachable
From 192.168.0.15 icmp_seq=4 Destination Host Unreachable
^C
--- 192.168.0.1 ping statistics ---
4 packets transmitted, 0 received, +3 errors, 100% packet loss, time 3000ms
, pipe 3
root@nighthawk:~#
IP 192.168.0.1 is the ip of the real box.

I see manual for this but i dont know how to setup it. I mean: http://www.virtualbox.org/wiki/Advanced ... king_Linux