An introduction to custom Xen networking
Posted by Steve on Mon 27 Feb 2006 at 05:16
I've been running Xen for a few weeks now and until now I've been happy with the default networking setup installed. Only when I decided to install Xen upon the server which is hosting this website did I need to explore the way Xen sets up networking.
Xen is pretty good at giving a working network setup for most common cases. By default it sets up virtual instances so they communicate with the network via the host's eth0 device, using NAT.
There are several other supported configurations for the times when this setup isn't appropriate these are:
- bridged networking.
- routed networking.
Each of the available network setups are implemented via a pair of scripts inside the directory /etc/xen/scripts. For example the bridge setup is implemented in the two files:
- /etc/xen/scripts/network-bridge
- /etc/xen/scripts/vif-bridge
In order to change the network setup you simply tell the xend daemon which script(s) it should be using via the configuration file /etc/xen/scripts/xend-config.sxp.
To switch to the bridge setup, for example, you'd make sure the following settings were present:
(network-script network-bridge) (vif-script vif-bridge)
When I needed to host some Xen instances upon this machine I needed to use the routed setup, which could be done by setting:
(network-script network-route) (vif-script vif-route)
- My server has the public IP address 80.68.80.176.
- My hosting provider gave me an additional range 80.68.86.192/29 for use by Xen.
The new IP addresses 80.68.86.192/29 were each routed via my existing public address - and in this scenario I couldn't use NAT, since these are public addresses.
Instead I needed to use a bridge. The range I've been given /29 means that I have 6 public IP addresses. One of these must be allocated to the bridge - leaving me with 5 addresses for use by Xen machines.
The following diagram shows what I needed to do:
This image was created using Dia; source file available
The way that bridging works is that the host gains an IP address in the new range, and the virtual instances use this IP address as their default gateway, or route, to the internet.
To setup the bridge required two steps:
- Setup the xend-config.sxp file, as previously discussed.
- Make sure the host has an IP address allocated on the bridge.
To give the host an IP address on the bridge we can't use virtual addresses so we manage it by using the dummy driver:
skx2:~# modprobe dummy skx2:~# ifconfig dummy0 80.68.86.193 up
To make sure that these settings persist we add the name 'dummy' to the file /etc/modules - and add the dummy network address to the file /etc/network/interfaces as follows:
auto dummy0
iface dummy0 inet static
address 80.68.86.193
broadcast 80.68.86.199
netmask 255.255.255.248
Once this is done we've got the host setup correctly. Restarting xend will allow it to create the bridge:
root@skx2:~# /etc/init.d/xend restart
Now we just need to create the virtual instances giving them IP addresses from the range 80.68.86.192/29 ensuring that they use the IP address 80.68.86.193 as their gateway.
One minor complication was that initially my Xen instances were unable to see the network. It turned out that adding a new line to the configuration file(s) in /etc/xen/ for each instances was required:
kernel = "/boot/xen-linux-2.6.12.6-xen" memory = 128 name = "vm1.steve.org.uk" root = "/dev/sda1 ro" vif = [ 'ip=80.68.86.194' ] disk = ....
Adding the vif line allowed things to work correctly.
How to prevent stealing others IP from inside domU?
[ Parent | Reply to this comment ]
ebtables
[ Parent | Reply to this comment ]
cheers
Paul
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
Yes. For routing, that IP is the bridge out to the internet - since the other machines have IPs on ranges where they couldn't reach the gateway..
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
No:
vm1:/home/steve# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 80.68.86.192 * 255.255.255.248 U 0 0 0 eth0 default 80.68.86.193 0.0.0.0 UG 0 0 0 eth0 vm1:/home/steve# route del default gw 80.68.86.193 vm1:/home/steve# route add default gw 80.68.80.176 SIOCADDRT: Network is unreachable
Because it is on a different network to the IP of the virtual host it can't be reached with the given netmask/broadcast address.
[ Parent | Reply to this comment ]
This is a bit off topic.
But is there a way to give each vm's their own public IP's which aren't in a nice subnet?
Becuase i've bought couple of IP's from my isp and all of them are jsut random ip's, in no particular order. Also they are all set to 255.255.255.255 netmask.
How would i go about doing this?
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
Assuming that you have something upstream of your IPs doing the routing for you (so that packets will reach your virtual machines) you might not need to do anything special at all.
Setup the machine(s) with the IP addresses you've been given, set the default route to whichever gateway you're supposed to use and hope for the best!
(Really it is hard to say without a lot more details and knowlege of your setup. But if your provider has sold you IPs I'd expect them to be routable and you to have all the details you need.)
[ Parent | Reply to this comment ]
James
[ Parent | Reply to this comment ]
route add 80.68.80.176 dev eth0
route add default gw 80.68.80.176
[ Parent | Reply to this comment ]
Do i also have to
skx2:~# modprobe dummy
skx2:~# ifconfig dummy0 ip.of.my.hostgateway up
I set
(network-script network-bridge)
(vif-script vif-bridge)
in /etc/xen/scripts/xend-config.sxp.
My domains .cfg looks like this
vif = ['']
and the vm networkconfiguration is unconfigured.
Starting vm is ok, but after configuring and starting vms network i loose the connection and have to reboot the host.
Can somebody help?
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
I have one NIC in the Server and two IPs. I want one for dom0, the other for domU.
The Problem is that my hoster is dropping my Switchport as soon as there arrive Packets with MACs different from my MAC in the physical NIC.
I had a look at ebtables but am not quite shure how exactly to use them in this special case.
tia
[ Parent | Reply to this comment ]
Does Xen also support bridging on several physical interfaces? This, I guess, would allow virtual hosts on the same CPU belonging to different subnets.
Thanks
Mikael
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
For me it was necessary to do:
echo "1" > /proc/sys/net/ipv4/ip_forward
To make sure your box is set to forward IP traffic from the bridge to the DomU
[ Parent | Reply to this comment ]
I recently started with Xen (3.1.0) on my new server running Ubuntu Gutsy (7.10) and I'm experiencing very poor network performance on my domU's.
Since my colo provider offers me a /28 of routed public IPs next to one interconnection IP to their routers, I built a Xen configuration as described in this article (thanks for writing it, it was very useful!). This works as expected: all domU's are accessible from the internet.
The network performance of the Dom0 is fine: I can saturate my 100Mb/sec uplink both by uploading and downloading. Performance towards the domU is fine as well. Performance from the DomU's to the internet however is dramatic: speeds start at 2-3MB/sec but quickly drop to just a few KB/sec (!). Transfer of large files never end at all.
The server I'm running this on is a Supermicro H8SSL-i2 with and AMD Opteron 1218 Dual Core proc, 4GB RAM, the NIC is a Broadcom 1G interface connected to a 100Mb/sec switchport at my ISP.
I've tried searching these archives (and the internet) for any clue what might cause this poor upload performance, but failed to find anything really useful.
If anyone has hints and tips on how to make my DomU's uplink speed normal, I'd really appreciate it. I really have no idea where to look now :(
TIA,
Teun
[ Parent | Reply to this comment ]
ethtool -K eth0 tx offon the domU solves this.
[ Parent | Reply to this comment ]
I am wrestling with a xen problem right now·
Regards;
[ Parent | Reply to this comment ]