Search This Blog

Showing posts with label Open Source : Virtual Box. Show all posts
Showing posts with label Open Source : Virtual Box. Show all posts

Monday, August 23

Virtual Box Networking :Bridge between Windows7 with Ubuntu 10.04 : Good tutorial


VirtualBox 2.0 and onwards provides straightforward networking allowing IP address assignment and internet access using NAT, the default network option. Read below for more sophisticated setups.
Version 2.1 has reimplemented some of its networking. Bridging a virtual machine can now be done entirely from the graphical user interface.

NAT over PPPoE

Some ISPs check the value of the TTL field of the IP packets coming from your computer. TTL is a number associated with every IP packet that is decremented at every hop encountered on it's way. When the TTL gets to zero, the IP packet gets discarded.
TTLs start at various numbers (see http://members.cox.net/~ndav1/self_published/TTL_values.html) usually 128 or 64.
Using this information, some ISPs decided to limit the number of computers connected on a network by discarding packets with that originate from the host and have a TTL different from what they expect (64, 128, etc.) and to change the TTL of all packets destined to the host to 1. This way, if there's another computer X behind the one that is connected A, its TTL will be decremented by the A when sending it on the internet. The ISP will detect that an unexpected TTL was received (63, 127, etc.) and will drop the packet. Similarly, when the ISP must forward a packet to the host A, it sets the TTL to 1. This way if the packet was really destined to X, A will decrement the TTL, will see that it's zero and will drop it before sending it to the computer.
The same things apply when X is a virtual machine running on the host A.
To enable the internet connection on Virtualbox virtual machines in such conditions you need to alter the TTL:
  • increment the TTL of packets as soon as they come in on the interface ppp0 (the default internet connection, this may buteth0, eth1, wlan0, etc.)
sudo iptables -t mangle -A PREROUTING -i ppp0 -j TTL --ttl-inc 1
  • alter the packets as they are about to get out
sudo iptables -t mangle -A POSTROUTING -j TTL --ttl-set 64

Host Networking

Connecting a virtual machine through NAT will allow the guest to connect to systems on the network (including the host or some website). A machine on the network will not be able to initiate a connection to the guest though.
But typically, one might want to connect from the host to the guest (as is the case when the guest runs a web server or an ssh server). For this use case, bridging can be used (one must be aware that bridging will make a virtual machine visible to the network so it must be secured beforehand)

Host Networking with VirtualBox 2.1 and later versions

Open the settings of the virtual machine. Go to the network section. Pick "Bridge network" in the list of "Attach to" options. Choose the network interface you want to bridge with. Most of the time, this will be "eth0" for a wired network, only IPv4 is supported for wireless interfaces.

Host Networking in Ubuntu 10.04

You just need to load the "vboxnetflt" modules if it isn't loaded yet, and adjust the networking type in the VirtualBox Guest Network Settings to Attach to "Host Interface".
sudo modprobe vboxnetflt
Note: This is now available for the OSE version as well, contrary to the report regarding 8.10 below

Host Networking in Ubuntu 10.04

You just need to load the "vboxnetflt" modules if it isn't loaded yet.
sudo modprobe vboxnetflt
Note: This does not work by default with virtualbox-ose, as the vboxnetflt module doesn't seem to be included in the package. Fix unknown.

Host Networking in Ubuntu 10.04 and older

To configure Host Networking you need to configure network bridging, you basically go through four steps on the host machine:
  • install necessary packages
  • declare bridge and real network interface you add to it
  • declare virtual interfaces
  • set permissions on /dev/net/tun

Install necessary packages

First you need to install bridge-utils to be able to create network bridges:
$ sudo apt-get install bridge-utils

Declare bridge

Before you begin, back up the current interfaces file with a copy that has the current date in its name:
$ sudo cp /etc/network/interfaces /etc/network/interfaces.`date +%F~%T` 
You have to edit /etc/network/interfaces on the host machine to declare the bridge, this procedure is slightly different if your host use static or dynamic IP.
If you have dynamic IP, on the host machine:
$ sudo nano /etc/network/interfaces
auto eth0
iface eth0 inet manual

auto br0
iface br0 inet dhcp
   bridge_ports eth0 vbox0

# The loopback network interface
auto lo
iface lo inet loopback
"eth0" is the name of your interface, it can be different depending on your machine.
"br0" is an arbitrary name for the bridge.
"vbox0" is an arbitrary name for the device VirtualBox will use, if you want more devices, you just add then like:
bridge_ports eth0 vbox0 vbox1 vbox2 vbox3 vbox4
and so on. Don't forget you will need to declare this devices on another file, this will be explained later on, keep reading.
If you are using static IP addresses modify the interfaces like this:
$ sudo nano /etc/network/interfaces
auto eth0
iface eth0 inet manual

auto br0
iface br0 inet static
    address 192.168.0.100
    netmask 255.255.255.0
    gateway 192.168.0.1
    bridge_ports eth0 vbox0 vbox1

# The loopback network interface
auto lo
iface lo inet loopback
Replace 192.168.0.100 with your IP, 255.255.255.0 with your netmask and 192.168.0.1 with your gateway. If you are using static IP addresses for eth0, eth1, etc; you will need to configure the br0 interface using the same settings! Otherwise your system will request an IP address via DHCP. You may add as many vbox# interfaces as you wish as long as they are also declared in /etc/vbox/interfaces; keep reading for details.
You need to restart networking for the changes to take effect:
$ sudo /etc/init.d/networking restart
You can ignore the messages complaining about the "vbox#" devices.

Declare virtual interfaces which will be used by VirtualBox

To declare the virtual interfaces used by VirtualBox you need to edit /etc/vbox/interfaces on the host machine:
$ sudo nano /etc/vbox/interfaces
# Each line should be of the format :
#   []
vbox0  br0
vbox1  br0
...
"vbox#" is an arbitrary name. You may declare here as many virtual interfaces as you wish, as long as they have been properly declared in /etc/network/interfaces. In this specific article, we declared two vbox interfaces in /etc/network/interfaces, then finished setting them up in /etc/vbox/interfaces.
To take the modifications into account, restart the VirtualBox host networking script. If you installed VirtualBox OSE:
$ sudo /etc/init.d/virtualbox-ose restart
If you installed the pre-compiled proprietary version:
$ sudo /etc/init.d/vboxnet restart
The virtual interfaces are now created and added to the bridge.
That's it! Now the different scripts will take care of cleanly create/configure/remove bridges and virtual interfaces when you boot and shut your system down.

Set permissions on /dev/net/tun

You need to have read/write permissions on the file /dev/net/tun to be able to use the bridge, to set permissions:
$ sudo chown root:vboxusers /dev/net/tun
$ sudo chmod g+rw /dev/net/tun
This file is created with the default permissions every time the system restarts, to make the new permissions permanent you have to edit the file /etc/udev/rules.d/20-names.rules and change:
KERNEL=="tun",                          NAME="net/%k"
to
KERNEL=="tun",                          NAME="net/%k",  GROUP="vboxusers",     MODE="0660"

Configure networking in VirtualBox

Once you have everything ready, you can start the VirtualBox management interface on the host machine, configure the network of your virtual machine, and by selecting "host networking", enter the name of one of the virtual adapter you have configured. Start your virtual machine, it gets a network card presented, that you can set up as you wish (static IP address, DHCP) using the network configuration tools inside the virtual machine.

Wireless Networking

Setting up a normal bridged network generally doesn't work if you're bridging from a wireless card to VirtualBox. A simple script that utilises the parprouted tool will allow your VM full access to the wireless network.
You will require parprouted to do this:
sudo apt-get install parprouted
Next, using your favorite text editor, create and edit the script, for example:
sudo nano /etc/network/if-up.d/vbox_network
Then, enter the script (replacing $USER with your username (or whoever you intend to run virtualbox as)). Replace wlan0 with the name of your wireless interface. Use an available IP address on your network for tap0 (I have used 192.168.1.100 in this case):
sysctl net.ipv4.ip_forward=1
VBoxTunctl -b -u $USER
ip link set tap0 up
ip addr add 192.168.1.100/24 dev tap0
parprouted wlan0 tap0
Finally, make sure the new file is executable by root:
sudo chmod 700 /etc/network/if-up.d/vbox_network
Now your networking script is installed, the virtual interface tap0 will be available on boot for VirtualBox. Rather than reboot, let's just run the script now:
sudo /etc/network/if-up.d/vbox_network
The final thing to do is tell VirtualBox to use the new virtual device tap0. Open VirtualBox, highlight a VM and click settings. Now choose the network option and select Host Interface on the 'attached to' drop down menu. In the Interface Name text box, enter: tap0
Click ok and start your VM. The VM should now behave as though it was another physical machine on your network!!
For more information on the process up to this point, please visit Bridged Networking with VirtualBox on Linux Hosts

Using DHCP in the Guest VM

It was possible to get DHCP to work on the guest virtual machine. Instructions were taken from here. Because parprouted does not relay multicast, we need to use an additional helper daemon to manage this. I tried dhcp-helper and bcrelay, and had the most success with bcrelay.
Use it as follows:
sudo apt-get install bcrelay
sudo bcrelay -i tap0 -o wlan0
At this point, my /etc/network/if-up.d/vbox_network is as follows:
#!/bin/sh
sysctl net.ipv4.ip_forward=1
VBoxTunctl -b -u jacob
ip link set tap0 up
ip addr add 192.168.1.200/32 dev tap0
parprouted tap0 wlan0  &
route add -net 192.168.1.0 netmask 255.255.255.0 tap0
bcrelay -i tap0 -o wlan0 &
It seems that I have to start the script by hand after boot. Other than that, host networking now seems to work fine (this issue should be solved by adding the "#!/bin/sh" line just at the beginning of the script.

Cloning Pitfalls Between Different Hosts

When cloning a VirtualBox guest operating system and using it between different host computers, one common pitfall for Debian/Ubuntu guest OSes is the MAC address.
If it differs from the one set for it by the host that created it, you will likely have problems with the networking adapter eth0 not showing up and may only see the lo when typing ifconfig from the CLI.
Here's the steps to fix this:
  1. Open VirtualBox on both host machines you're using the VirtualBox image on.
  2. On the host that you used to create the VirtualBox image on, select the virtual machine (make sure it's not running) and go to the settings.
  3. Click on the Network settings and then expand the Advanced section.
  4. Now copy the Mac Address.
  5. Follow steps 1-3 on the second host machine and then replace the Mac Address on the second host machine with the Mac Address from the first host machine.
You should be able to start your VirtualBox guest OS now and use the eth0 adapter just fine. If not, double-check the Mac Address again.


Awaiting your feedback on this tutorial ....... press mail me

Saturday, March 27

VirtualBox -- professional, flexible, open : Interesting solution for many problems !!

VirtualBox is a general-purpose full virtualizer for x86 hardware. Targeted at server, desktop and embedded use, it is now the only professional-quality virtualization solution that is also Open Source Software.
Some of the features of VirtualBox are:
  • Modularity. VirtualBox has an extremely modular design with well-defined internal programming interfaces and a client/server design. This makes it easy to control it from several interfaces at once: for example, you can start a virtual machine in a typical virtual machine GUI and then control that machine from the command line, or possibly remotely. VirtualBox also comes with a full Software Development Kit: even though it is Open Source Software, you don't have to hack the source to write a new interface for VirtualBox.
  • Virtual machine descriptions in XML. The configuration settings of virtual machines are stored entirely in XML and are independent of the local machines. Virtual machine definitions can therefore easily be ported to other computers.
  • Guest Additions for Windows, Linux and Solaris. VirtualBox has special software that can be installed inside Windows, Linux and Solaris virtual machines to improve performance and make integration much more seamless. Among the features provided by these Guest Additions are mouse pointer integration and arbitrary screen solutions (e.g. by resizing the guest window). There are also guest additions for OS/2 with somewhat reduced functionality.
  • Shared folders. Like many other virtualization solutions, for easy data exchange between hosts and guests, VirtualBox allows for declaring certain host directories as "shared folders", which can then be accessed from within virtual machines.
A number of extra features are available with the full VirtualBox release only (see the "Editions" page for details):
  • Virtual USB Controllers. VirtualBox implements a virtual USB controller and allows you to connect arbitrary USB devices to your virtual machines without having to install device specific drivers on the host.
  • Remote Desktop Protocol. Unlike any other virtualization software, VirtualBox fully supports the standard Remote Desktop Protocol (RDP). A virtual machine can act as an RDP server, allowing you to "run" the virtual machine remotely on some thin client that merely displays the RDP data.
  • USB over RDP. With this unique feature, a virtual machine that acts as an RDP server can still access arbitrary USB devices that are connected on the RDP client. This way, a powerful server machine can virtualize a lot of thin clients that merely need to display RDP data and have USB devices plugged in. 

Download VirtualBox

Here, you will find links to VirtualBox binaries and its source code.

VirtualBox binarie

The binaries in this section are all released under the VirtualBox Personal Use and Evaluation License (PUEL). By downloading, you agree to the terms and conditions of that license.
  • VirtualBox 3.1.6 for Windows hosts x86/amd64
  • VirtualBox 3.1.6 for OS X hosts Intel Macs
    Due to an accident the original 3.1.6 Mac OS X package (build 59338) was broken. Please install the fixed package if you installed the broken package. Sorry for the inconveniences!
  • VirtualBox 3.1.6 for Solaris and OpenSolaris hosts x86/amd64
  • VirtualBox 3.1.6 Software Developer Kit (SDK) All platforms (registration required) 
This is a snapshot of the OSE sources at the time of the stable 3.1.6 release.
This is the current development code, which is not necessarily stable.
  • Checking out from our Subversion server.
    svn co http://www.virtualbox.org/svn/vbox/trunk vbox
    This is the current development code, which is not necessarily stable.

    Note: The repository was recently moved. If svn update aborts with an error message regarding a moved repository, then do
    svn switch --relocate \
       http://virtualbox.org/svn/vbox/trunk \
    http://www.virtualbox.org/svn/vbox/trunk
After getting the sources in one of the ways listed above, you should have a look at the build instructions.


End-user documentation

This page is for end users who are looking for information about how to download and run VirtualBox.
In order to run VirtualBox on your machine, you need:
  • Reasonably powerful x86 hardware. Any recent Intel or AMD processor should do.
  • Memory. Depending on what guest operating systems you want to run, you will need at least 512 MB of RAM (but probably more, and the more the better). Basically, you will need whatever your host operating system needs to run comfortably, plus the amount that the guest operating system needs. So, if you want to run Windows XP on Windows XP, you probably won't enjoy the experience much with less than 1 GB of RAM. If you want to try out Windows Vista in a guest, it will refuse to install if it is given less than 512 MB RAM, so you'll need that for the guest alone, plus the memory your operating system normally needs.
  • Hard disk space. While VirtualBox itself is very lean (a typical installation will only need about 30 MB of hard disk space), the virtual machines will require fairly huge files on disk to represent their own hard disk storage. So, to install Windows XP, for example, you will need a file that will easily grow to several GB in size.
  • A supported host operating system. Presently, we support Windows (primarily XP) and many Linux distributions on 32-bit hosts and on 64-bit hosts. Support for Mac OS X and Solaris and OpenSolaris appeared in 1.6.
  • A supported guest operating system. Besides the user manual (see below), up-to-date information is available at "Status: Guest OSes". 
VirtualBox for FreeBSD. This screenshot shows a first version running Ubuntu. NAT networking works.
VirtualBox for FreeBSD. This screenshot shows a first version capable of running Windows.
VirtualBox for Mac OS X. One virtual machine is running in seamless mode on Leopard. Note the realtime preview of the virtual machine in the dock.
VirtualBox for Mac OS X, currently in beta test. Two virtual machines are visible: one with Windows Vista, another with Gentoo Linux.
Creating a new, empty VM for installing Windows Vista.
The new VM in the VirtualBox main window. Note that an ISO file (containing the Vista setup CD) has been mounted as the VM's CD-ROM drive.
After starting the VM, it boots off the virtual CD-ROM (the ISO file with the Vista setup), and Vista Setup starts up.
Vista is installing into the virtual hard drive.
Vista install complete: the log-on screen.
Compiling VirtualBox on Ubuntu Edgy Eft in VirtualBox on Windows XP.
Details of a snapshot performed after Vista installation. We can revert the virtual machine to this snapshot at a later time.
Damn Small Linux 2.0 works damn well in VirtualBox!
The Virtual Disk Manager allows you to work with VM images.
VirtualBox in Vista inside VirtualBox on XP? Perhaps some day...
A community-based effort is underway to port VirtualBox to OS/2 hosts. This screenshot shows a first alpha version. 

Send me your feedback on lifeisbeautiful0505@gmail.com