4 # Establishment of a runtime environment for a
5 # virtual machine under QEMU, This script permits
6 # to the virtual machine to share the
7 # network connection with a host machine under FC6.
18 # Fonction de mise en place du pont
25 set $(/sbin/ifconfig | grep $INTERFACE_LAN) >/dev/null
27 echo "Interface réseau $IF_HOTE non trouvée."
31 echo "Using the interface" $INTERFACE_LAN
34 echo "Starting the udev ..."
36 #Loding the tun/tap model
37 echo "Loading the tun module ..."
39 set $(lsmod | grep tun) >/dev/null
41 echo "Module tun/tap not activated"
46 #Giving acces in Read/Write to the tun module
47 echo "Granting the Read/Write acces to the tun module..."
48 chmod 666 /dev/net/tun
51 ##Get The BROADCAST ip @
52 set $(/sbin/ip addr show $INTERFACE_LAN | grep inet) >/dev/null 2>&1
58 #Getting the GATEWAY IP @
59 set $(netstat -rn | grep UG ) >/dev/null 2>&1
66 set $(ifconfig $INTERFACE_LAN 2> /dev/null | grep "inet addr:" | \
67 sed -e "s/.*addr:\([^ ]*\).*/\1/")
73 ##Getting the Netmask address
74 set $(ifconfig $INTERFACE_LAN 2> /dev/null | grep "inet addr:" | \
75 sed -e "s/.*Mask:\([^ ]*\).*/\1/")
81 # Création et paramétrage du pont
82 echo "Configure $INTERFACE_BRIDGE bridge..."
83 /usr/sbin/brctl addbr $INTERFACE_BRIDGE
84 #/usr/sbin/brctl stp $INTERFACE_BRIDGE yes
85 /usr/sbin/brctl addif $INTERFACE_BRIDGE $INTERFACE_LAN
86 echo "Activating promiscuous mode $INTERFACE_LAN..."
87 /sbin/ifconfig $INTERFACE_LAN 0.0.0.0 promisc up
89 echo "IP address on $INTERFACE_BRIDGE..."
91 /sbin/ifconfig $INTERFACE_BRIDGE $IP_HOST broadcast $IP_BROADCAST netmask $IP_NETMASK up
94 #Reconfigure the Bridge IP @ in the host machine
95 echo "Configuring the IP Gateway @:" $IP_GATEWAY
96 route add default gw $IP_GATEWAY
99 #wipe the host firewall otherwise the guest qemu can't acces to the LAN
100 echo "Wiping the firewall..."
103 #preparing the hard disk image for qemu install
104 if [ -e "hda_5.raw" ];then
107 echo "Creating hard disk for Qemu install..."
108 set $(qemu-img create hda_5.raw 5G) >/dev/null
110 echo "Can't Create disk image..."
119 #Adding a new interface to the bridge
121 /sbin/ifconfig $1 0.0.0.0 promisc up
122 /usr/sbin/brctl addif $INTERFACE_BRIDGE $1
126 #Stop the actual bridged network and Restore the original network
131 TESTPONT=$(/sbin/ifconfig | grep $INTERFACE_BRIDGE)
132 if [ -z "$TESTPONT" ]; then
133 echo "Attention : pont réseau non trouvé. Vérifier la config réseau ..."
136 /usr/sbin/brctl delif $INTERFACE_BRIDGE $INTERFACE_LAN
137 /sbin/ifconfig $INTERFACE_BRIDGE down
138 /usr/sbin/brctl delbr $INTERFACE_BRIDGE
139 /sbin/service network restart
154 echo $"Use: env-qemu {start|add|stop} [interface]"