关于“ubuntu 7.04配置网络桥使virtualbox虚拟机联网的简单方法”的一点补充

Kvm、VMware、Virtualbox、Xen、Qemu 等
回复
渔风
帖子: 56
注册时间: 2007-07-16 9:44

关于“ubuntu 7.04配置网络桥使virtualbox虚拟机联网的简单方法”的一点补充

#1

帖子 渔风 » 2007-12-28 15:25

下面是原文:

今晚无意中发现了virtualbox安装后放在/opt/VirtualBox-1.4.0目录中的用户手册文件UserManual.pdf,打开一看,哈哈!里面说得真是详细啊!可惜是英文的,但凭自己这么蹩脚的英语也还基本能看懂一些。这里将我根据其中的说明实现“主机”和“虚拟机”之间的桥接模式的过程描述一下。整个过程非常简单,比网上找到的方法简单多了,而且一次配置完了可以永久生效。

先简单描述一下我的电脑的基本情况:
主机硬件:惠普v3009tu
主机操作系统:ubuntu 7.04
主机网卡:有线网卡(eth0)一块(无线网卡我没用)
主机网络环境:内部局域网,通过路由器上网
虚拟机:用virtualbox建立,虚拟机操作系统为windows xp sp2

再说配置过程,并作简单说明:

第一步,安装必备的工具(若已安装可跳过):
(1)安装uml-utilities,该工具包含建立虚拟网络设备(所谓的“TAP interfaces”)的工具:
sudo apt-get install uml-utilities
(2)安装桥接工具bridge-utils:
sudo apt-get install bridge-utils

第二步,为了使你的虚拟机能够访问网络接口,你必须将运行虚拟主机的用户的用户名(通常是你的ubuntu登录用户名)添加到uml-net用户组。命令行的运行方法是(请用你的用户名替换其中的“vboxuser”):
sudo gpasswd -a vboxuser uml-net
你也可以通过gnome面板上的“系统—系统管理—用户和组”来添加,方法从略。
请注意:为了使改动生效,请重新启动你的电脑。

第三步,向你的ubuntu操作系统描述你要添加的虚拟网络设备:
sudo gedit /etc/network/interfaces
在打开的文件后面添加下面的内容(请用你的用户名替换其中的“vboxuser”),保存好:

auto tap0
iface tap0 inet manual
up ifconfig $IFACE 0.0.0.0 up
down ifconfig $IFACE down
tunctl_user vboxuser

auto br0
iface br0 inet dhcp
bridge_ports all tap0

上面第一部分的大概意思是将虚拟网络接口命名为“tap0”,指定该接口IP配置方法为手动,并指定使用该接口的用户。第二部分的大概意思是建立一个名叫“br0”的桥,该桥的IP配置方法为通过DHCP配置,主机中的所有网络接口,也包括tap0这个虚拟网络接口,都将建立在这个桥之上。
-------------------------------------------
这一步是需要注意的地方:
在这里你可以根据自己的网络状况将br0做相应的更改,你可以使网络桥使用静态 IP,实例形式如下:
auto br0
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
bridge_ports all tap0
一定要将“bridge_ports all tap0“这句加到后面,否则不通。
这里是很容易引起误解的地方,作者的网络环境肯定是用DHCP获取IP的,所以不需要设置成静态的IP。
还有就是这里的IP一定要设定为一个可以上网的IP,否则宿机于客机都上不了INTERNET网。
-----------------------------------------------

第四步,激活刚才建立的虚拟网络接口和网络桥:
sudo /sbin/ifup tap0
sudo /sbin/ifup br0
这个步骤只需要做一次,下次主机重新启动时,这个接口和桥将自动激活。

第五步,启动virtualbox,在主界面上选中要使用刚才建立的虚拟网络接口tap0的虚拟机,点“设置”,在弹出的窗口中选“网络”,选中其中一块网卡(通常为“网络适配器 0”),选中“启用网络适配器”,“连接到”后面选“Host Interface”,选中“接入网线”,然后在“主机网络界面名称”中填入刚才建立的虚拟网络接口的名字“tap0”,确定。

第六步,配置主机和虚拟机的网络。这步太简单了,两者你想怎么配置怎么配置。无论是主机,还是虚拟机,都是既可以手工指定静态IP,也可以从DHCP动态获取IP地址(当然,主机和虚拟机应该在同一个网段)。不过前提是要你的网管放行才行!

好了,经过上面的配置后,主机和虚拟机就成了局域网中地位相同的两台机器了,想怎么共享就怎么共享啰!
头像
百草谷居士
帖子: 3921
注册时间: 2006-02-10 16:36
系统: Mint21.1/Deepin20.8

#2

帖子 百草谷居士 » 2008-01-16 8:28

阅读,如果有多个虚拟机需要使用 桥接模式 并入局域网,应该怎么设置呢?
debian 12 / 深度系统 20.9 / Mint 21.3

为何热衷于搞发行版的多,搞应用程序开发的少?Linux最多余的就是各种发行版,最缺的就是应用程序,特别是行业应用程序。
头像
百草谷居士
帖子: 3921
注册时间: 2006-02-10 16:36
系统: Mint21.1/Deepin20.8

#3

帖子 百草谷居士 » 2008-01-16 9:47

在网上搜索到下面的文章,是快照,原文地址已经不可访问。未经测试。
====================================================
Ubuntu下多虚拟网卡(VirtualBox)

Tuesday, 13. November 2007, 06:20:53

uml-net, VirtualBox, 虚拟网卡, ubuntu
在Ubuntu下用VirtualBox做虚拟机,缺省的网络是NAT的。对于测试来说不太好用,外边的机器访问不进去。后来找到了方法就是虚拟一个网卡,然后在网络上就与宿主机平等了。
如下:

sudo apt-get install uml-utilities bridge-utils

装好虚拟网卡和桥接后,把要使用的用户加到uml-net用户组

sudo gpasswd -a your_user_account uml-net

然后在interface里增加虚拟网卡,我要开两个VirtualBox,所以加了两个卡

sudo nano /etc/network/interfaces

在后边增加:

auto tap0
iface tap0 inet manual
up ifconfig $IFACE 0.0.0.0 up
down ifconfig $IFACE down
tunctl_user your_user_account

auto tap1
iface tap1 inet manual
up ifconfig $IFACE 0.0.0.0 up
down ifconfig $IFACE down
tunctl_user your_user_account

auto br0
iface br0 inet dhcp
bridge_ports all tap0 tap1

完成后就可以启动tap0,tap1和网桥了:
sudo /sbin/ifup tap0
sudo /sbin/ifup tap1
sudo /sbin/ifup br0
debian 12 / 深度系统 20.9 / Mint 21.3

为何热衷于搞发行版的多,搞应用程序开发的少?Linux最多余的就是各种发行版,最缺的就是应用程序,特别是行业应用程序。
头像
felixlu
帖子: 311
注册时间: 2006-11-25 15:27
来自: SZ

#4

帖子 felixlu » 2008-02-21 16:59

请问怎么把桥接改回原来的NAT?按照这里的步骤一步一步反过来做?
发现改用桥接以后开机会在启用网络配置那里停好久,现在开机慢了很多。
NoteBook: IBM X40 (1G Hz, 1.25GB, 20G+120GB)
Desktop: APU A6-3670, MSI A75A-G55, 4GB DDR3 1600 x 2
Slackware64 + Win7
头像
百草谷居士
帖子: 3921
注册时间: 2006-02-10 16:36
系统: Mint21.1/Deepin20.8

#5

帖子 百草谷居士 » 2008-03-03 11:21

其实建立桥接有更简单的方法,我在virtualbox的帮助中看到的,不用下载uml-utilities包,另外,也不用编辑那么多配置文件,增加虚拟网卡只用一个命令就可以了。下面是帮助中的原文:
To set up a permanent host interface on a modern Debian or Ubuntu host, follow these steps:
1、First install the bridge utilities (bridge-utils). package. You can do this from the command line as follows
sudo apt-get install bridge-utils
2、Next, you must add an entry to the file /etc/network/interfaces to describe the bridge. The following sample entry creates a bridge called br0, adds the host ethernet interface eth0 to it 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 eth0

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. You will find more documentation in the files

/usr/share/doc/bridge-utilities/README.Debian.gz and
/usr/share/doc/ifupdown/examples/network-interfaces.gz.

3、Restart networking on the host:
sudo /etc/init.d/networking restart
After this the bridge will remain on your system even after a restart.
4、Now, to create a permanent host interface called vbox0 (all host interfaces created in this way must be called vbox followed by a number) and add it to the network bridge created above, use the following command (see Section 6.5.1.5, “Host Interface Networking utilities for Linux” for more details):
sudo VBoxAddIF vbox0 <user> br0
Replace <user> with the name of the user who is supposed to be able to use the new interface.
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 vbox0 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 vbox0
上面的方法经过我的验证,在vbox1.5.6+ubuntu7.10中通过,我使用的是静态ip地址,静态ip可以参考楼上的几个帖子。
概括起来,就是四个步骤:
1、安装bridge-utils包;
2、在/etc/network/interfaces配置文件中设置网桥;
3、重新启动网络,使用sudo /etc/init.d/networking restart可以在不重新启动电脑的情况下启动网络。
4、增加一个虚拟网卡:sudo VBoxAddIF vbox0 <user> br0。注意这个命令有三个参数:第一个是虚拟网卡的名字,必须以vbox开头,第二是用户名就是使用vbox的用户,第三是网桥名,就是在第二步做的网桥名字。
debian 12 / 深度系统 20.9 / Mint 21.3

为何热衷于搞发行版的多,搞应用程序开发的少?Linux最多余的就是各种发行版,最缺的就是应用程序,特别是行业应用程序。
头像
SecretZero
帖子: 1670
注册时间: 2007-08-30 5:39

#6

帖子 SecretZero » 2008-03-03 23:15

用了只有不能用pon dsl-provider上网啊。
深度,值得深入!
http://bbs.deepin.org/?u=348684

最新的综艺魔法相册
http://www.77studio.net/?fromuid=344
头像
SecretZero
帖子: 1670
注册时间: 2007-08-30 5:39

#7

帖子 SecretZero » 2008-03-05 18:13

在这里的时候无效啊。

代码: 全选

sudo /sbin/ifup tap0
sudo /sbin/ifup br0
深度,值得深入!
http://bbs.deepin.org/?u=348684

最新的综艺魔法相册
http://www.77studio.net/?fromuid=344
lgx2351
帖子: 5
注册时间: 2008-09-05 16:41

Re: 关于“ubuntu 7.04配置网络桥使virtualbox虚拟机联网的简单方法”的一点补充

#8

帖子 lgx2351 » 2008-09-27 10:15

我也是到sudo /sbin/ifup tap0的时候出错,楼主出来解决下啊?
liugx@thinkpad-t61:~$ sudo /sbin/ifup tap0
/etc/network/interfaces:23: interface br0 declared allow-auto twice
/sbin/ifup: couldn't read interfaces file "/etc/network/interfaces"
iamyql
帖子: 11
注册时间: 2007-04-29 13:28

Re: 关于“ubuntu 7.04配置网络桥使virtualbox虚拟机联网的简单方法”的一点补充

#9

帖子 iamyql » 2008-11-10 23:25

mask.正在找这 个,试了看看行不行。。
出岫之云
帖子: 220
注册时间: 2007-06-21 22:25

Re: 关于“ubuntu 7.04配置网络桥使virtualbox虚拟机联网的简单方法”的一点补充

#10

帖子 出岫之云 » 2009-02-03 23:31

楼主引用的是我很久以前的帖子,现在vbox 2.1.2已不必这么麻烦,可以直接在虚拟电脑的“设置”中设置虚拟机的网络为“Host Interface”了。
ziang8502
帖子: 1
注册时间: 2010-09-26 22:37

Re: 关于“ubuntu 7.04配置网络桥使virtualbox虚拟机联网的简单方法”的一点补充

#11

帖子 ziang8502 » 2010-11-20 21:29

现在好像不要这么麻烦吧……
回复