These two scripts are called when you start a qemu or kvm virtual machine.
#!/bin/sh
bridge=bridge0
iface=$1
openvpn=`which openvpn`
brctl=`which brctl`
ifconfig=`which ifconfig`
user=`whoami`
echo "Executing /etc/qemu-ifup"
echo "Bringing up iface: $1 and adding it to bridge: ${bridge}"
# Create a virtual tunnel interface, add it to the bridge, bring it up
if [ $user == root ]; then
#${openvpn} --mktun --dev ${iface}
${brctl} addif ${bridge} ${iface}
${ifconfig} ${iface} 0.0.0.0 promisc up
else
#sudo ${openvpn} --mktun --dev ${iface}
sudo ${brctl} addif ${bridge} ${iface}
sudo ${ifconfig} ${iface} 0.0.0.0 promisc up
fi
sleep 1
#!/bin/sh
bridge=bridge0
iface=$1
openvpn=`which openvpn`
brctl=`which brctl`
ifconfig=`which ifconfig`
user=`whoami`
echo "Executing /etc/qemu-ifdown"
echo "Bringing down iface: $1 and removing it from bridge: ${bridge}"
# down the interface, remove it from the bridge, destroy virtual tunnel
if [ $user == root ]; then
${ifconfig} ${iface} down
${brctl} delif ${bridge} ${iface}
else
sudo ${ifconfig} ${iface} down
sudo ${brctl} delif ${bridge} ${iface}
fi
I removed the openvpn –mktun and –rmtun commands because qemu handles it for you. You may need to run this as root out of the box unless you fix your networking to allow regular users to access the tunnel.