Network XML format

This page provides an introduction to the network XML format. For background information on the concepts referred to here, consult the network driver architecture page.

Element and attribute overview

The root element required for all virtual networks is named network and has no configurable attributes (although since 0.10.0 there is one optional read-only attribute - when examining the live configuration of a network, the attribute connections, if present, specifies the number of guest interfaces currently connected via this network). The network XML format is available since 0.3.0

General metadata

The first elements provide basic metadata about the virtual network.

      <network>
        <name>default</name>
        <uuid>3e3fce45-4f53-4fa7-bb32-11f34168b82b</uuid>
        ...
name
The content of the name element provides a short name for the virtual network. This name should consist only of alpha-numeric characters and is required to be unique within the scope of a single host. It is used to form the filename for storing the persistent configuration file. Since 0.3.0
uuid
The content of the uuid element provides a globally unique identifier for the virtual network. The format must be RFC 4122 compliant, eg 3e3fce45-4f53-4fa7-bb32-11f34168b82b. If omitted when defining/creating a new network, a random UUID is generated. Since 0.3.0

Connectivity

The next set of elements control how a virtual network is provided connectivity to the physical LAN (if at all).

        ...
        <bridge name="virbr0" stp="on" delay="5"/>
        <domain name="example.com"/>
        <forward mode="nat" dev="eth0"/>
        ...
bridge
The name attribute on the bridge element defines the name of a bridge device which will be used to construct the virtual network. The virtual machines will be connected to this bridge device allowing them to talk to each other. The bridge device may also be connected to the LAN. It is recommended that bridge device names started with the prefix vir, but the name virbr0 is reserved for the "default" virtual network. This element should always be provided when defining a new network with a <forward> mode of "nat" or "route" (or an isolated network with no <forward> element). Attribute stp specifies if Spanning Tree Protocol is 'on' or 'off' (default is 'on'). Attribute delay sets the bridge's forward delay value in seconds (default is 0). Since 0.3.0
domain
The name attribute on the domain element defines the DNS domain of the DHCP server. This element is optional, and is only used for those networks with a <forward> mode of "nat" or "route" (or an isolated network with no <forward> element). Since 0.4.5
forward
Inclusion of the forward element indicates that the virtual network is to be connected to the physical LAN.Since 0.3.0. The mode attribute determines the method of forwarding. If there is no forward element, the network will be isolated from any other network (unless a guest connected to that network is acting as a router, of course). The following are valid settings for mode (if there is a forward element but mode is not specified, mode='nat' is assumed):
nat
All traffic between guests connected to this network and the physical network will be forwarded to the physical network via the host's IP routing stack, after the guest's IP address is translated to appear as the host machine's public IP address (a.k.a. Network Address Translation, or "NAT"). This allows multiple guests, all having access to the physical network, on a host that is only allowed a single public IP address. If a network has any IPv6 addresses defined, the IPv6 traffic will be forwarded using plain routing, since IPv6 has no concept of NAT. Firewall rules will allow outbound connections to any other network device whether ethernet, wireless, dialup, or VPN. If the dev attribute is set, the firewall rules will restrict forwarding to the named device only. Inbound connections from other networks are all prohibited; all connections between guests on the same network, and to/from the host to the guests, are unrestricted and not NATed.Since 0.4.2
route
Guest network traffic will be forwarded to the physical network via the host's IP routing stack, but without having NAT applied. Again, if the dev attribute is set, firewall rules will restrict forwarding to the named device only. This presumes that the local LAN router has suitable routing table entries to return traffic to this host. All incoming and outgoing sessions to guest on these networks are unrestricted. (To restrict incoming traffic to a guest on a routed network, you can configure nwfilter rules on the guest's interfaces.) Since 0.4.2
bridge
This network describes either 1) an existing host bridge that was configured outside of libvirt (if a <bridge name='xyz'/> element has been specified, Since 0.9.4), 2) an existing Open vSwitch bridge that was configured outside of libvirt (if both a <bridge name='xyz'/> element and a <virtualport type='openvswitch'/> have been specified Since 0.10.0) 3) an interface or group of interfaces to be used for a "direct" connection via macvtap using macvtap's "bridge" mode (if the forward element has one or more <interface> subelements, Since 0.9.4) (see Direct attachment to physical interface for descriptions of the various macvtap modes). libvirt doesn't attempt to manage the bridge interface at all, thus the <bridge> element's stp and delay attributes are not allowed; no iptables rules, IP addresses, or DHCP/DNS services are added; at the IP level, the guest interface appears to be directly connected to the physical interface.Since 0.9.4
private
This network uses a macvtap "direct" connection in "private" mode to connect each guest to the network. The physical interface to be used will be picked from among those listed in <interface> subelements of the <forward> element; when using 802.1Qbh mode (as indicated by the <virtualport> type attribute - note that this requires an 802.1Qbh-capable hardware switch), each physical interface can only be in use by a single guest interface at a time; in modes other than 802.1Qbh, multiple guest interfaces can share each physical interface (libvirt will attempt to balance usage between all available interfaces).Since 0.9.4
vepa
This network uses a macvtap "direct" connection in "vepa" mode to connect each guest to the network (this requires that the physical interfaces used be connected to a vepa-capable hardware switch. The physical interface to be used will be picked from among those listed in <interface> subelements of the <forward> element; multiple guest interfaces can share each physical interface (libvirt will attempt to balance usage between all available interfaces).Since 0.9.4
passthrough
This network uses a macvtap "direct" connection in "passthrough" mode to connect each guest to the network (note that this is not the same thing as "PCI passthrough"). The physical interface to be used will be picked from among those listed in <interface> subelements of the <forward> element. Each physical interface can only be in use by a single guest interface at a time, so libvirt will keep track of which interfaces are currently in use, and only assign unused interfaces (if there are no available physical interfaces when a domain interface is being attached, an error will be logged, and the operation causing the attach will fail (usually either a domain start, or a hotplug interface attach to a domain).Since 0.9.4
As mentioned above, a <forward> element can have multiple <interface> subelements, each one giving the name of a physical interface that can be used for this network Since 0.9.4:
...
  <forward mode='passthrough'>
    <interface dev='eth10'/>
    <interface dev='eth11'/>
    <interface dev='eth12'/>
    <interface dev='eth13'/>
    <interface dev='eth14'/>
  </forward>
...
        

since 0.10.0, <interface> also has an optional read-only attribute - when examining the live configuration of a network, the attribute connections, if present, specifies the number of guest interfaces currently connected via this physical interface.

Additionally, since 0.9.10, libvirt allows a shorthand for specifying all virtual interfaces associated with a single physical function, by using the <pf> subelement to call out the corresponding physical interface associated with multiple virtual interfaces:

...
  <forward mode='passthrough'>
    <pf dev='eth0'/>
  </forward>
...
        

When a guest interface is being constructed, libvirt will pick an interface from this list to use for the connection. In modes where physical interfaces can be shared by multiple guest interfaces, libvirt will choose the interface that currently has the least number of connections. For those modes that do not allow sharing of the physical device (in particular, 'passthrough' mode, and 'private' mode when using 802.1Qbh), libvirt will choose an unused physical interface or, if it can't find an unused interface, fail the operation.

Quality of service
...
  <forward mode='nat' dev='eth0'/>
  <bandwidth>
    <inbound average='1000' peak='5000' burst='5120'/>
    <outbound average='128' peak='256' burst='256'/>
  </bandwidth>
...

This part of network XML provides setting quality of service. Incoming and outgoing traffic can be shaped independently. The bandwidth element can have at most one inbound and at most one outbound child elements. Leaving any of these children element out result in no QoS applied on that traffic direction. So, when you want to shape only network's incoming traffic, use inbound only, and vice versa. Each of these elements have one mandatory attribute average. It specifies average bit rate on interface being shaped. Then there are two optional attributes: peak, which specifies maximum rate at which bridge can send data, and burst, amount of bytes that can be burst at peak speed. Accepted values for attributes are integer numbers, The units for average and peak attributes are kilobytes per second, and for the burst just kilobytes. The rate is shared equally within domains connected to the network. Moreover, bandwidth element can be included in portgroup element. Since 0.9.4

Portgroups
...
  <forward mode='private'/>
    <interface dev="eth20"/>
    <interface dev="eth21"/>
    <interface dev="eth22"/>
    <interface dev="eth23"/>
    <interface dev="eth24"/>
  </forward>
  <portgroup name='engineering' default='yes'>
    <virtualport type='802.1Qbh'>
      <parameters profileid='test'/>
    </virtualport>
    <bandwidth>
      <inbound average='1000' peak='5000' burst='5120'/>
      <outbound average='1000' peak='5000' burst='5120'/>
    </bandwidth>
  </portgroup>
  <portgroup name='sales'>
    <virtualport type='802.1Qbh'>
      <parameters profileid='salestest'/>
    </virtualport>
    <bandwidth>
      <inbound average='500' peak='2000' burst='2560'/>
      <outbound average='128' peak='256' burst='256'/>
    </bandwidth>
  </portgroup>
...

Since 0.9.4 A portgroup provides a method of easily putting guest connections to the network into different classes, with each class potentially having a different level/type of service. Since 0.9.4 Each network can have multiple portgroup elements (and one of those can optionally be designated as the 'default' portgroup for the network), and each portgroup has a name, as well as various subelements associated with it. The currently supported subelements are <bandwidth> (documented here) and <virtualport> (documented here). If a domain interface definition specifies a portgroup (by adding a portgroup attribute to the <source> subelement), that portgroup's info will be merged into the interface's configuration. If no portgroup is given in the interface definition, and one of the network's portgroups has default='yes', that default portgroup will be used. If no portgroup is given in the interface definition, and there is no default portgroup, then none will be used. Any <bandwidth> specified directly in the domain XML will take precedence over any setting in the chosen portgroup. if a <virtualport> is specified in the portgroup (and/or directly in the network definition), the multiple virtualports will be merged, and any parameter that is specified in more than one virtualport, and is not identical, will be considered an error, and will prevent the interface from starting.

Addressing

The final set of elements define the addresses (IPv4 and/or IPv6, as well as MAC) to be assigned to the bridge device associated with the virtual network, and optionally enable DHCP services. These elements are only valid for isolated networks (no forward element specified), and for those with a forward mode of 'route' or 'nat'.

        ...
        <mac address='00:16:3E:5D:C7:9E'/>
        <domain name="example.com"/>
        <dns>
          <txt name="example" value="example value" />
          <srv service='name' protocol='tcp' domain='test-domain-name' target='.' port='1024' priority='10' weight='10'/>
          <host ip='192.168.122.2'>
            <hostname>myhost</hostname>
            <hostname>myhostalias</hostname>
          </host>
        </dns>
        <ip address="192.168.122.1" netmask="255.255.255.0">
          <dhcp>
            <range start="192.168.122.100" end="192.168.122.254" />
            <host mac="00:16:3e:77:e2:ed" name="foo.example.com" ip="192.168.122.10" />
            <host mac="00:16:3e:3e:a9:1a" name="bar.example.com" ip="192.168.122.11" />
          </dhcp>
        </ip>
        <ip family="ipv6" address="2001:db8:ca2:2::1" prefix="64" />
      </network>
mac
The address attribute defines a MAC (hardware) address formatted as 6 groups of 2-digit hexadecimal numbers, the groups separated by colons (eg, "52:54:00:1C:DA:2F"). This MAC address is assigned to the bridge device when it is created. Generally it is best to not specify a MAC address when creating a network - in this case, if a defined MAC address is needed for proper operation, libvirt will automatically generate a random MAC address and save it in the config. Allowing libvirt to generate the MAC address will assure that it is compatible with the idiosyncrasies of the platform where libvirt is running. Since 0.8.8
dns
The dns element of a network contains configuration information for the virtual network's DNS server. Since 0.9.3 Currently supported elements are:
txt
A dns element can have 0 or more txt elements. Each txt element defines a DNS TXT record and has two attributes, both required: a name that can be queried via dns, and a value that will be returned when that name is queried. names cannot contain embedded spaces or commas. value is a single string that can contain multiple values separated by commas. Since 0.9.3
host
The host element within dns is the definition of DNS hosts to be passed to the DNS service. The IP address is identified by the ip attribute and the names for that IP address are identified in the hostname sub-elements of the host element. Since 0.9.3
srv
The dns element can have also 0 or more srv record elements. Each srv record element defines a DNS SRV record and has 2 mandatory and 5 optional attributes. The mandatory attributes are service name and protocol (tcp, udp) and the optional attributes are target, port, priority, weight and domain as defined in DNS server SRV RFC (RFC 2782). Since 0.9.9
ip
The address attribute defines an IPv4 address in dotted-decimal format, or an IPv6 address in standard colon-separated hexadecimal format, that will be configured on the bridge device associated with the virtual network. To the guests this address will be their default route. For IPv4 addresses, the netmask attribute defines the significant bits of the network address, again specified in dotted-decimal format. For IPv6 addresses, and as an alternate method for IPv4 addresses, you can specify the significant bits of the network address with the prefix attribute, which is an integer (for example, netmask='255.255.255.0' could also be given as prefix='24'. The family attribute is used to specify the type of address - 'ipv4' or 'ipv6'; if no family is given, 'ipv4' is assumed. A network can have more than one of each family of address defined, but only a single address can have a dhcp or tftp element. Since 0.3.0; IPv6, multiple addresses on a single network, family, and prefix since 0.8.7
tftp
Immediately within the ip element there is an optional tftp element. The presence of this element and of its attribute root enables TFTP services. The attribute specifies the path to the root directory served via TFTP. tftp is not supported for IPv6 addresses, and can only be specified on a single IPv4 address per network. Since 0.7.1
dhcp
Also within the ip element there is an optional dhcp element. The presence of this element enables DHCP services on the virtual network. It will further contain one or more range elements. The dhcp element is not supported for IPv6, and is only supported on a single IP address per network for IPv4. Since 0.3.0
range
The start and end attributes on the range element specify the boundaries of a pool of IPv4 addresses to be provided to DHCP clients. These two addresses must lie within the scope of the network defined on the parent ip element. Since 0.3.0
host
Within the dhcp element there may be zero or more host elements; these specify hosts which will be given names and predefined IP addresses by the built-in DHCP server. Any such element must specify the MAC address of the host to be assigned a given name (via the mac attribute), the IP to be assigned to that host (via the ip attribute), and the name to be given that host by the DHCP server (via the name attribute). Since 0.4.5
bootp
The optional bootp element specifies BOOTP options to be provided by the DHCP server. Two attributes are supported: file is mandatory and gives the file to be used for the boot image; server is optional and gives the address of the TFTP server from which the boot image will be fetched. server defaults to the same host that runs the DHCP server, as is the case when the tftp element is used. The BOOTP options currently have to be the same for all address ranges and statically assigned addresses.Since 0.7.1 (server since 0.7.3).

Example configuration

NAT based network

This example is the so called "default" virtual network. It is provided and enabled out-of-the-box for all libvirt installations. This is a configuration that allows guest OS to get outbound connectivity regardless of whether the host uses ethernet, wireless, dialup, or VPN networking without requiring any specific admin configuration. In the absence of host networking, it at least allows guests to talk directly to each other.

      <network>
        <name>default</name>
        <bridge name="virbr0" />
        <forward mode="nat"/>
        <ip address="192.168.122.1" netmask="255.255.255.0">
          <dhcp>
            <range start="192.168.122.2" end="192.168.122.254" />
          </dhcp>
        </ip>
        <ip family="ipv6" address="2001:db8:ca2:2::1" prefix="64" />
      </network>

Routed network config

This is a variant on the default network which routes traffic from the virtual network to the LAN without applying any NAT. It requires that the IP address range be pre-configured in the routing tables of the router on the host network. This example further specifies that guest traffic may only go out via the eth1 host network device.

      <network>
        <name>local</name>
        <bridge name="virbr1" />
        <forward mode="route" dev="eth1"/>
        <ip address="192.168.122.1" netmask="255.255.255.0">
          <dhcp>
            <range start="192.168.122.2" end="192.168.122.254" />
          </dhcp>
        </ip>
        <ip family="ipv6" address="2001:db8:ca2:2::1" prefix="64" />
      </network>

Isolated network config

This variant provides a completely isolated private network for guests. The guests can talk to each other, and the host OS, but cannot reach any other machines on the LAN, due to the omission of the forward element in the XML description.

      <network>
        <name>private</name>
        <bridge name="virbr2" />
        <ip address="192.168.152.1" netmask="255.255.255.0">
          <dhcp>
            <range start="192.168.152.2" end="192.168.152.254" />
          </dhcp>
        </ip>
        <ip family="ipv6" address="2001:db8:ca2:3::1" prefix="64" />
      </network>

Using an existing host bridge

Since 0.9.4 This shows how to use a pre-existing host bridge "br0". The guests will effectively be directly connected to the physical network (i.e. their IP addresses will all be on the subnet of the physical network, and there will be no restrictions on inbound or outbound connections).

      <network>
        <name>host-bridge</name>
        <forward mode="bridge"/>
        <bridge name="br0"/>
      </network>

Using a macvtap "direct" connection

Since 0.9.4, QEMU and KVM only, requires Linux kernel 2.6.34 or newer This shows how to use macvtap to connect to the physical network directly through one of a group of physical devices (without using a host bridge device). As with the host bridge network, the guests will effectively be directly connected to the physical network so their IP addresses will all be on the subnet of the physical network, and there will be no restrictions on inbound or outbound connections. Note that, due to a limitation in the implementation of macvtap, these connections do not allow communication directly between the host and the guests - if you require this you will either need the attached physical switch to be operating in a mirroring mode (so that all traffic coming to the switch is reflected back to the host's interface), or provide alternate means for this communication (e.g. a second interface on each guest that is connected to an isolated network). The other forward modes that use macvtap (private, vepa, and passthrough) would be used in a similar fashion.

      <network>
        <name>direct-macvtap</name>
        <forward mode="bridge">
          <interface dev="eth20"/>
          <interface dev="eth21"/>
          <interface dev="eth22"/>
          <interface dev="eth23"/>
          <interface dev="eth24"/>
        </forward>
      </network>