VirtualBox - Public Static IP for a Debian Guest on a Dedicated Server
Solution 1
Thanks to everyone who answered!
The following German tutorial finally brought the solution (the network part).
My Host-IP and additional ip were not on the same subnet:
http://www.kitesurfer1404.de/klartext/eq6_setup
0. Information from my hosting company about the additional IP-address and Mac-address
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. On the Host
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. On the Host - change Guest settings
# 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. In the Guest
# 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
Solution 2
I have always done this by creating a bridge interface in the host so that it looks like this:
brctl show
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)
Running "VBoxManage showvminfo | grep NIC" should show something like:
NIC 1: MAC: 080027D96DFB, Attachment: Bridged Interface 'br0',
Cable connected: on, Trace: off (file: none), Type: 82540EM,
Reported speed: 0 Mbps, Boot priority: 0
I don't know if you can tell VirtualBox to bridge with eth0 directly, without having to set up br0 first. You seem to assume this is possible, and it could be the cause of your troubles. Also note the Bridged keyword. If you previously had it NATted, this could be the problem.
Related videos on Youtube
user86296
Updated on September 18, 2022Comments
-
user86296 over 1 year
Goal:
I want to run a Debian-squeeze-Guest in VirtualBox and give the guest it's own public static ip. I found tons of threads about this topic, but all in all I'm now trying for 10 hours (reading the manual, the forums, trying to learn about networking concepts & commands) to give a Guest his own public static ip (so that the Guest is similar to a vServer you can order from a hosting company), but wasn't able to.Since I'm a big noob as far as networking stuff is concerned, I'm probably doing something wrong.(please bear with me :-) )
Situation:
VirtualBox 4.0.10 (headless no gui) is running on a dedicated Debian-Server, the Guest OS is Debian as well.The server has a static ip and I ordered an additional ip for a VM.
Problem description:
Upto now I was able to use NAT to access the VM from the outside and to setup an internal network between several Guests and all of this worked very well.When setting NIC 1 to bridged and configuring a public static ip on the guest, the guest was unpingable. (neither from outside, nor from the host) I could connect to the guest via the internal network, from another vm, though. ( VBoxManage controlvm VMGuest nic1 bridged eth0 ) ( configuration attempt of static-ip on the guest '/etc/network/interfaces' is below)
Please let me know what I'm doing wrong, or what I can try to get it to work, or if you need more info.
I think I've read that with a current VirtualBox-version for bridged networking no special host-configuration is necessary, is that accurate, or might that be the problem?
Additional Info
Info I got from the hosting company about the additional IPPlease 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 on the Host-machine
# 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 on the 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
ifconfig -a on the Guest shows the correct static ip for eth0 but the Guest is unreachable "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)
-
user86296 almost 13 yearsGreat answer thanks! +1 when I have the rep. I read that bridge to eth0 directly should work in newer VBox-versions. Besides the direct way I also tried to configure a bridge br0 on the host and connect to br0 but without any luck so far. I think the problem has something to do with the hosting provider's setup.
-
user86296 almost 13 yearsGood answer thanks! I think this is the case with my hosting company. +1 when I have the rep.