1

I have a server which has a number of IPs assigned to it. I would like to set it up as a Xen hypervisor so that each VM has its own dedicated IP. The way I have my multiple IPs setup right now is:

#IP addresses are examples, actual server has public IPs
auto eth0
iface eth0 inet static
    address 192.168.1.10
    netmask 255.255.255.0
    gateway 192.168.1.1
    network 192.168.1.0

auto eth0:0
iface eth0:0 inet static
    address 192.168.1.11
    netmask 255.255.255.0

auto eth0:1
iface eth0:1 inet static
    address 192.168.1.12
    netmask 255.255.255.0

I have tried multiple things with bridging and, to be honest, I'm kinda losing hope of finding a solution on my own. How would I be able to get Xen to use one specifc IP for each of the domains?

1

The IP addresses for each of the VMs should be configured in the VM themselves, rather than the host machine.

It helps to picture each of the VMs and the host with their own interfaces, however only the host has a physical cable coming out of it, so the guest VM interfaces need to be bridged to the host interface.

You create the bridge in the /etc/networks/interfaces file, as follows:

auto lo br0 eth0

iface lo inet loopback

iface br0 inet static
        bridge_ports eth0
        address 192.168.1.10
        netmask 255.255.255.0
        gateway 192.168.1.1

This will create a new bridge when the network stack is started (such as at boot), and added your interface to it, and given the bridge the IP address of the host. Here you can see the bridge:

$ brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.60a4ecf28d84       no              eth0

You can treat the br0 interface just as you would the eth0 interface it contains.

Then in the guest config files, you have a line like:

vif = ['bridge=br0, mac=00:16:3E:12:16:19']

This is saying, "give this VM a virtual interface and add it to the br0 bridge, and give it the following mac".

Note that setting a MAC address here isn't needed, but I prefer it so that I can use DHCP to allocate a static IP address to the guests - that way I don't need to hard code any IP addresses other than the host (and the DHCP server, which in my case is a VM itself).

Then in the guest, you just configure it as you would any other linux machine:

auto eth0
iface eth0 inet static
    address 192.168.1.11
    netmask 255.255.255.0
    gateway 192.168.1.1

Note that this is in the guest machine network config.

When you bring the VM up, you'll see that the bridge now has two interfaces in it:

$ brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.60a4ecf28d84       no              eth0
                                                        vif1.0

That vif1.0 is the virtual interface of the guest. Now the guest will be able to ping the gateway and communicate just as if it were directly attached to your network with a bit of cable.

  • Thanks for your answer! I've marked it as correct, because it worked perfectly on my local test system. However, when I tried it on the machine that's meant to go in production (with the public IPs) it didn't work as expected. I'm thinking it has something to do with the gateway settings. The dom0 has address 188.165.X.Y, gateway 188.165.X.254 whilst the VM I'm trying to start has address 91.121.A.B, which is a completely different range. The VM can't reach the Internet. Do you have any idea how I should alter the settings to make this work? – Simon Jul 21 '14 at 9:27
  • @Simon I do - please ask this in a separate question and tag me in a comment here. It is different enough to need a different approach – Paul Jul 21 '14 at 11:06
  • thanks, you can find the question here: superuser.com/questions/785832/… – Simon Jul 21 '14 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.