No-hassle tun/tap 'bridged' networking with Linux host

using QEMU howto's - how to install a guest OS under QEMU, etc - people are more then welcome to submit any documents they written and share them with the community

No-hassle tun/tap 'bridged' networking with Linux host

Postby Guest on Fri Jul 29, 2005 6:53 pm

To make networking Linux-hosted VMs with tun/tap easier, this is what I did:

First, I changed my hosts's networking configuration. Instead of using eth0 directly, I changed the bootup scripts to build a bridge with only one interface (eth0):
Code: Select all
btctl addbr br0
ifconfig eth0 up
brctl addif br0 eth0
Then I configured br0 in the same way I previously configured eth0 (in my case, 'dhcpcd br0', but you might use dhclient, pump, or set a static IP).

Also, make sure you have the tun/tap module loaded on the host, if applicable ('modprobe tun').

That done on the host, I altered the /etc/qemu-ifup script as follows:
Code: Select all
ifconfig $1 up
brctl addif br0 $1
Now each VM I bring up will be on the same subnet as the host, just as a physical machine would be, with its own IP and full connectivity incoming and outgoing. This is the equivalent of 'Bridged' mode in VMWare.
Guest
 

Postby Eulex on Mon Aug 01, 2005 6:35 pm

The commands btctl and brctl are specific to whatever distro you are using.
Eulex
 

Postby Guest on Wed Aug 03, 2005 6:05 pm

Dang, btctl is a type. It should be brctl throughout.

brctl is the standard userspace bridge tool, you can download and compile it from source if your distro does not have it.
Guest
 

brctl

Postby Rakeleer on Sat Aug 06, 2005 8:56 pm

For brctl in Debian or Ubtuntu -

apt-get install bridge-utils
Rakeleer
 

Postby rhauff on Tue Sep 13, 2005 1:14 pm

Is there something more to getting tun setup other than modprobe tun?
What needs to be done so the host knows $1 is /dev/tun? Thanks!
rhauff
 
Posts: 1
Joined: Wed Sep 07, 2005 6:28 pm

Postby auwooo on Thu Sep 29, 2005 12:26 pm

hellow how to do bridge networking on any other guest os ?? other than linux ?
auwooo
 
Posts: 4
Joined: Tue Sep 27, 2005 12:39 pm

Postby pcweirdo on Sat Oct 01, 2005 7:04 am

auwooo wrote:hellow how to do bridge networking on any other guest os ?? other than linux ?


auwooo, the previously posted commands are to be run on the host OS. It doesn't matter what OS the guest is running.

-pcweirdo.
Maybe in my virtual machine girls will think I'm sexy?
pcweirdo
 
Posts: 1
Joined: Sat Oct 01, 2005 6:57 am
Location: Melbourne, Australia

Good Info

Postby tkocou on Sun Oct 02, 2005 4:40 pm

A simple Thank You for taking the time to post this How To.
tkocou
 
Posts: 2
Joined: Sun Oct 02, 2005 4:34 pm

Postby superfly on Tue Nov 29, 2005 11:51 am

which boot script did you edit where you added those lines to create a bridge?
superfly
 
Posts: 3
Joined: Tue Nov 29, 2005 11:44 am
Location: Cape Town, South Africa

Postby ahmahmahm on Tue Nov 29, 2005 3:23 pm

I second superfly - this looks really useful, but I don't know where those 'network startup' lines should go.

thanks Andy
ahmahmahm
 
Posts: 8
Joined: Tue Oct 25, 2005 5:40 pm

Re: No-hassle tun/tap 'bridged' networking with Linux host

Postby ish on Tue Nov 29, 2005 4:23 pm

Anonymous wrote:To make networking Linux-hosted VMs with tun/tap easier, this is what I did:

First, I changed my hosts's networking configuration. Instead of using eth0 directly, I changed the bootup scripts to build a bridge with only one interface (eth0):
Code: Select all
btctl addbr br0
ifconfig eth0 up
brctl addif br0 eth0
Then I configured br0 in the same way I previously configured eth0 (in my case, 'dhcpcd br0', but you might use dhclient, pump, or set a static IP).

Also, make sure you have the tun/tap module loaded on the host, if applicable ('modprobe tun').

That done on the host, I altered the /etc/qemu-ifup script as follows:
Code: Select all
ifconfig $1 up
brctl addif br0 $1
Now each VM I bring up will be on the same subnet as the host, just as a physical machine would be, with its own IP and full connectivity incoming and outgoing. This is the equivalent of 'Bridged' mode in VMWare.


A more detalied info on how to set up tun/tap device and the name of the scripts involved will be helpful to users not very familiar with Linux networking.

-ish
ish
helper
 
Posts: 35
Joined: Mon Oct 10, 2005 3:49 am

Bridging script (for Debian)

Postby oliver on Wed Nov 30, 2005 12:19 am

Here's a script that sets up a network bridge on a Debian machine. You can find it at http://wolfpackally.wo.funpic.de/qemu/setupbr.sh .

If run as "setupbr.sh start" (by the root user), it replaces the network interface eth0 by a bridged interface which is named eth0 as well. This means that after ca. 5 seconds, network should work as before, only that now you can connect Qemu's tap device to the bridge.
With "setupbr.sh stop" the bridge is removed and the old network setup is restored.
If your network interface is not eth0, replace that value in the "script header". Also, I have no idea what this script will do if you're not on a LAN, and eg. specify your modem interface instead of eth0 ...

The Debian-specific part is that the script calls "ifup" and "ifdown". These functions setup a given network interface or deconfigure it. I have no idea how this is usually done on other distros...

To use the script, either install it as an rc-Init-script, or run it manually whenever you want to start Qemu for the first time (that's what I do).

To use Qemu with this bridge, use this script: http://wolfpackally.wo.funpic.de/qemu/addtobridge.sh
Specify it with the -n parameter to Qemu. Note that you should edit this script if your network interface is not called eth0. Also, you need to edit /etc/sudoers to allow your normal user account to execute ifconfig and brctl (or you run Qemu as root - but that's not recommended).

Oliver
oliver
helper
 
Posts: 166
Joined: Sat Nov 12, 2005 3:00 pm

Postby superfly on Thu Dec 01, 2005 2:00 pm

hey oliver, thanks for the script. unfortuantely it doesn't seem to work. this is what i get when i try to run that script...

Code: Select all
mongoose:/home/raoul/Downloads # ./setupbr.sh start
Creating bridge br0 with eth0
    eth0      device: Silicon Integrated Systems [SiS] SiS900 PCI Fast Ethernet (rev 91)
    eth0      configuration: eth-id-00:0c:6e:6b:d9:68
Error: Can't open configuration file `/etc/iftab': No such file or directory
device eth0 already exists; can't create bridge with the same name
set stp status failed: Operation not supported
set forward delay failed: Operation not supported
interface br0eth0 does not exist!
bridge name     bridge id               STP enabled     interfaces
br0eth0: unknown interface: No such device
Configuring bridge br0
    eth0      device: Silicon Integrated Systems [SiS] SiS900 PCI Fast Ethernet (rev 91)
    eth0      configuration: eth-id-00:0c:6e:6b:d9:68
Starting DHCP Client Daemon on eth0... . . . . . no IP address yet... backgrounding.
ERROR: Warning: Could not set up default route via interface
       Command ip route replace to default via 192.168.0.101 returned:
       . RTNETLINK answers: Network is unreachable
       Configuration line: default 192.168.0.101 - -
       This needs NOT to be AN ERROR if you set up multiple interfaces.
       See man 5 routes how to avoid this warning.


i'm running suse 10.0 (okay, granted it's not debian),
any ideas oliver?
superfly
 
Posts: 3
Joined: Tue Nov 29, 2005 11:44 am
Location: Cape Town, South Africa

Postby oliver on Thu Dec 01, 2005 9:13 pm

Oh right, forgot to mention that apparently ifrename requires that the file /etc/iftab exists... Just do "touch /etc/iftab" as root to create the file. Then ifrename should work.

Oliver
oliver
helper
 
Posts: 166
Joined: Sat Nov 12, 2005 3:00 pm

Postby superfly on Fri Dec 02, 2005 2:16 pm

did that, but i now get this:
Code: Select all
mongoose:/home/raoul/Downloads # ./setupbr.sh start
Creating bridge br0 with eth0
    eth0      device: Silicon Integrated Systems [SiS] SiS900 PCI Fast Ethernet (rev 91)
    eth0      configuration: eth-id-00:0c:6e:6b:d9:68
br0eth0
bridge name     bridge id               STP enabled     interfaces
eth0            8000.000c6e6bd968       no              br0eth0
Configuring bridge br0
    eth0
ERROR: No configuration found for eth0


not sure what to do now. as far as i can see, it doesn't like eth0 as the name of both the bridge and the network interface... or should it actually be looking for "br0eth0" rather than "eth0"?
superfly
 
Posts: 3
Joined: Tue Nov 29, 2005 11:44 am
Location: Cape Town, South Africa

Next

Return to HOWTOs

Who is online

Users browsing this forum: No registered users and 1 guest