QuicksearchOuter LandsBlogs I ReadSyndicateCategories |
Getting Xen up and running: part IIThursday, September 13. 2007
This post is intended for people who are trying to set up a private network with Xen virtual machines. (For my notes on installation of Xen, see part I.) As such, it assumes that you know what Xen is, what dom0 and domU are, and how to configure domU and xend. Particularly, you should have read the XenNetworking wiki page.
The basic problem being solved is that I don't want to maintain static IP addresses for each domU, nor do I want to maintain any static host↔IP address mapping. Instead, I want to give domU machines an IP address over DHCP, and set their hostname in DNS automatically, at least from the point of view of the machine running Xen. Of course, if other machines on the physical LAN use dom0's DNS server, they, too, will be able to see the domU machines. This is similar in concept to Xen3 and a Virtual Network on the OpenSUSE wiki, but different in implementation. Networking: BackgroundWhenever a domU is started, it receives at least one virtual Ethernet card, eth0. That card is hard-wired to a virtual interface, vifU.0, in dom0. The final network architecture depends on what the vif-script does with that vifU.0 interface. The network-script and vif-script options in xend-config.sxp simply name scripts in /etc/xen/scripts which set up or tear down networking for each virtual machine. Don't forget to do sudo /etc/init.d/xend restart after changing xend-config.sxp. For more information on the configurations which come with Xen (bridged/routed/NAT), see their respective scripts, or the XenNetworking article linked to at the top of this post.In bridged mode (the network-bridge and vif-bridge scripts), the physical ethernet card of dom0, and all vifU.0 endpoints, are connected to a virtual bridge, xenbr0. The bridge works like a real bridge, learning which MAC addresses are at which ports, and sending traffic that arrives from any card to the appropriate destination, or to all ports if the destination is unknown. This is how any domU started can appear as peers on the same network that has dom0. This also means that domU should be given a sane IP address for the physical network, or use DHCP to get an address from the physical network's DHCP server. In other words, bridged mode does not really create a "virtual network" at all; it simply connects all Xen domains to the real network. In routed mode (network-route and vif-route, naturally), each vifU.N interface must have a static IP address, and the vifU.N card is given a static route in dom0 for that single address. The bridge interface, xenbr0, is not used in this configuration, and will only be visible in dom0 if you've used bridge-mode since rebooting. Routed mode is fundamentally incompatible with DHCP. If a domU doesn't have a static address, the vif-route script doesn't assign any route to the new domU. Since the DHCP packet is addressed to the new IP address, it follows the default route onto the physical LAN, instead of going to the domU which actually needs it. On the other hand, bridged mode operates below the IP level, which makes it difficult to block DHCP requests from traveling out to the physical branch of the LAN. netfilter actually does seem powerful enough to do it, but I couldn't figure out how. DHCP for domUTo make DHCP work, add a line to the domU's configuration file (e.g. /etc/xen/xen1.cfg):
Now xen1 will be able to get an address from any DHCP server that it can see, either the existing one for the physical LAN in bridged mode, or the one we set up in routed+DHCP mode. Customized RoutingUnable to do what I wanted with the default Xen scripts, I decided to customize my own. It turns out that the network-route script was suitable for my purposes, but vif-route was not. I created a new script, called vif-private-subnet, which simply adds the vif to a bridge, and brings it up. Make sure this script is executable after placing it in /etc/xen/scripts. Here is the code for the script:
To keep the Xen side as simple as possible, I configured the bridge outside of the Xen scripts. (Unlike the bridge scripts, which take care of creating the bridge themselves.) This is the relevant part of /etc/network/interfaces:
I'm not clear on the reasons yet, but giving the bridge an IP automatically lets dom0 use it as a virtual network card. No extra interface needs to be created and attached to the bridge, and no route needs to be created manually. Do note, however, that the gateway given for eth0 needs to have a static route in order for the domU machines to be visible from the LAN. That route should direct traffic for 192.168.0.0/24 to 192.168.11.100, the public IP of kubikal.Serving DHCPI installed dnsmasq for serving DHCP to the domU machines. dnsmasq also serves DNS, and can link DHCP addresses to hostnames. I decided to have '.xen' as the domain for the virtual network, and the IP range was set in the bridge configuration above. For symmetry with the DSL modem, dom0 also sits at the last address on the virtual network, 192.168.0.254.This is the minimal set of options needed in /etc/dnsmasq.conf:
I moved the initial /etc/resolv.conf to the mentioned /etc/resolv.upstream.conf, and then set /etc/resolv.conf to direct all traffic to 127.0.0.1, where dnsmasq listens. All the DHCP clients, by default, are given the address of dom0 as a DNS server, and thus also resolve names using dnsmasq.The final piece of the puzzle is to make the domU send a hostname to dnsmasq. Without that hostname, dnsmasq doesn't know what the domU should be called, and therefore can't add it to DNS. On Debian, the hostname line in /etc/network/interfaces only applies to the DHCP clients which are not installed by default. dhclient3 does its work using /etc/dhcp3/dhclient.conf instead. Once send host-name is uncommented and set to "xen1.xen", then the DNS query returns the correct IP address. (And I begin to think of a better name than xen1....)Is that all?It's been a long, complicated process, with a number of false starts. Hopefully, I didn't miss anything. Let me know if I did. Comments
Display comments as
(Linear | Threaded)
Thanks for this. I've been trying to get my head around this for some time ... this article took me 10 minutes to digest and implement! Cheers ....
#1
John
on
2008-06-18 23:20
The author does not allow comments to this entry
Originally based on the 'Coffee Cup' theme by David Cummins, then heavily modified right here at sapphirepaw.org. |