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.
21 # Fonction de mise en place du pont
23 #if we have already configured the same host_box no need to do it again
24 set $(/sbin/ifconfig | grep $INTERFACE_BRIDGE) >/dev/null
26 echo "Interface bridge $INTERFACE_BRIDGE already exist."
33 set $(/sbin/ifconfig | grep $INTERFACE_LAN) >/dev/null
35 echo "Interface réseau $IF_HOTE non trouvée."
39 echo "Using the interface" $INTERFACE_LAN
42 echo "Starting the udev ..."
44 echo "Starting the kqemu patch module ..."
46 #Loding the tun/tap model
47 echo "Loading the kqemu patch module ..."
49 #Loding the tun/tap model
50 echo "Loading the tun module ..."
52 set $(lsmod | grep tun) >/dev/null
54 echo "Module tun/tap not activated"
59 #Giving acces in Read/Write to the tun module
60 echo "Granting the Read/Write acces to the tun module..."
61 chmod 666 /dev/net/tun
64 ##Get The BROADCAST ip @
65 set $(/sbin/ip addr show $INTERFACE_LAN | grep inet) >/dev/null 2>&1
71 #Getting the GATEWAY IP @
72 set $(netstat -rn | grep UG ) >/dev/null 2>&1
79 set $(ifconfig $INTERFACE_LAN 2> /dev/null | grep "inet addr:" | \
80 sed -e "s/.*addr:\([^ ]*\).*/\1/")
86 ##Getting the Netmask address
87 set $(ifconfig $INTERFACE_LAN 2> /dev/null | grep "inet addr:" | \
88 sed -e "s/.*Mask:\([^ ]*\).*/\1/")
93 #check if the module brctl is there
94 if [ ! -e $brctl ] ; then
95 echo "Module Brctl '/usr/sbin/brctl' is not found"
98 # Création et paramétrage du pont
99 echo "Configure $INTERFACE_BRIDGE bridge..."
100 $brctl addbr $INTERFACE_BRIDGE
101 #/usr/sbin/brctl stp $INTERFACE_BRIDGE yes
102 $brctl addif $INTERFACE_BRIDGE $INTERFACE_LAN
103 echo "Activating promiscuous mode $INTERFACE_LAN..."
104 /sbin/ifconfig $INTERFACE_LAN 0.0.0.0 promisc up
106 echo "IP address on $INTERFACE_BRIDGE..."
108 /sbin/ifconfig $INTERFACE_BRIDGE $IP_HOST broadcast $IP_BROADCAST netmask $IP_NETMASK up
111 #Reconfigure the Bridge IP @ in the host machine
112 echo "Configuring the IP Gateway @:" $IP_GATEWAY
113 route add default gw $IP_GATEWAY
116 #wipe the host firewall otherwise the guest qemu can't acces to the LAN
117 echo "Wiping the firewall..."
123 #Adding a new interface to the bridge
125 /sbin/ifconfig $1 0.0.0.0 promisc up
126 /usr/sbin/brctl addif $INTERFACE_BRIDGE $1
130 #Stop the actual bridged network and Restore the original network
135 TESTPONT=$(/sbin/ifconfig | grep $INTERFACE_BRIDGE)
136 if [ -z "$TESTPONT" ]; then
137 echo "Attention : pont réseau non trouvé. Vérifier la config réseau ..."
140 #check if the module brctl is there
141 if [ ! -e $brctl ] ;then
142 echo "Module Brctl '/usr/sbin/brctl' is not found"
145 $brctl delif $INTERFACE_BRIDGE $INTERFACE_LAN
146 /sbin/ifconfig $INTERFACE_BRIDGE down
147 $brctl delbr $INTERFACE_BRIDGE
148 /sbin/service network restart
163 echo $"Use: env-qemu {start|add|stop} [interface]"