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
22 #if we have already configured the same host_box no need to do it again
23 set $(/sbin/ifconfig | grep $INTERFACE_BRIDGE) >/dev/null
25 echo "Interface bridge $INTERFACE_BRIDGE already exist."
32 set $(/sbin/ifconfig | grep $INTERFACE_LAN) >/dev/null
34 echo "Interface réseau $IF_HOTE non trouvée."
38 echo "Using the interface" $INTERFACE_LAN
41 echo "Starting the udev ..."
43 echo "Starting the kqemu patch module ..."
45 #Loding the tun/tap model
46 echo "Loading the kqemu patch module ..."
48 #Loding the tun/tap model
49 echo "Loading the tun module ..."
51 set $(lsmod | grep tun) >/dev/null
53 echo "Module tun/tap not activated"
58 #Giving acces in Read/Write to the tun module
59 echo "Granting the Read/Write acces to the tun module..."
60 chmod 666 /dev/net/tun
63 ##Get The BROADCAST ip @
64 set $(/sbin/ip addr show $INTERFACE_LAN | grep inet) >/dev/null 2>&1
70 #Getting the GATEWAY IP @
71 set $(netstat -rn | grep UG ) >/dev/null 2>&1
78 set $(ifconfig $INTERFACE_LAN 2> /dev/null | grep "inet addr:" | \
79 sed -e "s/.*addr:\([^ ]*\).*/\1/")
85 ##Getting the Netmask address
86 set $(ifconfig $INTERFACE_LAN 2> /dev/null | grep "inet addr:" | \
87 sed -e "s/.*Mask:\([^ ]*\).*/\1/")
93 # Création et paramétrage du pont
94 echo "Configure $INTERFACE_BRIDGE bridge..."
95 /usr/sbin/brctl addbr $INTERFACE_BRIDGE
96 #/usr/sbin/brctl stp $INTERFACE_BRIDGE yes
97 /usr/sbin/brctl addif $INTERFACE_BRIDGE $INTERFACE_LAN
98 echo "Activating promiscuous mode $INTERFACE_LAN..."
99 /sbin/ifconfig $INTERFACE_LAN 0.0.0.0 promisc up
101 echo "IP address on $INTERFACE_BRIDGE..."
103 /sbin/ifconfig $INTERFACE_BRIDGE $IP_HOST broadcast $IP_BROADCAST netmask $IP_NETMASK up
106 #Reconfigure the Bridge IP @ in the host machine
107 echo "Configuring the IP Gateway @:" $IP_GATEWAY
108 route add default gw $IP_GATEWAY
111 #wipe the host firewall otherwise the guest qemu can't acces to the LAN
112 echo "Wiping the firewall..."
118 #Adding a new interface to the bridge
120 /sbin/ifconfig $1 0.0.0.0 promisc up
121 /usr/sbin/brctl addif $INTERFACE_BRIDGE $1
125 #Stop the actual bridged network and Restore the original network
130 TESTPONT=$(/sbin/ifconfig | grep $INTERFACE_BRIDGE)
131 if [ -z "$TESTPONT" ]; then
132 echo "Attention : pont réseau non trouvé. Vérifier la config réseau ..."
135 /usr/sbin/brctl delif $INTERFACE_BRIDGE $INTERFACE_LAN
136 /sbin/ifconfig $INTERFACE_BRIDGE down
137 /usr/sbin/brctl delbr $INTERFACE_BRIDGE
138 /sbin/service network restart
153 echo $"Use: env-qemu {start|add|stop} [interface]"