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.
The root element required for all virtual networks is
named network
and has no attributes.
The network XML format is available since 0.3.0
The first elements provide basic metadata about the virtual network.
<network> <name>default</name> <uuid>3e3fce45-4f53-4fa7-bb32-11f34168b82b</uuid> ...
name
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.0uuid
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.0The 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"/> <forward mode="nat" dev="eth0"/> ...
bridge
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.
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
name
attribute on the domain
element
defines the DNS domain of the DHCP server. This element is optional.
Since 0.4.5
forward
forward
element indicates that
the virtual network is to be connected to the physical
LAN. the mode
attribute determines the method of
forwarding; possible selections are 'nat' and 'route'. If mode
is not specified, NAT forwarding will be used for
connectivity. If a network has any IPv6 addresses defined,
even if mode
is given as 'nat', the IPv6 traffic
will be forwarded using routing, since IPv6 has no concept of NAT.
Firewall rules will allow forwarding 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. If the mode
attribute is set to route
then the traffic will not have NAT applied. This presumes that the
local LAN router has suitable routing table entries to return traffic
to this host. Since 0.3.0; 'mode' attribute since
0.4.2The 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.
... <mac address='00:16:3E:5D:C7:9E'/> <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> </network>
mac
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
ip
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
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, can only be specified on a single IPv4 address
per network.
Since 0.7.1
dhcp
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
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
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
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).
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> </network>
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> </network>
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> </network>