Our Computer Notes

Recent site activity

Virtualization‎ > ‎VirtualBox‎ > ‎

Configure Internet with bridge for VirtualBox (Ubuntu 8.10)

  • Create a file for the following script and edit where is marked with < >:
    Code:
    ########### bridge_virtualbox.sh ##############

    #!/bin/sh

    # create a tap1 (network interface for Virtual Box)
    tunctl -t tap1 -u <host user>
    ip link set up dev tap1

    # create the bridge
    brctl addbr br0
    brctl addif br0 tap1

    # set the IP address and routing
    ip link set up dev br0
    ip addr add 10.1.1.1/24 dev br0
    ip route add 10.1.1.0/24 dev br0

    ###### NAT Rules ######

    # set the internal interface
    INTIF="br0"

    # set the external interface
    EXTIF="<Network interface. Ex: eth0>"

    # enable routing on Linux
    echo 1 > /proc/sys/net/ipv4/ip_forward

    # clear existing iptable rules, set a default policy
    iptables -P INPUT ACCEPT
    iptables -F INPUT
    iptables -P OUTPUT ACCEPT
    iptables -F OUTPUT
    iptables -P FORWARD DROP
    iptables -F FORWARD
    iptables -t nat -F

    # set forwarding and nat rules
    iptables -A FORWARD -i $EXTIF -o $INTIF -j ACCEPT
    iptables -A FORWARD -i $INTIF -o $EXTIF -j ACCEPT
    iptables -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE

    ########### bridge_virtualbox.sh ##############
  • Install a dhcp server:
    # sudo apt-get install dhcp3-server
  • Edit the file /etc/default/dhcp3-server  and change the last line to:
    INTERFACES="br0"
  • Edit the file /etc/dhcp3/dhcpd.conf and change its contents to:
    ddns-update-style interim;
    ignore client-updates;

    subnet 10.1.1.0 netmask 255.255.255.0 {

    option routers 10.1.1.1;
    option subnet-mask 255.255.255.0;

    option domain-name-servers <DNS server ip address. Look at ip in /etc/resolv.conf>;

    range dynamic-bootp 10.1.1.2 10.1.1.254;
    default-lease-time 21600;
    max-lease-time 43200;
    }
  • Run the script and start the dhcp server:
    # sudo sh /bridge_virtualbox.sh
    # sudo /etc/init.d/dhcp3-server start
  • Configure a network adapter at the virtual machine settings:

  • Start the guest virtual machine in VirtualBox