Author Topic: Internet connection for VirtualBox guest OS  (Read 2956 times)

Offline David_J_D

  • Jr. Member
  • **
  • Posts: 44
Internet connection for VirtualBox guest OS
« on: October 19, 2011, 01:00:42 PM »
I'll shortly be running a small virtual network as part of my degree course.  How do I give internet access to the virtual network in Virtual Box?

Offline pags

  • Hero Member
  • *****
  • Posts: 2515
  • Keep it clean.
Re: Internet connection for VirtualBox guest OS
« Reply #1 on: October 19, 2011, 02:08:56 PM »
I think you'll need one of your VMs to be dual-homed (setup with two virtual NICs).  One of them should be connected to the Internal (virtual) network.  the other should be either NAT or Bridged Adapter.  Then, that dual-homed node will need to be setup as a router.

Offline GermanTux

  • Hero Member
  • *****
  • Posts: 693
Re: Internet connection for VirtualBox guest OS
« Reply #2 on: October 20, 2011, 05:38:30 AM »
While Pags solution does work, it should be noted that Virtualbox, or even VMWare enterprise, really cannot do "virtual networks"  You can attach your VM's to internal only networks, but these cannot be routed at all. 

Offline menotu

  • PCLinuxOS Tester
  • Super Villain
  • *******
  • Posts: 15279
  • ┌∩┐(◕_◕)┌∩┐
Re: Internet connection for VirtualBox guest OS
« Reply #3 on: October 20, 2011, 05:52:57 AM »
The following gives some useful info on VBox networks etc.........

http://www.virtualbox.org/manual/ch06.html
PCLinuxOS 32bit KDE 4.10.1; kernel-3.4.11-pclos1.bfs & 64bit 3.2.18bfs; NVidia GeForce 8400GS 1GB 310.19 driver

Sony Vaio SVE1513A4ESI Laptop, Intel Core i5, 2.6GHz, 6GB RAM, 750GB, 15.6" Intel HD Graphics 4000

Offline kjpetrie

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 3979
Re: Internet connection for VirtualBox guest OS
« Reply #4 on: October 20, 2011, 07:24:30 AM »
If you mean allowing incoming connections to the VM, yes, it can be done. First you will need to set your router to forward the appropriate port to the host machine (logically it's first, but for security reasons you should do this second to protect your host). Secondly (but do it first) you need to set the VM to use bridged networking and configure its OS to use a static IP and then use IPtables to forward all incoming connections on the port to the guest and all related outgoing to the host's internet connection.

There are lots of options for bridged networking, ranging from a direct connection to the host's internet connection (I wouldn't recommend that, though I did once use it to flash my router firmware from a Windows VM!)) to downloading bridge-utils and tunctl and creating a completely self-contained virtual network inside the host's kernel tun/tap device, to which only the desired traffic can be forwarded, before being forwarded on to the host (this is what I use).

There really is no substitute for reading up on IPtables, networking, Virtualbox networking options and the kernel's tun/tap interface. Enjoy learning all about it!
-----------
KJP
-----------------------------------------------------------
PClos64 RC1 on Intel D945GCLF2 motherboard (Atom 330), 2GB DDR2 RAM, Maxtor STM325031, HL-DT-ST DVDRAM GSA-H42N, Amilo LSL 3220T monitor. Also Acer 5810TG (with custom kernel) and Asus eeePC 2G surf