Ubuntu 7.04下Virtualbox安装及网络桥接

来源:岁月联盟 编辑:zhuzhu 时间:2007-08-20
Ubuntu 7.04下Virtualbox安装及网络桥接内容简介:一、安装 1. 下载安装包。建议下载 Deb 包。 2. 准备依赖。VirtualBox 的正常使用需要 libxalan110 和 libxerces27 这两个包。所以,你要先行安装它们,可以使用下面的指令: sudo apt-get install libxalan1

一、安装

 

1. 下载安装包。建议下载 Deb 包。

 

2. 准备依赖。VirtualBox 的正常使用需要 libxalan110 和 libxerces27 这两个包。所以,你要先行安装它们,可以使用下面的指令:

sudo apt-get install libxalan110 libxerces27

 

3. 安装编译工具及相关包。在安装过程中,要编译 VirtualBox 所用的内核模块。为此,你需要准备基本的编译工具及包,你可以使用下列指令来安装它们:

sudo apt-get install build-essential linux-headers-`uname -r`

 

4. 现在,转到所保存 VirtualBox 安装包的目录,通过下面的指令来安装它:

sudo dpkg -i VirtualBox_1.x.x_Ubuntu_feisty_i386.deb

在安装的过程中,VirtualBox 会要求你接受许可协议。另外,安装程序也会创建 vboxusers 用户组,并编译所需的内核模块。

5. 现在,你还不能启动 VirtualBox,因为你的当前用户还不属于 vboxusers 用户组。你可以使用下面的指令来将当前的用户(请使用你的用户名代替指令中的“youruser”)添加到 vboxusers 用户组中:

sudo adduser youruser vboxusers

 

virtualbox 屏幕下移问题:

如果虚拟机的分辨率接近x的分辨率而导致部分界面在x边沿时,全屏后原来窗口管理器 title 的地方变为黑色条状区域,屏幕下移,windows的开始菜单显示在下一个桌面。

解决方法:全屏前把分辨率调小,全屏后右键把显示器分辨率调到同x一致,这样就不会有屏幕偏移。

 

二、桥接网络配置

 

一般而言,安装完VirtualBox设定网路时选择默认的NAT模式,Guest就可顺利联网了,但是这种方式比较死板,要作更有弹性的变化,应该采用桥接模式(Bridged),这里的桥接模式就如同VMware中的Bridged模式,Host与Guest在局域网(LAN)中的地位是相等的。

 

参考 virtualbox 安装后放在 VirtualBox 目录中的用户手册文件 UserManual.pdf 配置如下:

 

1. 在基于 Debian 和 Ubuntu 的系统上,首先要安装含有建立虚拟网络设备 ( TAP interfaces ) 的工具 uml-utilities 和桥接工具 bridge-utils:

sudo apt-get install uml-utilities

sudo apt-get install bridge-utils

为了使你的虚拟机能够访问网络接口,你必须将运行虚拟主机的用户的用户名(通常是你的ubuntu登录用户名)添加到uml-net用户组(请用你的用户名替换其中的“vboxuser”):

sudo gpasswd -a vboxuser uml-net

注意:为了使改动生效,请重新启动你的电脑。

 

2. 向你的 Debian 或者 ubuntu 操作系统描述你要添加的虚拟网络设备,编辑 /etc/network/interfaces:

sudo vim /etc/network/interfaces

在打开的文件后面添加下面的内容,将虚拟网络接口命名为 "tap0",指定该接口IP配置方法为手动,并指定使用该接口的用户(请用你的用户名替换其中的 "vboxuser"):

auto tap0

iface tap0 inet manual

up ifconfig $IFACE 0.0.0.0 up

down ifconfig $IFACE down

tunctl_user vboxuser

 

3. 首次使用需要激活刚才建立的虚拟网络接口和网络桥:

sudo /sbin/ifup tap0

sudo /sbin/ifup br0

这个步骤只需要做一次,下次主机重新启动时,这个接口和桥将自动激活。

 

4. 另外还需要在 /etc/network/interfaces 中加入如下内容,建立一个名叫 "br0" 的桥,该桥的IP配置方法为通过DHCP配置,主机中的所有网络接口,也包括tap0这个虚拟网络接口,都将建立在这个桥之上:

auto br0

iface br0 inet dhcp

bridge_ports all tap0

在这里你可以根据自己的网络状况做相应的更改,你可以使网络桥使用静态 IP:

iface br0 inet static

address 192.168.1.2

netmask 255.255.255.0

network 192.168.1.0

broadcast 192.168.1.255

gateway 192.168.1.1

 

5. 让 virtualbox 使用这个虚拟网络接口,启动 virtualbox,在主界面上选中要使用刚才建立的虚拟网络接口tap0的虚拟机,点“设置”,在弹出的窗口中选“网络”,选中其中一块网卡(通常为 “网络适配器 0”),选中“启用网络适配器”,“连接到”后面选 "Host Interface",选中“接入网线”,然后在“主机网络界面名称”中填入刚才建立的虚拟网络接口的名字 "tap0",确定。同样的你也可以使用 VBoxManage 的命令行工具(将 "My VM" 换成你的虚拟机名字 ):

VBoxManage modifyvm "My VM" -hostifdev1 tap0/

 

最后,配置主机和虚拟机的网络,使主机和虚拟机在同一个网段,这样主机和虚拟机就成了局域网中地位相同的两台机器了,可以互相访问了。

 

三、撤销网络桥

 

1. 禁用网桥和虚拟网卡:

sudo /sbin/ifdown br0

sudo /sbin/ifdown tap0

2. 将前面修改的 /etc/network/interfaces 文件还原。

 

Debian 和 Ubuntu 下 virtualbox 桥接设置原文:

 

6.5.1.1 Debian and Ubuntu hosts

 

To set up a permanent host interface on a Debian or Ubuntu host, follow these steps:

 

1. On modern Debian and Ubuntu based hosts, you must first install the UserMode Linux utilities package (uml-utilities), which contains tools to create TAP interfaces, as well as the bridge utilities (bridge-utils). package. You can do this from the command line using

 

sudo apt-get install uml-utilities

sudo apt-get install bridge-utils

 

In order for VirtualBox to be able to access the interface, the user who will be running the virtual machine must be added to the group uml-net, for example with the following command (replace vboxuser with your user name):

 

sudo gpasswd -a vboxuser uml-net

 

You may have to log out and log in again for the change to take effect.

 

2. To describe the TAP interface to your Debian or Ubuntu system, add an entry to the file /etc/network/interfaces. This names the the interface and must also specify the user who will be running the virtual machine using the interface. The following sample entry creates the interface tap0 for the user vboxuser (again, replace with your user name):

 

auto tap0

iface tap0 inet manual

up ifconfig $IFACE 0.0.0.0 up

down ifconfig $IFACE down

tunctl_user vboxuser

 

You will probably want to change the entry based on your networking needs. On the host, you will find more documentation in these files:

a) /usr/share/doc/uml-utilities/README.Debian and

b) /usr/share/doc/ifupdown/examples/network-interfaces.gz.

 

3. The first time it is used, activate the new interface and the bridge with these two commands:

 

sudo /sbin/ifup tap0

sudo /sbin/ifup br0

 

This is only needed once, however; the next time the host is restarted, the interface and the bridge should be activated automatically.

 

4. Another entry must be added to the file /etc/network/interfaces to describe the bridge. The following sample entry creates a bridge called br0, adds to it all ethernet interfaces on the host as well as the TAP interface created above and tells it to obtain an IP address using DHCP so that the host remains able to access the network.

 

auto br0

iface br0 inet dhcp

bridge_ports all tap0

 

Again, you will probably want to change this to suit your own networking needs. In particular, you may want to assign a static IP address to the bridge, or if you are using TAP interfaces created by VirtualBox (these are described later), you will want to remove tap0 from the last line. On the host, you will find more documentation in the files

 

a) /usr/share/doc/bridge-utilities/README.Debian.gz and

b) /usr/share/doc/ifupdown/examples/network-interfaces.gz.

 

5. To tell VirtualBox to use the interface, select the virtual machine which is to use it in the main window of the VirtualBox application, configure one of its network adaptors to use Host Interface Networking (using "Settings", "Network",“Attached to”) and enter “tap0” into the “Interface name” field. Alternatively, you can use the VBoxManage command line tool (in this example we are attaching the interface to the first network card of the virtual machine ("My VM"):

 

VBoxManage modifyvm "My VM" -hostifdev1 tap0