Robotic Tendencies
The personal blog of Robert McQueen

June 9, 2008

Xen virtual interfaces with more than one IP

I’ve got a load of boxes running Debian etch with Xen 3.0.3 with routed networking (rather than bridged, so I can do iptables and reverse path filtering etc in dom0). Since upgrading from Xen 2.x many moons ago, I’ve not known how to configure one virtual interface to have more than one IP. In the meantime, I’ve ended up doing nonsense like providing a VM with two interfaces just to give it two IPs. However, this interacts really badly with reverse path filtering unless you do a bunch of source-routing rocket science in the domU to send out through the right vif.

So, I looked at the vif-route script and it seems to support iterating through a space-separated list of IPs, but I was totally unable to find any documentation or mailing list posts explaining how to format the IPs within the formerly-Python key/value Xen domain config file syntax. After a while playing with the parser and various levels of quoting, I found that actually, the correct amount of quoting is none at all, and also uncovered a bug in another script which prevents it from working correctly. In the hope that this might help others using Google and trying to achieve the same as me, here is my recipe for configuring Xen vif devices to have multiple IPs (note that I think this might be specific to Xen 3.0.x, as I believe 3.2.x introduces config files in the S-expression format which is what xenstore uses internally):

  1. Configure your VM using this surprisingly obvious, but somewhat dubious syntax (including a second argument just to prove that yes, it really does work like that):

    vif=['ip=, mac=00:16:3e:01:23:45']

    When parsed into SXP by xm create, this sets the ip value correctly as a space separated list as the scripts expect:

    (device (vif (ip '') (mac 00:16:3e:01:23:45)))
  2. Fix the bug in /etc/xen/scripts/

    --- /etc/xen/scripts/ 2008-06-09 01:14:23.065065119 +0100
    +++ /etc/xen/scripts/ 2008-06-09 01:11:06.599986274 +0100
    @@ -103,7 +103,7 @@
    if [ "$ip" != "" ]
    local addr
    - for addr in "$ip"
    + for addr in $ip
    frob_iptable -s "$addr"
  3. Set up multi-homed or aliased interfaces as normal in the domU (depending if you’re a ip or an ifconfig kinda guy).
  4. Profit!

posted by ramcq @ 12:40 am
Comments (5) .:. Trackback .:. Permalink

5 responses to “Xen virtual interfaces with more than one IP”

  1. What’s the benefit of specifying an IP address in the Xen configuration?

    I just specify the MAC address and then in the DomU use as many IP addresses as I want without any problems.

    That said, thanks for the informative post. If you (or someone else) explains why I would want to put the IP addresses in the Xen configuration I’ll take advantage of this information to do what you have done.

  2. Russell: We’re using vif-route and network-route, meaning we don’t have any bridging set up on the dom0, it instead acts as a layer 3 router. Regardless of how the network is configured inside the domU, the configuration file needs to have a list of the IP addresses so that the vif-route script can add routes to those IPs in the dom0. We then use proxy_arp on the dom0’s eth0 so that people outside the machine can contact the VMs.

    The reasons for us using this configuration are partly historical (bridging used to be unreliable in the past), but we keep it now as it allows a lot more “conventional” control of traffic and addressing using iptables and friends (rather than the slightly less conventional ebtables hidden features :D). We can list the addresses our customers are able to use in the configuration file, and enforcing it to prevent any spoofing is as simple as turning on rp_filter by default for all the interfaces on the machine.

    Also, as a somewhat fringe benefit, it means the answer to “where is this VM running?” is findable using mtr. 😀

  3. tomás zerolo says:

    Thanks, Robert!

    I’ve been banging my head against this problem for quite a while a couple of weeks ago.

  4. […] Hallo Huschi, ich hab mich mal umgesehen. Bei dem Kollegen hier habe ich Beispiel gefunden, was in deine Richtung geht. Bei ihm ist es nach diesem Schema […]

  5. Charlie says:

    Thanks! This also fixes antispoof protection for multiple IPs when using vif-bridge 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.