Sometimes it's not possible to use bridged adapters for you VM guests and you need to use NAT.
To access your VM guest from the VM host becomes difficult but not impossible with host-only networking.
As a developer I have a web, version control and database server running on my VM guest and don't want to use port forwarding, example:
VBoxManage setextradata MyLinux "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222
VBoxManage setextradata MyLinux "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
VBoxManage setextradata MyLinux "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP
See also this article: http://allisterx.blogspot.nl/2008/05/additions-and-ssh-access-to-virtualbox.html for more explanation how to port forward.
In my case the VM host is Windows 7 64 bit and the VM guest Ubuntu 11.10 (Oneiric Ocelot).
To have access to your VM guest from your VM host will using NAT you need to enable the host-only network:
This will create an virtual network adaptor in your VM host:
Ethernet adapter VirtualBox Host-Only Network:Connection-specific DNS Suffix . :Link-local IPv6 Address . . . . . : fe80::741c:9a5d:6840:6769%17Autoconfiguration IPv4 Address. . : 192.168.56.1Subnet Mask . . . . . . . . . . . : 255.255.0.0Default Gateway . . . . . . . . . :
The VM guest will automatically after starting will have the new adapter (eth1) configured:
eth0 Link encap:Ethernet HWaddr 08:00:27:68:75:9a inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe68:759a/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1360 errors:0 dropped:0 overruns:0 frame:0 TX packets:614 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1507853 (1.5 MB) TX bytes:79158 (79.1 KB)eth1 Link encap:Ethernet HWaddr 08:00:27:06:d1:4c inet addr:192.168.56.101 Bcast:192.168.56.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe06:d14c/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:492 errors:0 dropped:0 overruns:0 frame:0 TX packets:508 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:167816 (167.8 KB) TX bytes:115585 (115.5 KB)
You can now access the VM guest (in my case) through 192.168.56.255 from the VM host.
If you have multiple VM guests on NAT this also the solution to let them communicate with each other.
There is one big problem with host-only networking: it breaks after
updating to a new VirtualBox version (in my case upgrade to 4.1.14).
The IP address on the VM host will default to 169.254.*.* because the adapter did not get an IP address from the DHCP server.
Fortunately there is a fix:
More information about this problem:
Competition entry by David Cummins
powered by Serendipity v1.0