Saturday, April 17, 2010

Configuring a KVM guest to support multiple interfaces

As part of an experiment we were trying to configure
a single KVM virtual machine to have multiple interfaces
with each interface being on a different (IP) network.

We also needed to do this without bridging i.e. we did not
want to bridge the vnet devices coming out of the virtual
machines directly with the outside interfaces.

KVM has a concept of networks, which are essentially bridges
on some definite IP networks. The networks configured for
your ubuntu KVM setup can be checked by logging into the
virsh viewer and using the command:

virsh: net-list --all

A new network can be created by replicating and editing the XML
configuration for a network. The location for the default.xml
network definition is here: /etc/libvirt/qemu/networks/

To create a new network we will make a copy of this xml file in
the home directory (or any other path for that matter).

$> cp /etc/libvirt/qemu/networks/default.xml mynetwork.xml

Edit the mynetwork.xml file to define your new network. You can
read this new network configuration into the setup by invoking virsh
and using the net-define /path-to/mynetwork.xml command.

This network can be made to auto-start at the begininng by using the
appropriate net-autostart option in virsh. You can verify this network
by checking with the virsh net-list --all command.

Finally, you can add another interface to the KVM virtual machine instance
by editing the XML definition of the guest which is present
at: /etc/libvirt/qemu/domain.xml where domain is the name of your vm instance.

The network section can be edited to have two network interfaces as:

<interface type='network'>
<mac address='52:54:22:2a:26:33'/>
<source network='default'/>
<interface type='network'>
<mac address='52:54:00:2a:26:25'/>
<source network='mynetwork'/>

Note that the mac addresses need to be different and unique.
This definition can be read into the system by using the virsh
define domain.xml command.

Doing this should setup everything and get things running.


jukebox said...

Can you post your mynetwork.xml?

Post a Comment