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):
- 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=1.2.3.4 5.6.7.8, 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 '1.2.3.4 5.6.7.8') (mac 00:16:3e:01:23:45)))
- Fix the bug in /etc/xen/scripts/vif-common.sh:
--- /etc/xen/scripts/vif-common.sh~ 2008-06-09 01:14:23.065065119 +0100
+++ /etc/xen/scripts/vif-common.sh 2008-06-09 01:11:06.599986274 +0100
@@ -103,7 +103,7 @@
if [ "$ip" != "" ]
then
local addr
- for addr in "$ip"
+ for addr in $ip
do
frob_iptable -s "$addr"
done
- Set up multi-homed or aliased interfaces as normal in the domU (depending if you’re a ip or an ifconfig kinda guy).
- Profit!
5 responses to “Xen virtual interfaces with more than one IP”
Leave a Reply
Calendar
M | T | W | T | F | S | S |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
Links
Archives
- April 2024
- February 2024
- March 2023
- November 2022
- May 2022
- February 2022
- June 2021
- January 2021
- August 2019
- October 2018
- July 2017
- May 2010
- October 2009
- August 2009
- July 2009
- March 2009
- January 2009
- July 2008
- June 2008
- April 2008
- May 2007
- January 2007
- December 2006
- June 2006
- April 2006
- March 2006
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- May 2005
- April 2005
- March 2005
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.
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. 😀
Thanks, Robert!
I’ve been banging my head against this problem for quite a while a couple of weeks ago.
[…] 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 […]
Thanks! This also fixes antispoof protection for multiple IPs when using vif-bridge 🙂