VirtualBox Interface Sharing

12:06 am Vm Desktop, VM, Gentoo, Linux

VirtualBoxOk.. first little stumble when trying out Virtual Box but it is not the fault of Sun/VirtualBox.

The virtual folder sharing works but is slow. The way to fix that is actually simple turn up network sharing on a regular virtual interface.

Here is a way to do that!

First you need to make sure that you have the following packages on your Gentoo System: sys-apps/usermode-utilities if you do not have them, emerge them you will need it. If the system is not Gentoo look for usermode utilities on your system, I think it Ubuntu it is uml-utilities.

Then you want to make sure that you have TUN/TAP driver loaded. To do that you want to see if it came up during startup.
dmesg | grep TUN
You should see a line like
tun: Universal TUN/TAP device driver, 1.6

If you do not you can use the first part of this documentation on how to bring it up:
http://www.gentoo.org/doc/en/vpnc-howto.xml

After the utilities are installed you need to execute the following commands as root or use sudo:

tunctl -t <interface_name> -u <username>

For me for the interface named I used vboxp0 (virtual box private 0), but you can use any interface name you like. For the username use your username.

After interface is assigned, you need to assign an IP address to it. To do that you use the regular ifconfig command. For example you can use something like this as root or using sudo:

ifconfig vboxp0 10.10.10.1 netmask 255.255.255.0

A few more steps and we are done.

Next we need to make sure that vboxusers group has access to the tun interface and to do that is simple, once again as root or using sudo:

chgrp vboxusers /dev/net/tun

Then make sure to set group permissions so that vboxusers can use it.
chmod 660 /dev/net/tun

Now make sure that vboxusers has the proper users in it, you would have to do that anyway to get vbox to work.

Now before we make it permanent lets test and see if it works!

Start Virtual Box but do not start the virtual machine. Go to one of the interfaces that are not used in your virtual machine as shown in the picture below.

VirtualBox_Net01

(For those that can not see the picture, it is enable Host Interface, then set the name of the interface to the name that you choose).

Boot your VirtualBox System now, and it should find the second interface. It will fail because the interface is set to DHCP and we do not have a DHCP server running on that interface (it is not hard to start one up, but there is no reason to do it ). So you need to hard code the Interface to a static IP address. Make sure you do not put a default gateway (leave it blank) as on windows systems that screws up the routing.

You should now be able to ping the gateway system.

If you can ping the gateway system, then we can make the settings to start up automatically. There are two ways of doing this of course. One way is to have a script that will start up the interface as part of vritual box, but since I always use the virtualbox of one kind or another, windows, linux, bsd, etc on my system then I felt for me I will make it boot up all the time.

This is the power of GENTOO! For how to do this you can also reference the file /etc/conf.d/net.example:

In /etc/conf.d/net set the following options:
#<Vbox_Interface_Name> Interface
tuntap_<vboxname>=”tap”
tunctl_<vboxname>=”-u <username>”
config_<vboxname>=(”<network_IP>/<bit_Mask>”)

Example of my configuration (modified of course):

#Vboxp0 Interface
tuntap_vboxp0=”tap”
tunctl_vboxp0=”-u testuser”
config_vboxp0=(”10.10.10.1/24″)

Now for some explanation:
The first line tuntap_xxx=”tap” sets the interface as a tap, and assignes a virtual name to it.

The second line sets the user up on the interface that will start VirtualBox. Unfortunately I have found no way to get around this, even though the group is correct the user must match the user starting Virtual Box. If you figure out some workaround for this, please let me know. This works for me and since I am the only one that uses this system it is no big deal.

The third line just assigns an IP address to the interface.

Now there are two ways you can use this, like I do which is automatically started every time. Or manually start it. In either way step one below is needed.

Step1: We need to link the script to startup the interface. So as root or using sudo issue the following:

ln -s /etc/init.d/net.lo net.<interfacename>

For me it is ln -s /etc/init.d/net.lo net.vboxp0

Now if you want to start and stop it manually, go ahead and do it as a regular interface on Gentoo. If you want to automate it starting up that is simple as well, we just need to set the following as root or using sudo:

rc-update add net.<interfacename> default

For me it is rc-update add net.vboxp0 default.

That is it!

Now that we got the interface running and pinging I will write another post on how to share out a share from a Linux host only on the virtual interface in Samba.

Request: if you find a better way of doing things, or have some modification to this, please let me know as I know there are a lot of smarter people then me out there, that can find a better way of doing this!

Thank you!


Site Search Tags: , , , , , , , ,
Copyright (c) by BlueKnight

Leave a Comment

Your comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.