Public static IP for a Debian Guest on a Dedicated Server

Discussions about using Linux guests in VirtualBox.
Post Reply
Carl_Carlson
Posts: 5
Joined: 30. Jun 2011, 20:30
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian

Public static IP for a Debian Guest on a Dedicated Server

Post by Carl_Carlson »

Goal:
I want to give a Debian-squeeze-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 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 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)
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Public static IP for a Debian Guest on a Dedicated Server

Post by Sasquatch »

Why do you have added the static route for something that's in the same subnet? You don't need a gateway in order to access machines that are in the same subnet. What happens if you change that?
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
Carl_Carlson
Posts: 5
Joined: 30. Jun 2011, 20:30
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian

Re: Public static IP for a Debian Guest on a Dedicated Server

Post by Carl_Carlson »

# default route to access subnet
up route add -net 46.4.xx.xx netmask 255.255.255.224 gw 46.4.xx.xx eth0
This part has been in the host's /etc/network/interfaces-config from the start I didn't make any changes to it.
Actually the current version of the interfaces-file on the host is completely unchanged.

I commented the 'up route ..'-part out and made an '/etc/init.d/networking restart' on the host+guest which had no effect.
(unpingable)

I've never done any network-stuff before, only basic server-administration that's necessary for a simple web-service, I'm reading up on this since yesterday, but I'm still pretty clueless about how a correct network-configuration should look like.

Should I try some other changes?
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Public static IP for a Debian Guest on a Dedicated Server

Post by Sasquatch »

The Guest has internet access? The configuration looks fine. The Host and Guest have almost the same configuration? I am assuming here that you do not give the VM the same IP as the Host, that would be bad. Does the Hosting provider allow only certain MAC addresses on their network? Maybe the block the VM.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
Carl_Carlson
Posts: 5
Joined: 30. Jun 2011, 20:30
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian

Re: Public static IP for a Debian Guest on a Dedicated Server

Post by Carl_Carlson »

Sasquatch wrote:The Guest has internet access?
No using bridged I can't ping anything but other VMs that are in the internal network.
Sasquatch wrote:The Host and Guest have almost the same configuration?
Yes I'd say so, both are debian squeeze OS and both have (well should have) a static ip.
Sasquatch wrote:I am assuming here that you do not give the VM the same IP as the Host, that would be bad.
No double checked that the host has it's original IP unchanged and I tried to set the 2nd IP that I ordered within the Guest.
Sasquatch wrote:Does the Hosting provider allow only certain MAC addresses on their network? Maybe the block the VM.
That seems to be the case I'm investigating that.
Sasquatch wrote:The configuration looks fine.
Good to know so I should probably look more on the side of the hosting provider.
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Public static IP for a Debian Guest on a Dedicated Server

Post by Sasquatch »

Yes, but take a look at the DHCP settings on the internal side. Does it include a default gateway? If so, then that needs to be removed as it can conflict with the gateway it needs on eth0. If the other VMs are not able to connect to the internet and a gateway is set anyway in the DHCP options, it will certainly cause issues.
If the DHCP side is the Host-Only adapter, then it should not have a default gateway. See the output of 'route -n' for the gateways that are set on the OSes. Compare them and post them here if you don't know what to look for.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
Carl_Carlson
Posts: 5
Joined: 30. Jun 2011, 20:30
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian

Re: Public static IP for a Debian Guest on a Dedicated Server

Post by Carl_Carlson »

Sasquatch, thanks a lot for the help!
I was finally able to give the guest it's own public static ip.


Now I'm going to figure out which of all the things I did were actually necessary :) and how I can make those configuration-changes persistent and then I'm going to write an update about the necessary steps. (Might take 2-3 days)

Cheers
Carl_Carlson
Posts: 5
Joined: 30. Jun 2011, 20:30
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian

Re: Public static IP for a Debian Guest on a Dedicated Server

Post by Carl_Carlson »

# 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

Code: Select all

# 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

Code: Select all

# 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
Post Reply