目标:
我想在 VirtualBox 中运行 Debian-squeeze-Guest,并为 Guest 提供自己的公共静态 IP。我找到了很多关于这个主题的帖子,但总的来说,我现在花了 10 个小时(阅读手册、论坛,尝试了解网络概念和命令)为 Guest 提供自己的公共静态 IP(以便 Guest 类似于您可以从托管公司订购的 vServer),但未能成功。
由于我在网络方面还是个菜鸟,所以我可能做错了什么。(请忍耐一下:-))
情况:
VirtualBox 4.0.10(无头无 GUI)在专用的 Debian 服务器上运行,客户操作系统也是 Debian。
该服务器有一个静态 IP,我为虚拟机订购了一个额外的 IP。
问题描述:
到目前为止,我能够使用 NAT 从外部访问 VM,并在多个客户机之间设置内部网络,并且这一切运行良好。
当将 NIC 1 设置为桥接并在客户机上配置公共静态 IP 时,客户机无法 ping 通。(无论是从外部还是从主机)但我可以从另一个虚拟机通过内部网络连接到客户机。(VBoxManage controlvm VMGuest nic1 bridged eth0)(客户机“/etc/network/interfaces”上的静态 IP 配置尝试如下)
请让我知道我做错了什么,或者我可以尝试什么来让它工作,或者您是否需要更多信息。
我认为我已经读到过,使用当前的 VirtualBox 版本的桥接网络不需要特殊的主机配置,这是准确的吗,或者这可能是问题所在?
附加信息
我从托管公司获得的有关附加 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
在 Guest-VM 上执行 cat /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 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 无法通过 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)
答案1
我一直通过在主机中创建桥接接口来实现这一点,因此它看起来像这样:
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。您似乎认为这是可能的,这可能是您遇到麻烦的原因。另请注意桥接关键字。如果您之前已对其进行过 NAT,则这可能是问题所在。
答案2
我使用该脚本通过 Virtual Box 创建了不带 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。
答案3
“请注意,您只能使用此服务器的 IP 地址。”
这可能表明托管公司已在交换级别实施了第 2 层安全性,因此如果 MAC 不匹配,则不允许进入交换网络。
答案4
感谢所有回答的人!
以下德语教程终于带来了解决方案(网络部分)。我的主机 IP 和附加 IP 不在同一子网:
http://www.kitesurfer1404.de/klartext/eq6_setup
0. 来自我的托管公司的有关附加 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