#!/bin/bash # bridge_virtualbox # # Make all to Host Interface (bridge mode) works. # Get up the virtual machine with HeadLess mode. #################################################### ################################## #TODO: make any interface works ################################## #if [ "$1" ];then # echo "utilizando $1" # IFACE=$1 #else # echo "utilizando eth0" # IFACE=eth0 #fi ################################## #general variables DIR="/home/kessia/scripts" #change that to your path VBOX_DIR="/opt/virtualbox" VM="none" VMS=`VBoxManage list vms|grep Name|grep -v UUID|awk -F: '{print $2}'` IFACE="eth0" CUR_USER=`whoami` # dont run it with root! if [ "$CUR_USER" == root ];then echo echo "Duh!" echo "Please, be a normal user to run that." echo "Don't run with root!" echo exit fi if [ "$1" ];then case "$1" in -h | --help) # some help to execute the script cat - <<-FIM Make the host IFACE network up. Turn on the [tun] module and get up the virtual [tap0] interface. Makes a bridge with fisical and the virtual network adapter. Usage: bridge_virtualbox bridge_virtualbox --help List of disponible Virtual Machines: FIM # list all VM's avaliable LD_LIBRARY_PATH=$VBOX_DIR $VBOX_DIR/VBoxManage list vms|grep Name|grep -v UUID|awk -F" " '{ print "\t"NR".",$2 }' echo ;; -*) echo "Wrong parameter!" echo "Read with carefull!" $DIR/bridge_virtualbox -h ;; *) #do the magic! # check if parameter if right for machine in $VMS;do if [ "$1" == "$machine" ];then VM=$machine break fi done if [ "$VM" != "none" ];then # make all described in: # http://even.archlinux-br.org/blog/virtualbox-configuracoes-de-rede su root -c " modprobe tun if [ ! -e /dev/net/tun ];then mkdir -p /dev/net mknod /dev/net/tun c 10 200 fi chown root.vboxusers /dev/net/tun chmod 0660 /dev/net/tun tunctl -b -t tap0 -u kessia brctl addbr br0 ifconfig $IFACE 0.0.0.0 promisc brctl addif br0 $IFACE pkill -9 dhcpcd sleep 2 dhcpcd -t 30 -h rainbows br0 brctl addif br0 tap0 ifconfig tap0 up 1>/dev/null " # get up! LD_LIBRARY_PATH=$VBOX_DIR $VBOX_DIR/VBoxHeadless -startvm "$VM" & else echo "This machine doesn't exists!" $DIR/bridge_virtualbox -h fi ;; esac else $DIR/bridge_virtualbox -h fi