1

myself and a friend have rented a dedicated server and have used KVM and libvirt to create virtual machines for us to use. (we are using debian jessie on the host)

we purchased two additional IP adresses (one for each of us) giving us three IP adresses total including the original host IP.

the host IP is 195.154.XXX.221 with a gateway of 195.154.XXX.1 and our extra IP's are 212.129.XXX.XXX on a different subnet with the same gateway. Our provider has given us mac addresses that have to be used on the device with the additional IP assigned.

we have no trouble assigning the IP's to a single virtual machine, however we do not know how we would have multiple VM's on one IP. A bridge would not work due to the fact all the VM's would need to have the same mac address.

2 Answers2

1

You have to set up DNAT on the Host to forward ports from the outside IP address to the VMs in the private VM network you have set up.

You cannot share the IP on the layer 3.

Tero Kilkanen
  • 38,887
1

This was posted a long time ago, but I've used this configuration several times now with online.net and I know other providers use the same configuration, so I'll update with the solution.

For this scenario I'll have one host and two guest machines. I'm going to be showing networking config for Debian, adjust to your OS.

**** IF YOUR ADDITIONAL IP'S ARE OUTSIDE YOUR GATEWAY IP SUBNET SEE BOTTOM OF POST AFTER SETTING UP BRIDGE ****

When you are given your IP's you will generate or get given a MAC address to use with them e.g.

XXX.YYY.ZZZ.101 - 52:54:00:00:00:01

XXX.YYY.ZZZ.102 - 52:54:00:00:00:02

XXX.YYY.ZZZ.103 - 52:54:00:00:00:03

On your host set up a bridge in your networking with your host IP assigned like so.

iface eth0 inet manual

auto vmbr0
iface vmbr0 inet static
    address XXX.YYY.ZZZ.101
    netmask 255.255.255.0
    gateway XXX.YYY.ZZZ.1
    bridge_ports eth0
    bridge_stp off
    bridge_fd 0

Now when you create your VM's set them up with the network interface vmbr0. On each of your VM's set up the following config for your networking.

auto eth0
iface eth0 inet static
    address XXX.YYY.ZZZ.102
    netmask 255.255.255.0
    gateway XXX.YYY.ZZZ.1

This should pass your additional IP's to your VM's! Awesome!

You may encounter the problem however that you are given additional IP's with a gateway outside the subnet e.g.

Gateway IP: XXX.YYY.100.1

Additional IP1: XXX.YYY.200.1

If you find yourself in this situation on your VM, you will need to manually add a route to the gateway IP and assign the IP to your interface on boot.

In debian you would do the following in your /etc/network/interfaces to achieve this:

auto eth0
iface eth0 inet manual
    pre-up ip l set dev eth0 up
    pre-up ip a add XXX.YYY.200.1 dev eth0
    pre-up ip r add XXX.YYY.100.1 dev eth0
    pre-up ip r add default via XXX.YYY.100.1
    post-down ip l set dev eth0 down

Hope this is concise and helps someone.