#!/bin/bash -x # id of the user running qemu (kvm). Make sure you change it appropriately. USERID=1000 # number of TUN/TAP devices to setup NUM_OF_DEVICES=1 case $1 in start) modprobe tun /etc/init.d/vtun start chmod a+rw /dev/net/tun echo -n "Setting up bridge device br0" brctl addbr br0 ifconfig br0 192.168.99.1 netmask 255.255.255.0 up for ((i=0; i < NUM_OF_DEVICES ; i++)); do echo -n "Setting up " tunctl -b -u $USERID -t qtap$i brctl addif br0 qtap$i ifconfig qtap$i up 0.0.0.0 promisc done ;; stop) for ((i=0; i < NUM_OF_DEVICES ; i++)); do ifconfig qtap$i down brctl delif br0 qtap$i tunctl -d qtap$i done ifconfig br0 down brctl delbr br0 /etc/init.d/vtun stop ;; *) echo "Usage: $(basename $0) (start|stop)" ;; esac