目标:
我想在VirtualBox中运行一个Debian-squeeze-Guest,并给它自己的公共静态IP。 我发现了很多关于这个主题的话题,但总而言之,我现在正在尝试10个小时(阅读手册,论坛,试图了解networking概念和命令)给客人他自己的公共静态IP(所以客户类似于你可以从托pipe公司订购的vServer),但是无法做到。
因为在networking方面我是一个大白菜,所以我可能做错了什么(请耐心等待:-))
情况:
VirtualBox 4.0.10(headless no gui)运行在专用的Debian-Server上,Guest OS也是Debian。
服务器有一个静态IP,我为VM订购了一个额外的IP。
问题描述:
现在,我可以使用NAT从外部访问虚拟机,并在几个虚拟机之间build立内部networking,所有这些工作都非常顺利。
在将NIC 1设置为桥接并在来宾上configuration公共静态IP时,来宾无法启动。 (既不是从外部,也不是从主机)我可以通过内部networking连接到来宾,从另一个VM,但是。 (VBoxManage controlvm VMGuest nic1桥接eth0)(在guest虚拟机的'/ etc / network / interfaces'下configurationstatic-ip的尝试如下)
请让我知道我做错了什么,或者我可以尝试得到它的工作,或者如果你需要更多的信息。
我想我已经阅读了一个当前的VirtualBox版本的桥接networking没有特殊的主机configuration是必要的,是否准确,或者可能是这个问题?
附加信息
我从托pipe公司获得的有关额外IP的信息
Please note that you can use the IP address only for this server. IP: 46.4.xx.xx Gateway: 46.4.xx.xx Mask: 255.255.255.248
VBoxManage showvminfo VMGuest | less
... NIC 1: MAC: 080027D72F7B, Attachment: Bridged Interface 'eth0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0 NIC 2: MAC: 080027B03B75, Attachment: Internal Network 'InternalNet1', Cable connected: on, Trace: off (file: none), Type: Am79C973, Reported speed: 0 Mbps, Boot priority: 0 NIC 3: disabled (...rest is disabled)
cat / etc / network / interfaces在主机上
# Loopback device: auto lo iface lo inet loopback # device: eth0 auto eth0 iface eth0 inet static address 46.4.xx.xx broadcast 46.4.xx.xx netmask 255.255.255.224 gateway 46.4.xx.xx post-up mii-tool -F 100baseTx-FD eth0 # default route to access subnet up route add -net 46.4.xx.xx netmask 255.255.255.224 gw 46.4.xx.xx eth0
cat / etc / network / interfaces在Guest-VM上
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug eth0 auto eth0 iface eth0 inet static address 46.4.xx.xx netmask 255.255.255.248 gateway 46.4.xx.xx auto eth1 iface eth1 inet dhcp
Guest上的ifconfig -a显示eth0的正确静态IP,但guest虚拟机“over eth0”无法访问
eth0 Link encap:Ethernet HWaddr 08:00:27:d7:2f:7b inet addr:46.4.xx.xx Bcast:46.4.xx.xx Mask:255.255.255.248 inet6 addr: fe80::a00:27ff:fed7:2f7b/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:21 errors:0 dropped:0 overruns:0 frame:0 TX packets:69 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1260 (1.2 KiB) TX bytes:3114 (3.0 KiB) eth1 Link encap:Ethernet HWaddr 08:00:27:b0:3b:75 inet addr:192.168.10.3 Bcast:192.168.10.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:feb0:3b75/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:142 errors:0 dropped:0 overruns:0 frame:0 TX packets:92 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:15962 (15.5 KiB) TX bytes:14540 (14.1 KiB) Interrupt:16 Base address:0xd240 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:123 errors:0 dropped:0 overruns:0 frame:0 TX packets:123 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:25156 (24.5 KiB) TX bytes:25156 (24.5 KiB)
我一直通过在主机中创build一个网桥接口来完成这个工作,看起来像这样:
brctl显示
bridge name bridge id STP enabled interfaces br0 8000.0025b3bafc61 no eth0
ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:25:B3:BA:FC:61 inet6 addr: fe80::225:b3ff:feba:fc61/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:12199478 errors:0 dropped:0 overruns:0 frame:0 TX packets:1121494 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1101744530 (1.0 GiB) TX bytes:396467719 (378.1 MiB) Interrupt:51
ifconfig br0
br0 Link encap:Ethernet HWaddr 00:25:B3:BA:FC:61 inet addr:10.16.21.55 Bcast:10.16.21.255 Mask:255.255.255.0 inet6 addr: fe80::225:b3ff:feba:fc61/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1280420 errors:0 dropped:0 overruns:0 frame:0 TX packets:1098325 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:334957389 (319.4 MiB) TX bytes:394733263 (376.4 MiB)
运行“VBoxManage showvminfo | grep NIC”应该显示如下内容:
NIC 1: MAC: 080027D96DFB, Attachment: Bridged Interface 'br0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0
我不知道你是否可以直接告诉VirtualBox与eth0桥接,而不必先设置br0。 你似乎认为这是可能的,这可能是你的烦恼的原因。 另请注意Bridged关键字。 如果你以前有过NAT,这可能是问题所在。
我使用该脚本创build虚拟机与虚拟框没有GUI:
#!/bin/bash VMNAME="OpenBSD" VBoxManage createvm --name $VMNAME --ostype OpenBSD --register VBoxManage createhd --filename ~/"VirtualBox VMs"/$VMNAME/$VMNAME --size 100000 VBoxManage storagectl $VMNAME --name "IDE Controller" --add ide --controller PIIX4 --hostiocache on --bootable on VBoxManage storageattach $VMNAME --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium ~/"VirtualBox VMs"/$VMNAME/$VMNAME.vdi VBoxManage storageattach $VMNAME --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium ~/iso/install49.iso --passthrough off VBoxManage modifyvm $VMNAME --memory 512 --vrde on --acpi on --rtcuseutc on VBoxManage modifyvm $VMNAME --nic1 bridged --bridgeadapter1 eth0 VBoxManage modifyvm $VMNAME --nic2 bridged --bridgeadapter2 eth1 VBoxManage modifyvm $VMNAME --nic3 bridged --bridgeadapter3 eth2
它工作正常。 其中一个虚拟接口有公网IP,其他接口有内网IP。
“请注意,您只能使用此服务器的IP地址。”
这可能表明托pipe公司已经在交换级实现了第2层安全性,所以如果MAC不匹配,它将不被允许进入交换networking。
感谢所有回答的人!
下面的德语教程最后提出了解决scheme(networking部分)。 我的主机IP和附加IP不在同一个子网上:
http://www.kitesurfer1404.de/klartext/eq6_setup
0.来自我的托pipe公司的关于额外的IP地址和Mac地址的信息
Host-IP: _hostIP_ Additional IP: _additionalIP_ Gateway: _gatewayIP_ Maske: 255.255.255.248 Your IP _additionalIP_ has the following separate MAC-adress for virtualisation purposes: Mac-address for the nic: _macaddress_
1.在主机上
iptables -P FORWARD ACCEPT sysctl -w net.ipv4.ip_forward=1 # Add the Gateway as an IP-address on the host, in the following way (not the actual additional IP): ip addr add _gatewayIP_/255.255.255.248 dev eth0 # Add a route for the 2nd additional ip in the following way route add -host _additionalIP_ gw _additionalIP_ # make the changes persistent - this part is not tested! emacs /etc/network/interfaces # ---------------------------------------- # Loopback device: auto lo iface lo inet loopback # device: eth0 auto eth0 iface eth0 inet static address _hostIP_ broadcast _broadcast_ netmask 255.255.255.224 gateway _gateway_ post-up mii-tool -F 100baseTx-FD eth0 # default route to access subnet up route add -net 46.4.xx.xx netmask 255.255.255.224 gw 46.4.xx.xx eth0 up ip addr add _gatewayIP_/255.255.255.248 dev eth0 up route add -host _additionalIP_ gw _additionalIP_ # ----------------------------------------
2.在主机 – 更改访客设置
# set the mac-address of the guests nic to the virtual mac-address we got for our additional ip # bridgeadapter1 is the network card from the Host that should be used for the bridge VBoxManage modifyvm VMGuest --nic1 bridged --bridgeadapter1 eth0 --nictype1 Am79C973 --macaddress1 _macaddress_ VBoxHeadless -startvm VMGuest
3.在客人
# connect via internal network and edit the network-configuration emacs /etc/network/interfaces # -------------------------------------------------- # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug eth0 auto eth0 iface eth0 inet static address _additionalIP_ netmask 255.255.255.248 gateway _gatewayIP_ allow-hotplug eth1 auto eth1 iface eth1 inet dhcp # -------------------------------------------------- shutdown -r now