Page 1 of 3 123 LastLast
Results 1 to 10 of 29

Thread: HowTo : Virtualbox host networking with WIFI

  1. #1
    Join Date
    May 2005
    Location
    Lyon, France
    Beans
    916
    Distro
    Ubuntu Development Release

    HOWTO : Virtualbox host networking with WIFI

    Virtualbox host networking and WIFI.

    Virtualbox > 2.1.4 and Jaunty. Virtualbox does that on its own now. Select host interface (or bridge network in 2.2) and then your wifi card.
    No need for this lengthy howto anymore...


    Scope of this HowTo
    While being connected to your router (thus the Internet) via your laptop WIFI card, enable host networking on a different subnet by bridging your ethernet card.
    Your ethernet card does not have to be physically connected to your network for this to work.

    Your Virtualbox machines will be connected to the Internet as well.

    The tutorial is constructed as follows:
    similar settings to Vbox > 2.1.0 and Vbox < 2.1.0
    Vbox > 2.1.0
    Vbox < 2.1.0
    Guest configuration

    Tested and working with the following:
    Virtualbox 1.5.6, 1.6.0, 1.6.2 Ubuntu 8.04 Hardy Heron
    Virtualbox 2.0.4, 2.0.6 Ubuntu 8.10 Intrepid Ibex
    Virtualbox > 2.1.0 Ubuntu 8.10 Intrepid Ibex

    Pre-requisites
    One computer with:
    ethernet controller eth0
    WIFI Controller eth1 (or wlan0 or whatever you have, change accordingly to your system)
    Virtualbox
    Internet connection thru eth1 (WIFI)

    All the bridge creation and host interface creation knowledge comes from Virtualbox help contents. (see chapter Host Interface Networking and bridging on Linux hosts, version 2.0.6 or previous, as of 2.1.0 host networking is "integrated" in VBox)

    HowTo - by example
    Consider a connection to the internet via eth1 (WIFI) with IP 192.168.1.2 (netmask 255.255.255.0).
    The bridge IP address will be 192.168.0.2 (same netmask as above - note the difference of subnet between the wifi and the bridge).

    Bridge br0 will include eth0 (ethernet card) and the host interfaces (tap0, tap1 ... - only for Vbox < 2.1.0)

    I will assume that virtualbox is up and running for the user joe.

    Similar settings
    Install the necessary tools
    Code:
    sudo apt-get install bridge-utils
    Modify /etc/network/interfaces
    Code:
    auto lo
    iface lo inet loopback
    
    auto br0
    iface br0 inet static
    address 192.168.0.2
    netmask 255.255.255.0
        bridge_ports eth0
        bridge_maxwait 0
    Restart networking
    Code:
    sudo invoke-rc.d networking restart
    Enable ip_forwarding: modify /etc/sysctl.conf
    Code:
    net.ipv4.ip_forward=1
    While it is not necessary to create a firewall service to enable masquerading, it will be much easier to activate if you do so. You can use ufw if you prefer.

    Code:
    sudo vi /etc/init.d/firewall
    #/bin/bash
    
    start() {
    	echo "Creating iptables rule"
    	iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
    }
    
    stop() {
    	echo "Flushing iptables"
    	iptables -P INPUT ACCEPT
    	iptables -P FORWARD ACCEPT
    	iptables -P OUTPUT ACCEPT
    	iptables -t nat -P PREROUTING ACCEPT
    	iptables -t nat -P POSTROUTING ACCEPT
    	iptables -t nat -P OUTPUT ACCEPT
    	iptables -F
    	iptables -t nat -F
    	iptables -X
    	iptables -t nat -X
    }
    
    case $1 in
    	start) 	start;;
    	stop) 	stop;;
    	restart) 	stop
    			start;;
    	status) /sbin/iptables -L
    		/sbin/iptables -t nat -L
    		exit 0;;
    	*) 	echo "Usage: firewall {start|stop|restart|status}"
    		exit 1
    esac
    exit
    Make the script executable
    Code:
    sudo chmod u+x /etc/init.d/firewall
    Create links for the service to be started/stopped automatically
    Code:
    sudo update-rc.d firewall defaults
    Start the service to enable masquerading
    Code:
    sudo invoke-rc.d firewall start
    VBox 2.1.0
    The configuration is almost over.
    You just need to select host interface in the virtual machine settings and choose br0.

    VBox < 2.1.0

    Code:
    sudo apt-get install uml-utilities
    sudo gpasswd -a uml-net $USER
    sudo chgrp uml-net /lib/udev/devices/net/tun
    sudo chmod g+rw /lib/udev/devices/net/tun
    (reboot necessary unless someone has another solution. You can change the ownership of /dev/net/tun right away and wait for a later reboot)

    If you want to create a permanent host interface
    change /etc/network/interfaces to
    Code:
    auto lo
    iface lo inet loopback
    
    auto tap0
    iface tap0 inet manual
    up ifconfig $IFACE 0.0.0.0 up
    down ifconfig $IFACE down
    tunctl_user joe    ###replace joe with the name of your user member of vboxusers and uml-net groups##
    
    auto br0
    iface br0 inet static
    address 192.168.0.2
    netmask 255.255.255.0
        bridge_ports eth0 tap0 #tap1 tap2 ...
        bridge_maxwait 0
    Add as many host interfaces (tap1 tap2 ...) as desired on the same principle. If you do so, don't forget to add them to the bridge.

    Restart networking
    Code:
    sudo invoke-rc.d networking restart
    Assign tap0 (tap1 ...) as a host interface to your virtual machine.

    I prefer dynamic host interfaces
    To create dynamic tap interfaces (from the virtualbox help, 6.7.2. Creating interfaces dynamically when a virtual machine starts up):
    * create a start up script (wherever you want, just remember where), replace joe with your user member of vboxusers and uml-net groups
    Code:
    cat > /home/joe/addtap.sh <<eof
    #!/bin/bash
    
    # Create an new TAP interface for the user 'joe' and remember its name.
    interface=\`VBoxTunctl -b -u joe\`## replace joe with your user
    
    # If for some reason the interface could not be created, return 1 to
    # tell this to VirtualBox.
    if [ -z "\$interface" ]; then
    exit 1
    fi
    
    # Write the name of the interface to the standard output.
    echo \$interface
    
    # Bring up the interface.
    ifconfig \$interface up
    
    # And add it to the bridge.
    brctl addif br0 \$interface
    eof
    
    chmod u+x /home/joe/addtap.sh
    * create an end script
    Code:
    cat > /home/joe/deltap.sh <<eof
    #!/bin/bash
    
    # Remove the interface from the bridge.  The second script parameter is
    # the interface name.
    brctl delif br0 \$2
    
    # And use VBoxTunctl to remove the interface.
    VBoxTunctl -d \$2
    eof
    
    chmod u+x /home/joe/deltap.sh
    In the virtual machine network settings, do the following changes
    attached to: host interface
    interface name: (nothing, leave it empty)
    setup application: gksudo /home/joe/addtap.sh
    terminate application: gksudo /home/joe/deltap.sh

    if you wish to avoid typing your password when the tap interface is created, add the following line to your sudoers file
    Code:
    sudo visudo
    %vboxusers ALL=(ALL) NOPASSWD: /home/joe/addtap.sh, /home/joe/deltap.sh
    Guest configuration

    1) No DHCP server
    If you have no dhcp server serving the 192.168.0.0 range, you will need to assign an IP address in the 192.168.0.0 range to your virtual machine once it is started.
    Code:
    sudo ifconfig eth0 192.168.0.3
    It will be necessary to add 192.168.0.2 as a default route as well
    Code:
    sudo route add default gw 192.168.0.2
    If you want to make it permanent, edit /etc/network/interfaces of your virtual machine.
    Code:
    auto eth0
    iface eth0 inet static
    address 192.168.0.3
    netmask 255.255.255.0
    gateway 192.168.0.2
    2) DHCP server
    You have a dhcp server serving on the 192.168.0.0 range
    either locally (laptop):
    make sure the "option routers" given by dhcp is the IP of your bridge br0 (192.168.0.2)

    or on your ethernet LAN connection:
    nothing to do (in that case, your access to the internet will occur thru ethernet most certainly and not thru WIFI)

    James Dupin
    https://wiki.ubuntu.com/VirtualboxHostNetworkingAndWIFI
    Last edited by bluefrog; April 28th, 2009 at 10:46 AM.
    James Dupin
    IT contractor
    Project delivery specialist
    http://fr.linkedin.com/in/jamesdupin

  2. #2
    Join Date
    Dec 2007
    Beans
    9

    Re: HowTo : Virtualbox host networking with WIFI

    You are my Hero, after many many failed attempts i have my wifi bridged (Ubuntu Hardy Host / Win XP Guest). I can now enjoy my slingplayer goodness from my home network without having to reboot and load up my windows partition. I followed the instructions but then realized that my network did not fit your pre-requisites.
    the alias on my devices were different fixed it with info i found on this thread:
    http://ubuntuforums.org/showthread.php?t=496532
    that got me in the ball park then i followed your steps for dynamic setup,
    then got real frustrated
    cause when i set my virtual box settings
    "In the virtual machine network settings, do the following changes
    attached to: host interface
    interface name: (nothing, leave it empty)
    setup application: gksudo /home/joe/addtap.sh
    terminate application: gksudo /home/joe/deltap.sh"

    Vbox wouldn't load
    I was about ready to give up and undo what i had done so far, but i tried changing from "host interface"
    to "nat"
    Loaded up again.... and bango booya ...bridged network goodness and my slingplayer is now working in virtualbox on my home network....yah
    (a bit long winded but im excited to be able to use my favorite windows app again)

  3. #3
    Join Date
    May 2005
    Location
    Lyon, France
    Beans
    916
    Distro
    Ubuntu Development Release

    Re: HowTo : Virtualbox host networking with WIFI

    You don't need to do all that if you use NAT. NAT is working out of the box with wifi or ethernet. (this how to has a specific use people who need it will recognize)

    So basically, if you are using NAT, all you have done following this howto is useless. Would have worked anyway (normally).

    You say VBox wouldn't load. What was the error message? Make sure you adapted the commands/lines in script to fit your architecture (example: replace joe with your user name, and adapt the path to where you created the scripts) and make sure your user is a member of the uml-net group (you need to log out/ log in after having added the user to the group) and that the following lines are written as is (VBox machines settings, as if you write gksudo then select the script with the "explorer" button in the settings window, gksudo will disappear.
    setup application: gksudo /home/joe/addtap.sh
    terminate application: gksudo /home/joe/deltap.sh

  4. #4
    Join Date
    Jul 2008
    Beans
    1

    Re: HowTo : Virtualbox host networking with WIFI

    Hi, thanks for the howto , but unfortunately I can't get my VBox to work with a bridged connection... I've followed several tutorials but so far no luck. Here's my setup:

    My Box:
    -Dell Inspiron 1420N w/Ubuntu Hardy.
    -eth0 is wifi / eth1 is wired.
    -VirtualBox 1.5.6_OSE hosting a Windows XP VM.

    I need to be able to gain direct (or transparent) access to several different LAN networks, each with their own DHCP, DNS and internet gateway.

    It'd be nice if I could bridge both of my ethernet interfaces (wired and wireless) to my VMs, but wireless is definitively a priority.

    I followed your tutorial step-by-step, except for "make sure the gateway given by dhcp is the ip of your bridge br0". How do I know the IP of my br0 bridge? Do I have to tweak every DHCP I use? (I don't have admin access to some)

    Please help me, I'm new to linux and I'm loving it, but I really need to get this right for my work. I really don't wanna install Windoze natively!

    Thanks in advance.

  5. #5
    Join Date
    May 2005
    Location
    Lyon, France
    Beans
    916
    Distro
    Ubuntu Development Release

    Re: HowTo : Virtualbox host networking with WIFI

    If you followed that HowTo, you have given br0 an IP, so you know it.

    And what is failing if you followed that HowTo? Please give details as of what is the error and if you followed that HowTo concerning that error.

    For the rest, I don't understand what you want to do as if there are several dhcp servers (with different subnets of course) on your network(s) how are you going to do to get an IP from a specific server, but well this is your problem. The only thing that would be of some sense to me is for you to assign an IP to each of your virtual machines (inside the virtual machine) so that they can talk on the different subnets you have.

    If you read carefully that HowTo, you will see that I do not bridge the wifi interface but only the ethernet interface, but I use the wifi interface to get out of the laptop.
    Bridging the wifi interface do not work 99% (or more or less, I don't know) of the time due to wifi card restrictions.

  6. #6
    Join Date
    Jan 2008
    Beans
    219

    Re: HowTo : Virtualbox host networking with WIFI

    Hi,
    I also am trying to get this to work, and thus far have had little luck (on this machine).
    I went for your preferred method, the dynamic host interface, and so, I modified the /etc/network/interfaces file as specified.
    This is, I believe, where things go wrong for me.
    With this file modified so, I no longer get an address from my dhcp. I found this out when I restarted networking....
    I wasn't quite sure what was going on (as i am... new to messing about with networking) and so i did the super sure reboot, and the problem still existed. Reverting the interfaces file to its original state and restarting networking fixed my wireless.

    What do you believe may be the problem here?

    Thanks in advance!

    sean

    p.s. stupid newbie question, but how do I know which interface is my wireless, and which is my ethernet? By looking at the output from 'ifconfig' and seeing that the eth1 is the more verbose, and knowing that I only ever use wireless, i would have assumed that the eth1 is my WIFI controller, and eth0 is my ethernet..... This I assume would make a big difference to it working or not?

    Just in case, here is a printout from my ifconfig when all is fresh and as normal: p.s. I think the vm interfaces at the bottom were created by my installation of vmware some time back..... no?

    Code:
    sean@svUbuntuX:~$ ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:08:0d:9e:52:12  
              UP BROADCAST MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
    
    eth1      Link encap:Ethernet  HWaddr 00:02:2d:81:93:eb  
              inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
              inet6 addr: fe80::202:2dff:fe81:93eb/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:3132 errors:0 dropped:0 overruns:0 frame:0
              TX packets:3024 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:2653334 (2.5 MB)  TX bytes:540078 (527.4 KB)
              Interrupt:11 Base address:0xd100 
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:1108 errors:0 dropped:0 overruns:0 frame:0
              TX packets:1108 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:57430 (56.0 KB)  TX bytes:57430 (56.0 KB)
    
    vmnet1    Link encap:Ethernet  HWaddr 00:50:56:c0:00:01  
              inet addr:192.168.241.1  Bcast:192.168.241.255  Mask:255.255.255.0
              inet6 addr: fe80::250:56ff:fec0:1/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:82 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
    
    vmnet8    Link encap:Ethernet  HWaddr 00:50:56:c0:00:08  
              inet addr:192.168.152.1  Bcast:192.168.152.255  Mask:255.255.255.0
              inet6 addr: fe80::250:56ff:fec0:8/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:83 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
    
    sean@svUbuntuX:~$

  7. #7
    Join Date
    Dec 2007
    Beans
    2

    Re: HowTo : Virtualbox host networking with WIFI

    I follow you step "sudo gpasswd -a $USER uml-net" -a is "Command line option 'a' [from -a] is not known" is there any reference ?? to do help.

    thanks
    Zyke

  8. #8
    Join Date
    May 2005
    Location
    Lyon, France
    Beans
    916
    Distro
    Ubuntu Development Release

    Re: HowTo : Virtualbox host networking with WIFI

    to Zeefux:
    sudo gpasswd -a $USER uml-net works as is on a "normal" ubuntu distro and should work as is on any?/most Linux distro.
    gpasswd is a tool to administer the /etc/group file (man gpasswd).
    You could use usermod as well but the syntax is usermod -aG group user (failure to write "a" will replace all your groups by the new group, that is why I prefer gpasswd when I explain how to add a user to a group)

    to Svaens:
    Use iwconfig to be sure.
    Your vmnet network interfaces come from vmware indeed. They should have been removed when you removed vmware. Don't know if they can disturb what you are trying to do.
    In the HowTo I do not do anything about eth0 or eth1 in the file /etc/network/interfaces, so if you touched that file according to the HowTo there is no reason for your card to not getting a dhcp address.
    Are you using Ubuntu or Kubuntu? Do you have the network-manager running?

  9. #9
    Join Date
    Jan 2008
    Beans
    219

    Re: HowTo : Virtualbox host networking with WIFI

    Hi, and thanks for the reply bluefrog!
    iwconfig shows my eth1 to be the wireless.

    Code:
    lo        no wireless extensions.
    
    eth0      no wireless extensions.
    
    irda0     no wireless extensions.
    
    eth1      IEEE 802.11b  ESSID:"HoneyPie"  Nickname:"HERMES I"
              Mode:Managed  Frequency:2.462 GHz  Access Point: 00:16:E3:6C:1C:7C   
              Bit Rate:11 Mb/s   Sensitivity:1/3  
              Retry limit:4   RTS thr:off   Fragment thr:off
              Power Management:off
              Link Quality=45/92  Signal level=-47 dBm  Noise level=-92 dBm
              Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:31
              Tx excessive retries:0  Invalid misc:0   Missed beacon:0
    
    vmnet1    no wireless extensions.
    
    vmnet8    no wireless extensions.
    I guess that means I need to modify your scripts (and instructions) to swap your usage of eth0 and eth1 ?

    As for your comments and questions,
    the vmnet interfaces, they are there because I never did uninstall vmware in any way. I never considered that the existing interfaces that it has left could cause me trouble. I am no expert, but i wouldn't have expected it. If nothing else works, I will remove them.

    It is strange that my network halts with the interfaces file modified... yes. But i did indeed simply copy your text exactly into the file.
    But you do mention eth1 in the file, in the line:
    Code:
    bridge_ports eth1
    Obviously, I do not know enough about it, and I should (and will) try to read up on how this file is used by the networking components. But any hints and help from you would be heartily welcome!

    I am using Ubuntu by the way. Hardy 8.04, fully up to date Ubuntu.
    And yes, I would say the network-manager is correctly running... I checked just now and I see the nm-applet in the process list.. (i assume that is it? ).

    Actually, Looking through your HowTo, the interfaces file is the 'Only' place you mention either eth0 or eth1. Not mentioned in the create script at all..... How is it working? What could be going wrong with my situation?

  10. #10
    Join Date
    May 2005
    Location
    Lyon, France
    Beans
    916
    Distro
    Ubuntu Development Release

    Re: HowTo : Virtualbox host networking with WIFI

    The problem came as you bridged your wifi card.

    if eth1 is your wifi card then use this configuration:

    /etc/network/interfaces
    Code:
    auto lo
    iface lo inet loopback
    
    auto br0
    iface br0 inet static
    address 192.168.1.20      ## replace by your preferred IP
    netmask 255.255.255.0     ## replace by your preferred subnet mask
        bridge_ports eth0
        bridge_maxwait 0

Page 1 of 3 123 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •