qemu-ifup and qemu-ifdown network configuration scripts

Virtual Machines

These two scripts are called when you start a qemu or kvm virtual machine.

QEMU networking pre-configure script

#!/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

QEMU networking pre-configure script

#!/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

OpenVPN

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.

Posted by admica   @   8 April 2010

Related Posts

Like this post? Share it!

Digg Twitter StumbleUpon Delicious Technorati Facebook RSS

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Name

Email

Website

Previous Post
« Opt out of Online Ad Networks invading your privacy
Next Post
Modern Warfare 2 Console Commands »
Powered by Wordpress   |   Lunated designed by ZenVerse