#下載VBOX
# http://www.virtualbox.org/wiki/Linux_Downloads
http://download.virtualbox.org/virtualbox/2.2.2/virtualbox-2.2_2.2.2-46594_Ubuntu_jaunty_i386.deb
#安裝網路橋接原件
sudo apt-get install bridge-utils uml-utilities
#安裝常用套件
sudo apt-get install wget cron openssh-server portmap nfs-common vsftpd gpm
#加入使用者到vboxuser 群組
usermod -G vboxusers -a user name
======== vboxbridge.sh
#!/bin/sh
#/usr/bin/gksudo /root/vboxbridge eth0 tap1 start
#/usr/bin/gksudo /root/vboxbridge eth0 tap2 start
#/usr/bin/gksudo /root/vboxbridge eth0 tap3 start
#Put your username here
USERNAME= user name
TAP_INTERFACE="$2"
HOST_INTERFACE="$1"
BRIDGE_INTERFACE="br0"
TAP_COUNT=`ifconfig | grep -c tap`
case "$3" in
start)
if [ `ifconfig | grep -c $TAP_INTERFACE` = 0 ]; then
#create the bridge if it does not exist
if [ `ifconfig | grep -c $BRIDGE_INTERFACE` = 0 ]; then
brctl addbr $BRIDGE_INTERFACE
#check if we are using DHCP and retrieve configuration if IP is static
if [ `ps ax | grep -c "dhclient $HOST_INTERFACE"` = 2 ]; then
ifconfig $HOST_INTERFACE 0.0.0.0 promisc
brctl addif $BRIDGE_INTERFACE $HOST_INTERFACE
dhclient $BRIDGE_INTERFACE
else
IP_ADDRESS=`ifconfig $HOST_INTERFACE | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
BROADCAST_ADDRESS=`ifconfig $HOST_INTERFACE | grep 'inet addr:' | cut -d: -f3 | awk '{ print $1}'`
SUBNET_MASK=`ifconfig $HOST_INTERFACE | grep 'inet addr:' | cut -d: -f4 | awk '{ print $1}'`
DEFAULT_GATEWAY=`route -n |tail -n1|cut -d' ' -f10`
ifconfig $HOST_INTERFACE 0.0.0.0 promisc
brctl addif $BRIDGE_INTERFACE $HOST_INTERFACE
ifconfig $BRIDGE_INTERFACE $IP_ADDRESS netmask $SUBNET_MASK broadcast $BROADCAST_ADDRESS
route add default gw $DEFAULT_GATEWAY
fi
fi
#add tap interface to bridge
tunctl -t $TAP_INTERFACE -u $USERNAME
brctl addif $BRIDGE_INTERFACE $TAP_INTERFACE
ifconfig $TAP_INTERFACE up
chmod 0666 /dev/net/tun
else
echo "Interface $TAP_INTERFACE already configured"
fi
;;
stop)
if [ `ifconfig | grep -c $TAP_INTERFACE` = 0 ]; then
echo "Interface $TAP_INTERFACE does no exist"
else
#shut down tap interface and remove it from bridge
ifconfig $TAP_INTERFACE down
brctl delif $BRIDGE_INTERFACE $TAP_INTERFACE
tunctl -d $TAP_INTERFACE
#we remove the bridge if this was the last tap interface
if [ $TAP_COUNT = 1 ]; then
brctl delif $BRIDGE_INTERFACE $HOST_INTERFACE
ifconfig $HOST_INTERFACE 0.0.0.0 -promisc
#check if we are using DHCP and retrieve configuration if IP is static
if [ `ps ax | grep -c "dhclient $BRIDGE_INTERFACE"` = 2 ]; then
ifconfig $BRIDGE_INTERFACE down
brctl delbr $BRIDGE_INTERFACE
dhclient $HOST_INTERFACE
else
IP_ADDRESS=`ifconfig $BRIDGE_INTERFACE | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
BROADCAST_ADDRESS=`ifconfig $BRIDGE_INTERFACE | grep 'inet addr:' | cut -d: -f3 | awk '{ print $1}'`
SUBNET_MASK=`ifconfig $BRIDGE_INTERFACE | grep 'inet addr:' | cut -d: -f4 | awk '{ print $1}'`
DEFAULT_GATEWAY=`route -n |tail -n1|cut -d' ' -f10`
ifconfig $BRIDGE_INTERFACE down
brctl delbr $BRIDGE_INTERFACE
ifconfig $HOST_INTERFACE $IP_ADDRESS netmask $SUBNET_MASK broadcast $BROADCAST_ADDRESS
route add default gw $DEFAULT_GATEWAY
fi
fi
fi
;;
*)
echo "Usage: vboxbridge hostinterface tapinterface {start|stop}" >&2
exit 1
;;
esac
==========
2009年5月12日 星期二
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言