On Mon, 12 Sep 2016 21:14:15 +0100
Andrew Wood <andrewjamesw...@ymail.com> wrote:

> Im (slowly) trying to setup bridging and TAP interfaces to use with QEMU 
> so each VM can have a 'real' IP on the network rather than NAT.
> 
> 
> I now have a bridge setup (br1) using eth1 which Ive done in 
> /etc/network/interfaces with:
> 
> auto eth1
> auto br1
> iface br1 inet dhcp
>          bridge_ports eth1
>          bridge_stp off
>          bridge_fd 0
>          bridge_maxwait 0
> 
> 
> However I cannot work out how to add TAP interfaces to this bridge using 
> that file. Currently I have to do it with the tunctl & brctl commands in 
> a separate script.
> 
> 
> It is possible to do it in /etc/network/interfaces ?
> 
> Thanks
> Andrew
> 

You might find something in here useful. How I did it with my 500-line script, 
kvm-go.:

-----auto GREEN
allow-hotplug GREEN
iface GREEN inet manual
  bridge_ports eth1 regex tapGN.*
  bridge_maxwait 0
  post-up brctl setfd GREEN 0-----

The salient part is 'regex tapGN.*', etc.

(I actually use four bridges--GREEN/ORANGE/PURPLE/RED--because I build and test 
the Smoothwall Express firewall. One of them has no connection to the outside 
world (no slave NIC). In my case, taps for each bridge have unique and 
identifiable names (my script does this automatically). This is required if you 
should 'ifdown RED; ifup RED'; you want the tap devices reconnected.)

If you have only one bridge, you mightn't need to give the taps unique names 
and can use 'regex tap.*' to reconnect all taps to the bridge if it is bounced. 
But your mileage may vary depending on any VPNs you may use.

I also have a set of scripts in /etc/network that handle the up-down bits. 
Examples for my GREEN bridge:

Up:
-----
#! /bin/bash

chgrp netdev /dev/net/tun
/sbin/brctl addif GREEN $1
ip link set dev $1 up
-----

Down:
-----
#! /bin/bash

ip link set dev $1 down
/sbin/brctl delif GREEN $1
-----

(Yeah, yeah, I know. I should use ip() for bridge control. But debian's ip() 
hasn't been quite new enough.)

And a GREEN example of qemu options for those scripts:
-----
# netIF is either virtio or e1000
# tapGREEN is 'tapGN$tapID'
# tapID is the MAC addr (sans colons) that the script generated for that VM's 
GREEN NIC

NIC1="-net nic,vlan=1,macaddr=$macGREEN,model=${netIF} -net 
tap,vlan=1,ifname=$tapGREEN,script=/etc/network/qemuGREENup,downscript=/etc/network/qemuGREENdown"
-----

I also assign explicitly coded MAC addresses to the virtual NICs so I know 
which VM is being addressed in any particular packet.

I can't find it now, but I also have an init script that starts VMs marked 
'AUTOSTART' and stops them, if running, on shutdown.

Reply via email to