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.
20 # Fonction de mise en place du pont
27 set $(/sbin/ifconfig | grep $INTERFACE_LAN) >/dev/null
29 echo "Interface réseau $IF_HOTE non trouvée."
33 echo "Using the interface" $INTERFACE_LAN
36 echo "Starting the udev ..."
38 #Loding the tun/tap model
39 echo "Loading the tun module ..."
41 set $(lsmod | grep tun) >/dev/null
43 echo "Module tun/tap not activated"
48 #Giving acces in Read/Write to the tun module
49 echo "Granting the Read/Write acces to the tun module..."
50 chmod 666 /dev/net/tun
53 ##Get The BROADCAST ip @
54 set $(/sbin/ip addr show $INTERFACE_LAN | grep inet) >/dev/null 2>&1
60 #Getting the GATEWAY IP @
61 set $(netstat -rn | grep UG ) >/dev/null 2>&1
68 set $(ifconfig $INTERFACE_LAN 2> /dev/null | grep "inet addr:" | \
69 sed -e "s/.*addr:\([^ ]*\).*/\1/")
75 ##Getting the Netmask address
76 set $(ifconfig $INTERFACE_LAN 2> /dev/null | grep "inet addr:" | \
77 sed -e "s/.*Mask:\([^ ]*\).*/\1/")
83 # Création et paramétrage du pont
84 echo "Configure $INTERFACE_BRIDGE bridge..."
85 /usr/sbin/brctl addbr $INTERFACE_BRIDGE
86 #/usr/sbin/brctl stp $INTERFACE_BRIDGE yes
87 /usr/sbin/brctl addif $INTERFACE_BRIDGE $INTERFACE_LAN
88 echo "Activating promiscuous mode $INTERFACE_LAN..."
89 /sbin/ifconfig $INTERFACE_LAN 0.0.0.0 promisc up
91 echo "IP address on $INTERFACE_BRIDGE..."
93 /sbin/ifconfig $INTERFACE_BRIDGE $IP_HOST broadcast $IP_BROADCAST netmask $IP_NETMASK up
96 #Reconfigure the Bridge IP @ in the host machine
97 echo "Configuring the IP Gateway @:" $IP_GATEWAY
98 route add default gw $IP_GATEWAY
101 #wipe the host firewall otherwise the guest qemu can't acces to the LAN
102 echo "Wiping the firewall..."
105 #preparing the hard disk image for qemu install
106 if [ -e "hda_5.raw" ];then
109 echo "Creating hard disk for Qemu install..."
113 set $(qemu-img create $local_path/hda_5.raw 5G) >/dev/null
115 echo "Can't Create disk image..."
124 #Adding a new interface to the bridge
126 /sbin/ifconfig $1 0.0.0.0 promisc up
127 /usr/sbin/brctl addif $INTERFACE_BRIDGE $1
131 #Stop the actual bridged network and Restore the original network
136 TESTPONT=$(/sbin/ifconfig | grep $INTERFACE_BRIDGE)
137 if [ -z "$TESTPONT" ]; then
138 echo "Attention : pont réseau non trouvé. Vérifier la config réseau ..."
141 /usr/sbin/brctl delif $INTERFACE_BRIDGE $INTERFACE_LAN
142 /sbin/ifconfig $INTERFACE_BRIDGE down
143 /usr/sbin/brctl delbr $INTERFACE_BRIDGE
144 /sbin/service network restart
159 echo $"Use: env-qemu {start|add|stop} [interface]"