1

I have a server with one network card in it (eth1). My server is assigned 5 public IP addresses and it is currently configured like this (/etc/network/interfaces):

# The primary network interface
allow-hotplug eth1
iface eth1 inet static
    address xxx.yyy.zzz.130
    netmask 255.255.255.248
    network xxx.yyy.zzz.128
    broadcast xxx.yyy.zzz.135
    gateway xxx.yyy.zzz.129

iface eth1:0 inet static
    address xxx.yyy.zzz.131
    netmask 255.255.255.248

iface eth1:1 inet static
    address xxx.yyy.zzz.132
    netmask 255.255.255.248

iface eth1:2 inet static
    address xxx.yyy.zzz.133
    netmask 255.255.255.248

iface eth1:3 inet static
    address xxx.yyy.zzz.134
    netmask 255.255.255.248

This is working perfectly, however I wanted to add a KVM virtual machine with a bridged connection with the public IP xxx.yyy.zzz.131.

If I do this:

auto br0
iface br0 inet static
  bridge-ports eth1
  bridge_stp off
  bridge_fd 0
  bridge_maxwait 0
  address xxx.yyy.zzz.131
  netmask 255.255.255.248

Then only xxx.yyy.zzz.131 is accessible. None of the other IPs are.

If I change it to bridge-ports eth1:0 I get the error:

SIOCSIFFLAGS: Cannot assign requested address
RTNETLINK answers: File exists
Failed to bring up br0.

If I comment out the other sections about eth1:0, in addition to the above error, I also get Ignoring unknown interface eth1:0=eth10. at the beginning.

How do I add a bridged device if I only have one NIC and multiple IPs?

1

You should only have the IP address for the host on the host bridge. The IP addresses for the guests should be assigned only in the guests.

  • I tried that by removing the br0 and eth1:0 interfaces (thus freeing up that IP address), then used the default network in virt-install and I am unable to access anything or even ping the host's IP. Am I doing something else wrong? – Mike Feb 9 '15 at 23:05
  • Ugh. It turns out it was the firewall on the main server preventing it. Thanks for your help. This actually answers my question. – Mike Feb 9 '15 at 23:24
1

You can use several ways to use a public ip inside a VM.

First way is that, what you've chosen. In this case you create a bridge interface with eth1 as bridge port.

Your interfaces file should be look something like.

iface br0 inet static
    bridge-ports eth1
    bridge_stp off
    bridge_fd 0
    bridge_maxwait 0
    address xxx.yyy.zzz.130
    netmask 255.255.255.248
    gateway xxx.yyy.zzz.129

iface br0:1 inet static
    address xxx.yyy.zzz.132
    netmask 255.255.255.248

iface br0:2 inet static
    address xxx.yyy.zzz.133
    netmask 255.255.255.248

iface br0:3 inet static
    address xxx.yyy.zzz.134
    netmask 255.255.255.248

Notice, the xxx.yyy.zzz.131 isn't assigned on the host. Also the broadcast and network options are useless, so I've omitted them.

After this you can use the public ip inside VM without any additional tricks, because the VM will be connected as bridge port.

Other way is use the proxy-arp feature. For this you don't need change the interfaces file. You just assign the public ip inside VM (as primary or secondary), on the host add a route to this public ip, and enable the proxy-arp function on the eth1 interface. Notice, this public ip shouldn't be assigned on the host itself, only inside a VM. Also, don't forget make these changes permanent (you can use the post-up options in the interfaces file).

ip route add <public-ip> dev <virt-bridge-iface>
sysctl -w net.ipv4.conf.eth1.proxy_arp=1
-1

It is not possible to create a bridged network for one IP address. It needs to be done to the entire network interface or not at all. If you only have one NIC, your only option is to assign all IP addresses on the host machine and then use a firewall (e.g. iptables) to do NAT to the guest OS.

This article has a script that will do it for you automatically when the guest OSes start/stop.

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.