vbox下安装xp,网桥和NAT都有网络问题,求解

Kvm、VMware、Virtualbox、Xen、Qemu 等
回复
amatsuka
帖子: 10
注册时间: 2008-11-10 20:58

vbox下安装xp,网桥和NAT都有网络问题,求解

#1

帖子 amatsuka » 2008-11-24 21:38

我的网络是这样的,普通的ADSL,用路由器拨号,主机的IP由路由器分配。

用vbox装的xp,如果用NAT的方法,Host可以上网,但是Guest上不了。

如果换成网桥,那么Guest就可以上网,Host就上不了了,查看连接信息,网桥br0和网卡eth0的信息是一模一样的,下面附上我的/etc/network/interfaces里的设置,哪位高人能看看我这个该怎么弄?

auto lo
iface lo inet loopback

allow-hotplug eth0
iface eth0 inet manual
up ifconfig eth0 0.0.0.0 promisc up

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

auto br0
iface br0 inet dhcp
bridge_ports all tap0
up ifconfig $IFACE up

按着这个脚本设置以后,eth0的ip不是0.0.0.0,还依旧是路由器分配的地址,同时br0的地址和eth0一模一样。
amatsuka
帖子: 10
注册时间: 2008-11-10 20:58

Re: vbox下安装xp,网桥和NAT都有网络问题,求解

#2

帖子 amatsuka » 2008-11-25 8:16

NAT的解决了。曾经有一篇文章是说通过设置第一DNS来给火狐加速的,问题就出这里了,dnsmasq的首选dns不能设为127.0.0.1,设成本机以后,NAT就上不去了。
woooo
帖子: 83
注册时间: 2007-08-11 16:37
来自: HUBEI WUHAN

Re: vbox下安装xp,网桥和NAT都有网络问题,求解

#3

帖子 woooo » 2008-11-25 14:43




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

网上很多文章,包括VirtualBox自己的帮助文档都有为VirtualBox设置桥接模式的教程,但是基本上都是写Host和Guest都采用dhcp的方式来获取IP,但是在我的环境中,必须要设置自己的静态IP,所以最后有一些稍微不一样。

下面我在Ubuntu7.04下设定VirtualBox中Host Networking为桥接模式的过程, 桥接模式可以使Host OS 和Guest OS在区域网路中处于平行地位。

安装所需工具uml-utilities,bridge-utils
sudo apt-get install uml-utilities bridge-utils


首先为Host OS建立桥接界面(Bridge)和虚拟网卡设备(tap device),这样作的原故,是使将来取得IP是由桥接界面(bridge),而不是由ethx(真实的有线网卡)或tapx(虚拟网卡)来取得IP。

将下面的文本保存成文件,有需要按自己的情况修改一两个地方。存为在/etc/init.d/vboxbridgedrun
sudo gedit /etc/init.d/vboxbridgedrun

引用
# VirtualBox Bridging

# Create a tap device with permission for the user running vbox
# 建立一个使用者(user)有权限的设备tap0,{user}为自己用户名
tunctl -t tap0 -u {user}
chmod 0666 /dev/net/tun

# Bring up ethX and tapX in promiscuous mode
# 将ethx和tapx网卡界面设为混杂模式(Promiscuous)
ifconfig eth0 0.0.0.0 promisc
ifconfig tap0 0.0.0.0 promisc

# Create a new bridge and add the interfaces to the bridge.
# 建立新的桥接界面(bridge),並把 eth0, tap0加入bridge
brctl addbr br0
brctl addif br0 eth0
brctl addif br0 tap0

# 下面是两种获取IP的方式,可以自由选择,把不需要的注释掉就好了。
# 将bridge设成静态IP。XXX都分别对应IP、子网掩码、网关。
ifconfig br0 XXX.XXX.XXX.XXX netmask XXX.XXX.XXX.XXX up
route add default gw XXX.XXX.XXX.XXX
# 将bridge设成动态DHCP分配IP。
#dhclient br0

给上面的文件加上可执行权限
sudo chmod +x /etc/init.d/vboxbridgedrun

然后再建立一个可执行文件,添加如下内容。
sudo gedit /etc/init.d/vboxbridge

引用
/etc/init.d/vboxbridgedrun &

sudo chmod +x /etc/init.d/vboxbridge

最后在/etc/rc2.d目录下做一个指向/etc/init.d/vboxbridge的链接
cd /etc/rc2.d/
sudo ln -sf ../init.d/vboxbridge S999vboxbridge #取名S999开头是为了让它最后启动


重新启动电脑之后,现在可以在VirtualBox的Guest OS网路设定画面中,将attached to的选项中选择host interface,interface name选项中设为tap0。

这样就完成Virtualbox桥接网路模式的设定了,马上启动Guest吧 ! Guest的网路设定和Host是独立平行的。

PS:实用小指令
刪除 tap0
tunctl -d tap0

刪除 br0
ifconfig br0 down
brctl delbr br0

将tap0, eth0 移出bridge(br0)
brctl delif br0 tap0
brctl delif br0 eth0
回复