NonExistentHelpPage

Differences between revisions 6 and 7
Revision 6 as of 2008-05-05 19:17:26
Size: 4557
Editor: dyn-213-36-168-139
Comment:
Revision 7 as of 2008-05-05 19:28:08
Size: 35
Editor: dyn-213-36-168-139
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
||<tablestyle="float:right; font-size: 0.9em; width:40%; background:#F1F1ED; margin: 0 0 1em 1em;" style="padding:0.5em;">'''Contents'''[[BR]][[TableOfContents(4)]]||

Virtualbox host networking and WIFI

= Scope of this howto =
While being connected to your router (thus the Internet) via your computer WIFI card, enable host networking on a different subnet by bridging your unused ethernet card.

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

Tested with Virtualbox 1.5.6 and Ubuntu 8.04 (Hardy)

= Pre-requisites =
One computer with:[[BR]]
WIFI controller eth0[[BR]]
ethernet controller eth1[[BR]]
Virtualbox[[BR]]
Internet connection thru eth0[[BR]]
 
All the bridge creation and host interface creation knowledge comes from Virtualbox help contents. (see chapter 6.5.1. Permanent host interfaces and bridging)

= How to - by example =
Consider a connection to the internet via eth0 (WIFI) with IP 192.168.0.2 . [[BR]]
The bridge IP address will be 192.168.1.254 (note the difference of subnet between the wifi and the bridge). [[BR]]
Bridge br0 will include eth1 (ethernet card) and host interface tap0. [[BR]]

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

== Install the necessary tools ==
{{{
sudo apt-get install bridge-utils uml-utilities
sudo gpasswd -a $USER uml-net
}}}

At this stage /dev/net/tun owners should be root.uml-net, change accordingly if this is not the case.
{{{
ls -l /dev/net/tun
crw-rw---- 1 root uml-net 10, 200 2008-04-11 23:55 /dev/net/tun
}}}

== Edit /etc/network/interfaces ==
A fresh /etc/network/interfaces should look like the following (or be quite similar)
{{{
auto lo
iface lo inet loopback
auto eth1
}}}

Edit it and change it to
{{{
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.1.254
netmask 255.255.255.0
    bridge_ports eth1 tap0
    bridge_maxwait 0

auto eth1
}}}

Add as many host interfaces as desired on the same principle.

== Enable IP forwarding ==
Enable IP forwarding by uncommenting line 38 in /etc/sysctl.conf
{{{
net.ipv4.ip_forward=1
}}}

== Create a firewall service ==
While it is not necessary to create a firewall service to enable masquerading, it will be much easier to activate if you do so.

{{{
sudo cat > /etc/init.d/firewall <<stop
#/bin/bash

start() {
 echo "Creating iptables rule"
 iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
 exit 0
}

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
 exit 0
}

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
stop
}}}

Create links for the service to be started/stopped automatically
{{{
sudo update-rc.d firewall defaults
}}}
Start the service
{{{
sudo invoke-rc.d firewall start
}}}

== Host interface IP in the virtual machine ==
Assign tap0 as a host interface to your virtual machine.

=== 2 possibilities (at least) for the host interface IP address: ===

==== No DHCP server ====
If you have no dhcp server serving the 192.168.1.0 range, you will need to assign an IP address in the 192.168.1.0 range to your virtual machine once it is started.
{{{
sudo ifconfig eth0 192.168.1.253
}}}

It will be necessary to add 192.168.1.254 as a default route as well
{{{
sudo route add default gw 192.168.1.254
}}}

If you want to make it permanent in you virtual machine, edit /etc/network/interfaces of your virtual machine.
{{{
auto eth0
iface eth0 inet static
address 192.168.1.253
netmask 255.255.255.0
gateway 192.168.1.254
}}}

==== DHCP server ====
You have a dhcp server serving on the 192.168.1.0 range
either locally (laptop):
make sure the gateway given by dhcp is the ip of your bridge br0

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
----
CategoryNetworking
Describe NonExistentHelpPage here

Describe NonExistentHelpPage here

NonExistentHelpPage (last edited 2008-08-06 16:25:19 by localhost)