Subject: Defining TAP interfaces in /etc/network/interfaces

From: Andrew Wood <[email-masked]>
Date: Mon, 12 Sep 2016 21:14:15 +0100

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

---

From: "Neal P. Murphy" <[email-masked]>
Date: Mon, 12 Sep 2016 18:23:46 -0400

On Mon, 12 Sep 2016 21:14:15 +0100

> It is possible to do it in /etc/network/interfaces ?

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.

---

From: Andrew Wood <[email-masked]>
Date: Fri, 16 Sep 2016 20:48:33 +0100

On 12/09/16 23:23, Neal P. Murphy wrote:
>
> You might find something in here useful.

On 12/09/16 21:43, Charlie Kravetz wrote:
> Change the bridge_ports to:
> 	bridge_ports eth1 tap0
>
> then add the tap lines:
>          auto tap0
>               iface tap0 inet static
>               address 192.168.??.?
>               netmask 255.255.255.0
>               tunctl_user vboxusers

On 12/09/16 21:33, Nemeth Gyorgy wrote:
> An example:
>
> http://www.shakthimaan.com/installs/debian-tun-tap-setup.html
>

Thanks all, very useful

---

From: Charlie Kravetz <[email-masked]>
Date: Mon, 12 Sep 2016 13:43:00 -0700

then add the tap lines:
        auto tap0
             iface tap0 inet static
             address 192.168.??.?
             netmask 255.255.255.0
             tunctl_user vboxusers

Change these as needed for your own setup. This works for me using
virtual box.

- -- 
Charlie Kravetz
Linux Registered User Number 425914
[http://linuxcounter.net/user/425914.html]
Never let anyone steal your DREAM.   [http://keepingdreams.com]

---

From: Nemeth Gyorgy <[email-masked]>
Date: Mon, 12 Sep 2016 22:33:50 +0200

2016-09-12 22:14 keltezéssel, Andrew Wood írta:
> 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.
>
>
> 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.
>
>
An example: