formatnetwork.html.in 62.6 KB
Newer Older
1 2 3
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
4 5 6
  <body>
    <h1>Network XML format</h1>

7 8 9
    <ul id="toc">
    </ul>

D
Daniel P. Berrange 已提交
10
    <p>
11 12 13
      This page provides an introduction to the network XML format. For
      background information on the concepts referred to here, consult the
      <a href="https://wiki.libvirt.org/page/Networking">relevant wiki page</a>.
D
Daniel P. Berrange 已提交
14 15
    </p>

16
    <h2><a id="elements">Element and attribute overview</a></h2>
D
Daniel P. Berrange 已提交
17 18 19

    <p>
      The root element required for all virtual networks is
20 21 22 23 24 25 26 27
      named <code>network</code> and has no configurable attributes
      (although <span class="since">since 0.10.0</span> there is one
      optional read-only attribute - when examining the live
      configuration of a network, the
      attribute <code>connections</code>, if present, specifies the
      number of guest interfaces currently connected via this
      network).  The network XML format is
      available <span class="since">since 0.3.0</span>
D
Daniel P. Berrange 已提交
28 29
    </p>

30
    <h3><a id="elementsMetadata">General metadata</a></h3>
D
Daniel P. Berrange 已提交
31 32 33 34 35 36 37

    <p>
      The first elements provide basic metadata about the virtual
      network.
    </p>

    <pre>
38 39 40 41 42 43 44 45
&lt;network ipv6='yes' trustGuestRxFilters='no'&gt;
  &lt;name&gt;default&lt;/name&gt;
  &lt;uuid&gt;3e3fce45-4f53-4fa7-bb32-11f34168b82b&lt;/uuid&gt;
  &lt;metadata&gt;
    &lt;app1:foo xmlns:app1="http://app1.org/app1/"&gt;..&lt;/app1:foo&gt;
    &lt;app2:bar xmlns:app2="http://app1.org/app2/"&gt;..&lt;/app2:bar&gt;
  &lt;/metadata&gt;
  ...</pre>
D
Daniel P. Berrange 已提交
46 47 48 49

    <dl>
      <dt><code>name</code></dt>
      <dd>The content of the <code>name</code> element provides
M
Matthew Booth 已提交
50 51 52 53 54
        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. <span class="since">Since 0.3.0</span></dd>
D
Daniel P. Berrange 已提交
55 56
      <dt><code>uuid</code></dt>
      <dd>The content of the <code>uuid</code> element provides
M
Matthew Booth 已提交
57 58 59 60
        a globally unique identifier for the virtual network.
        The format must be RFC 4122 compliant, eg <code>3e3fce45-4f53-4fa7-bb32-11f34168b82b</code>.
        If omitted when defining/creating a new network, a random
        UUID is generated. <span class="since">Since 0.3.0</span></dd>
61 62 63 64 65 66
      <dd>The <code>metadata</code> node can be used by applications to
        store custom metadata in the form of XML nodes/trees. Applications
        must use custom namespaces on their XML nodes/trees, with only
        one top-level element per namespace (if the application needs
        structure, they should have sub-elements to their namespace
        element). <span class="since">Since 2.1.0</span></dd>
67 68 69
      <dt><code>ipv6</code></dt>
      <dd>When set to <code>yes</code>, the optional parameter
        <code>ipv6</code> enables
70 71 72 73
        a network definition with no IPv6 gateway addresses specified
        to have guest-to-guest communications.  For further information,
        see the example below for the example with no gateway addresses.
        <span class="since">Since 1.0.1</span></dd>
74
      <dt><code>trustGuestRxFilters</code></dt>
75 76 77 78
      <dd>The optional parameter <code>trustGuestRxFilters</code> can
        be used to set that attribute of the same name for each domain
        interface connected to this network (<span class="since">since
        1.2.10</span>). See
79
        the <a href="formatdomain.html#elementsNICS">Network
80 81 82 83
        interfaces</a> section of the domain XML documentation for
        more details. Note that an explicit setting of this attribute
        in a portgroup or the individual domain interface will
        override the setting in the network.</dd>
D
Daniel P. Berrange 已提交
84 85
    </dl>

86
    <h3><a id="elementsConnect">Connectivity</a></h3>
D
Daniel P. Berrange 已提交
87 88 89 90 91 92 93

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

    <pre>
94 95
...
&lt;bridge name="virbr0" stp="on" delay="5" macTableManager="libvirt"/&gt;
96
&lt;mtu size="9000"/&gt;
97 98 99
&lt;domain name="example.com" localOnly="no"/&gt;
&lt;forward mode="nat" dev="eth0"/&gt;
...</pre>
D
Daniel P. Berrange 已提交
100 101 102 103

    <dl>
      <dt><code>bridge</code></dt>
      <dd>The <code>name</code> attribute on the <code>bridge</code> element
M
Matthew Booth 已提交
104 105 106
        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
107
        may also be connected to the LAN. When defining
108
        a new network with a <code>&lt;forward&gt;</code> mode of
109

110
        "nat" or "route" (or an isolated network with
111 112 113 114 115 116 117 118
        no <code>&lt;forward&gt;</code> element), libvirt will
        automatically generate a unique name for the bridge device if
        none is given, and this name will be permanently stored in the
        network configuration so that that the same name will be used
        every time the network is started. For these types of networks
        (nat, routed, and isolated), a bridge name beginning with the
        prefix "virbr" is recommended (and that is what is
        auto-generated), but not enforced.
119 120 121 122
        Attribute <code>stp</code> specifies if Spanning Tree Protocol
        is 'on' or 'off' (default is
        'on'). Attribute <code>delay</code> sets the bridge's forward
        delay value in seconds (default is 0).
M
Matthew Booth 已提交
123
        <span class="since">Since 0.3.0</span>
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154

        <p>
          The <code>macTableManager</code> attribute of the bridge
          element is used to tell libvirt how the bridge's MAC address
          table (used to determine the correct egress port for packets
          based on destination MAC address) will be managed. In the
          default <code>kernel</code> setting, the kernel
          automatically adds and removes entries, typically using
          learning, flooding, and promiscuous mode on the bridge's
          ports in order to determine the proper egress port for
          packets.  When <code>macTableManager</code> is set
          to <code>libvirt</code>, libvirt disables kernel management
          of the MAC table (in the case of the Linux host bridge, this
          means enabling vlan_filtering on the bridge, and disabling
          learning and unicast_filter for all bridge ports), and
          explicitly adds/removes entries to the table according to
          the MAC addresses in the domain interface configurations.
          Allowing libvirt to manage the MAC table can improve
          performance - with a Linux host bridge, for example, turning
          off learning and unicast_flood on ports has its own
          performance advantage, and can also lead to an additional
          boost by permitting the kernel to automatically turn off
          promiscuous mode on some ports of the bridge (in particular,
          the port attaching the bridge to the physical
          network). However, it can also cause some networking setups
          to stop working (e.g. vlan tagging, multicast,
          guest-initiated changes to MAC address) and is not supported
          by older kernels.
          <span class="since">Since 1.2.11, requires kernel 3.17 or
          newer</span>
        </p>
155
      </dd>
156

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
      <dt><code>mtu</code></dt>
      <dd>
        The <code>size</code> attribute of the <code>mtu></code>
        element specifies the Maximum Transmission Unit (MTU) for the
        network. <span class="since">Since 3.1.0</span>. In the case
        of a libvirt-managed network (one with forward mode
        of <code>nat</code>, <code>route</code>, <code>open</code>, or
        no <code>forward</code> element (i.e. an isolated network),
        this will be the MTU assigned to the bridge device when
        libvirt creates it, and thereafter also assigned to all tap
        devices created to connect guest interfaces. Network types not
        specifically mentioned here don't support having an MTU set in
        the libvirt network config. If mtu size is unspecified, the
        default setting for the type of device being used is assumed
        (usually 1500).
D
Daniel P. Berrange 已提交
172
      </dd>
173

174 175
      <dt><code>domain</code></dt>
      <dd>
176 177 178 179 180 181
        The <code>name</code> attribute on the <code>domain</code>
        element defines the DNS domain of the DHCP server. This
        element is optional, and is only used for those networks with
        a <code>&lt;forward&gt;</code> mode of "nat" or "route" (or an
        isolated network with no <code>&lt;forward&gt;</code>
        element). <span class="since">Since 0.4.5</span>
182 183 184 185 186 187 188 189 190 191

        <p>
          If the optional <code>localOnly</code> attribute on the
          <code>domain</code> element is "yes", then DNS requests under
          this domain will only be resolved by the virtual network's own
          DNS server - they will not be forwarded to the host's upstream
          DNS server.  If <code>localOnly</code> is "no", and by
          default, unresolved requests <b>will</b> be forwarded.
          <span class="since">Since 1.2.12</span>
        </p>
192
      </dd>
D
Daniel P. Berrange 已提交
193 194
      <dt><code>forward</code></dt>
      <dd>Inclusion of the <code>forward</code> element indicates that
195
        the virtual network is to be connected to the physical
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
        LAN.<span class="since">Since 0.3.0.</span>
        The <code>mode</code> attribute determines the method of
        forwarding. If there is no <code>forward</code> 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 <code>mode</code> (if there is a <code>forward</code>
        element but mode is not specified, <code>mode='nat'</code> is
        assumed):
        <dl>
          <dt><code>nat</code></dt>
          <dd>
            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 <code>dev</code> 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.<span class="since">Since
            0.4.2</span>
227 228

            <p><span class="since">Since 1.0.3</span> it is possible to
229 230
            specify a public IPv4 address and port range to be used for
            the NAT by using the <code>&lt;nat&gt;</code> subelement.
J
Ján Tomko 已提交
231 232
            Note that all addresses from the range are used, not just those
            that are in use on the host.
233 234 235
            The address range is set with the <code>&lt;address&gt;</code>
            subelements and <code>start</code> and <code>stop</code>
            attributes:
J
Jiri Denemark 已提交
236
            </p>
237 238 239 240 241 242 243
            <pre>
...
  &lt;forward mode='nat'&gt;
    &lt;nat&gt;
      &lt;address start='1.2.3.4' end='1.2.3.10'/&gt;
    &lt;/nat&gt;
  &lt;/forward&gt;
J
Jiri Denemark 已提交
244 245
...</pre>
            <p>
J
Ján Tomko 已提交
246
            A single IPv4 address can be set by setting
247 248 249
            <code>start</code> and <code>end</code> attributes to
            the same value.
            </p>
250 251 252
            <p>
            The port range to be used for the <code>&lt;nat&gt;</code> can
            be set via the subelement <code>&lt;port&gt;</code>:
J
Jiri Denemark 已提交
253
            </p>
254 255 256 257 258 259 260
            <pre>
...
  &lt;forward mode='nat'&gt;
    &lt;nat&gt;
      &lt;port start='500' end='1000'/&gt;
    &lt;/nat&gt;
  &lt;/forward&gt;
J
Jiri Denemark 已提交
261
...</pre>
262 263 264 265 266 267 268 269 270 271
          </dd>

          <dt><code>route</code></dt>
          <dd>
            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 <code>dev</code>
            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
272 273 274 275 276 277
            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 <a href="formatnwfilter.html">nwfilter rules</a>
            on the guest's interfaces.)
            <span class="since">Since 0.4.2</span>
278 279
          </dd>

280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
          <dt><code>open</code></dt>
          <dd>
            As with mode='route', guest network traffic will be
            forwarded to the physical network via the host's IP
            routing stack, but there will be no firewall rules added
            to either enable or prevent any of this traffic. When
            forward='open' is set, the <code>dev</code> attribute
            cannot be set (because the forward dev is enforced with
            firewall rules, and the purpose of forward='open' is to
            have a forwarding mode where libvirt doesn't add any
            firewall rules).  This mode presumes that the local LAN
            router has suitable routing table entries to return
            traffic to this host, and that some other management
            system has been used to put in place any necessary
            firewall rules. Although no firewall rules will be added
            for the network, it is of course still possible to add
            restrictions for specific guests using
            <a href="formatnwfilter.html">nwfilter rules</a> on the
            guests' interfaces.)
            <span class="since">Since 2.2.0</span>
          </dd>

302 303 304 305 306
          <dt><code>bridge</code></dt>
          <dd>
            This network describes either 1) an existing host bridge
            that was configured outside of libvirt (if
            a <code>&lt;bridge name='xyz'/&gt;</code> element has been
307 308 309 310 311 312 313 314 315 316 317
            specified, <span class="since">Since 0.9.4</span>), 2) an
            existing Open vSwitch bridge that was configured outside of
            libvirt (if both a <code>&lt;bridge name='xyz'/&gt;</code>
            element <b>and</b> a <code>&lt;virtualport
            type='openvswitch'/&gt;</code> have been
            specified <span class="since">Since 0.10.0</span>) 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 <code>&lt;interface&gt;</code>
            subelements, <span class="since">Since 0.9.4</span>)
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
            (see <a href="formatdomain.html#elementsNICSDirect">Direct
            attachment to physical interface</a> for descriptions of
            the various macvtap modes). libvirt doesn't attempt to
            manage the bridge interface at all, thus
            the <code>&lt;bridge&gt;</code> element's <code>stp</code>
            and <code>delay</code> 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.<span class="since">Since 0.9.4</span>
          </dd>
          <dt><code>private</code></dt>
          <dd>
            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 <code>&lt;interface&gt;</code> subelements
            of the <code>&lt;forward&gt;</code> element; when using
            802.1Qbh mode (as indicated by
            the <code>&lt;virtualport&gt;</code> 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).<span class="since">Since
            0.9.4</span>
          </dd>
          <dt><code>vepa</code></dt>
          <dd>
            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 <code>&lt;interface&gt;</code> subelements of
            the <code>&lt;forward&gt;</code> element; multiple guest
            interfaces can share each physical interface (libvirt will
            attempt to balance usage between all available
            interfaces).<span class="since">Since 0.9.4</span>
          </dd>
          <dt><code>passthrough</code></dt>
          <dd>
            This network uses a macvtap "direct" connection in
            "passthrough" mode to connect each guest to the network
            (note that this is <i>not</i> the same thing as "PCI
            passthrough"). The physical interface to be used will be
            picked from among those listed
            in <code>&lt;interface&gt;</code> subelements of
            the <code>&lt;forward&gt;</code> 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).<span class="since">Since 0.9.4</span>
          </dd>
377 378 379 380 381 382 383 384 385 386 387 388 389 390
          <dt><code>hostdev</code></dt>
          <dd>
            This network facilitates PCI Passthrough of a network
            device.  A network device is chosen from the interface
            pool and directly assigned to the guest using generic
            device passthrough, after first optionally setting the
            device's MAC address and vlan tag to the configured value,
            and optionally associating the device with an 802.1Qbh
            capable switch using a <code>&lt;virtualport&gt;</code>
            element.  Note that - due to limitations in standard
            single-port PCI ethernet card driver design - only SR-IOV
            (Single Root I/O Virtualization) virtual function (VF)
            devices can be assigned in this manner; to assign a
            standard single-port PCI or PCIe ethernet card to a guest,
391
            use the traditional <code>&lt;hostdev&gt;</code> device
392 393
            definition. <span class="since"> Since 0.10.0</span>

394
            <p>
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
              To force use of a particular type of device assignment,
              a &lt;forward type='hostdev'&gt; interface can have an
              optional <code>driver</code> sub-element with
              a <code>name</code> attribute set to either "vfio" (VFIO
              is a new method of device assignment that is compatible
              with UEFI Secure Boot) or "kvm" (the legacy device
              assignment handled directly by the KVM kernel module)
              <span class="since">Since 1.0.5 (QEMU and KVM only,
              requires kernel 3.6 or newer)</span>. When specified,
              device assignment will fail if the requested method of
              device assignment isn't available on the host. When not
              specified, the default is "vfio" on systems where the
              VFIO driver is available and loaded, and "kvm" on older
              systems, or those where the VFIO driver hasn't been
              loaded <span class="since">Since 1.1.3</span> (prior to
              that the default was always "kvm").
411 412
            </p>

413 414
            <p>Note that this "intelligent passthrough" of network
            devices is very similar to the functionality of a
415
            standard <code>&lt;hostdev&gt;</code> device, the
416
            difference being that this method allows specifying a MAC
417
            address, vlan tag, and <code>&lt;virtualport&gt;</code>
418 419 420 421 422 423 424 425 426 427 428 429 430 431
            for the passed-through device. If these capabilities are
            not required, if you have a standard single-port PCI,
            PCIe, or USB network card that doesn't support SR-IOV (and
            hence would anyway lose the configured MAC address during
            reset after being assigned to the guest domain), or if you
            are using a version of libvirt older than 0.10.0, you
            should use a standard
            <code>&lt;hostdev&gt;</code> device definition in the
            domain's configuration to assign the device to the guest
            instead of defining an <code>&lt;interface
            type='network'&gt;</code> pointing to a network
            with <code>&lt;forward mode='hostdev'/&gt;</code>.
            </p>
          </dd>
432 433 434 435
        </dl>
        As mentioned above, a <code>&lt;forward&gt;</code> element can
        have multiple <code>&lt;interface&gt;</code> subelements, each
        one giving the name of a physical interface that can be used
L
Laine Stump 已提交
436
        for this network <span class="since">Since 0.9.4</span>:
437 438 439 440 441 442 443 444 445 446 447
        <pre>
...
  &lt;forward mode='passthrough'&gt;
    &lt;interface dev='eth10'/&gt;
    &lt;interface dev='eth11'/&gt;
    &lt;interface dev='eth12'/&gt;
    &lt;interface dev='eth13'/&gt;
    &lt;interface dev='eth14'/&gt;
  &lt;/forward&gt;
...
        </pre>
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
        <p>
          <span class="since">since 0.10.0</span>,
          <code>&lt;interface&gt;</code> also has an optional read-only
          attribute - when examining the live configuration of a
          network, the attribute <code>connections</code>, if present,
          specifies the number of guest interfaces currently connected
          via this physical interface.
        </p>
        <p>
          Additionally, <span class="since">since 0.9.10</span>, libvirt
          allows a shorthand for specifying all virtual interfaces
          associated with a single physical function, by using
          the <code>&lt;pf&gt;</code> subelement to call out the
          corresponding physical interface associated with multiple
          virtual interfaces:
        </p>
464 465 466 467 468 469 470 471 472
        <pre>
...
  &lt;forward mode='passthrough'&gt;
    &lt;pf dev='eth0'/&gt;
  &lt;/forward&gt;
...
        </pre>

        <p>When a guest interface is being constructed, libvirt will pick
473 474 475 476 477 478 479
        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
480
        or, if it can't find an unused interface, fail the operation.</p>
481 482 483 484 485

        <p>
          <span class="since">since 0.10.0</span> When using forward
          mode 'hostdev', the interface pool is specified with a list
          of <code>&lt;address&gt;</code> elements, each of which has
486
          <code>&lt;type&gt;</code> (must always be <code>'pci'</code>),
487
          <code>&lt;domain&gt;</code>, <code>&lt;bus&gt;</code>,
488
          <code>&lt;slot&gt;</code>and <code>&lt;function&gt;</code>
489 490 491 492 493
          attributes.
        </p>
        <pre>
...
  &lt;forward mode='hostdev' managed='yes'&gt;
494
    &lt;driver name='vfio'/&gt;
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
    &lt;address type='pci' domain='0' bus='4' slot='0' function='1'/&gt;
    &lt;address type='pci' domain='0' bus='4' slot='0' function='2'/&gt;
    &lt;address type='pci' domain='0' bus='4' slot='0' function='3'/&gt;
  &lt;/forward&gt;
...
        </pre>

        Alternatively the interface pool can also be defined using a
        single physical function  <code>&lt;pf&gt;</code> subelement to
        call out the  corresponding physical interface associated with
        multiple virtual interfaces (similar to passthrough mode):

        <pre>
...
  &lt;forward mode='hostdev' managed='yes'&gt;
    &lt;pf dev='eth0'/&gt;
  &lt;/forward&gt;
...
        </pre>

515
      </dd>
D
Daniel P. Berrange 已提交
516
    </dl>
517
    <h5><a id="elementQoS">Quality of service</a></h5>
518 519 520 521 522 523 524 525 526 527 528

<pre>
...
  &lt;forward mode='nat' dev='eth0'/&gt;
  <b>&lt;bandwidth&gt;
    &lt;inbound average='1000' peak='5000' burst='5120'/&gt;
    &lt;outbound average='128' peak='256' burst='256'/&gt;
  &lt;/bandwidth&gt;</b>
...</pre>

      <p>
529
        The <code>&lt;bandwidth&gt;</code> element allows setting
J
John Ferlan 已提交
530 531 532 533
        quality of service for a particular network
        (<span class="since">since 0.9.4</span>). Setting
        <code>bandwidth</code> for a network is supported only
        for networks with a <code>&lt;forward&gt;</code> mode
534
        of <code>route</code>, <code>nat</code>, or no mode at all
J
John Ferlan 已提交
535
        (i.e. an "isolated" network). Setting <code>bandwidth</code>
536 537
        is <b>not</b> supported for forward modes
        of <code>bridge</code>, <code>passthrough</code>, <code>private</code>,
J
John Ferlan 已提交
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
        or <code>hostdev</code>. Attempts to do this will lead to
        a failure to define the network or to create a transient network.
      </p>
      <p>
        The <code>&lt;bandwidth&gt;</code> element can only be a
        subelement of a domain's <code>&lt;interface&gt;</code>, a
        subelement of a <code>&lt;network&gt;</code>, or a subelement of
        a <code>&lt;portgroup&gt;</code> in a <code>&lt;network&gt;</code>.
      </p>
      <p>
        As a subelement of a domain's <code>&lt;interface&gt;</code>,
        the bandwidth only applies to that one interface of the domain.
        As a subelement of a <code>&lt;network&gt;</code>, the bandwidth
        is a total aggregate bandwidth to/from all guest interfaces attached
        to that network, <b>not</b> to each guest interface individually.
        If a domain's <code>&lt;interface&gt;</code> has
        <code>&lt;bandwidth&gt;</code> element values higher
        than the aggregate for the entire network, then the aggregate
        bandwidth for the <code>&lt;network&gt;</code> takes precedence.
        This is because the two choke points are independent of each other
        where the domain's <code>&lt;interface&gt;</code> bandwidth control
        is applied on the interface's tap device, while the
        <code>&lt;network&gt;</code> bandwidth control is applied on the
        interface part of the bridge device created for that network.
      </p>
      <p>
        As a subelement of a
        <code>&lt;portgroup&gt;</code> in a <code>&lt;network&gt;</code>,
        if a domain's <code>&lt;interface&gt;</code> has a
        <code>portgroup</code> attribute in its
        <code>&lt;source&gt;</code> element <b>and</b> if the
        <code>&lt;interface&gt;</code>
        itself has no <code>&lt;bandwidth&gt;</code> element, then the
        <code>&lt;bandwidth&gt;</code> element of the portgroup will be
        applied individually to each guest interface defined to be a
        member of that portgroup. Any <code>&lt;bandwidth&gt;</code>
        element in the domain's <code>&lt;interface&gt;</code> definition
        will override the setting in the portgroup
        (<span class="since">since 1.0.1</span>).
577 578 579
      </p>
      <p>
        Incoming and outgoing traffic can be shaped independently. The
J
John Ferlan 已提交
580 581
        <code>bandwidth</code> element can have at most one
        <code>inbound</code> and at most one <code>outbound</code>
582 583
        child element. Leaving either of these children elements out
        results in no QoS applied for that traffic direction.  So,
J
John Ferlan 已提交
584
        when you want to shape only incoming traffic, use
585
        <code>inbound</code> only, and vice versa. Each of these
J
John Ferlan 已提交
586 587 588
        elements have one mandatory attribute - <code>average</code> (or
        <code>floor</code> as described below). The attributes are as follows,
        where accepted values for each attribute is an integer number.
589
      </p>
J
John Ferlan 已提交
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
        <dl>
          <dt><code>average</code></dt>
          <dd>
          Specifies the desired average bit rate for the interface
          being shaped (in kilobytes/second).
          </dd>
          <dt><code>peak</code></dt>
          <dd>
          Optional attribute which specifies the maximum rate at
          which the bridge can send data (in kilobytes/second).
          Note the limitation of implementation: this attribute in the
          <code>outbound</code> element is ignored (as Linux ingress
          filters don't know it yet).
          </dd>
          <dt><code>burst</code></dt>
          <dd>
          Optional attribute which specifies the amount of kilobytes that
          can be transmitted in a single burst at <code>peak</code> speed.
          </dd>
          <dt><code>floor</code></dt>
          <dd>
          Optional attribute available only for the <code>inbound</code>
          element. This attribute guarantees minimal throughput for
          shaped interfaces. This, however, requires that all traffic
          goes through one point where QoS decisions can take place, hence
          why this attribute works only for virtual networks for now
          (that is <code>&lt;interface type='network'/&gt;</code> with a
          forward type of route, nat, or no forward at all). Moreover, the
          virtual network the interface is connected to is required to have
          at least inbound QoS set (<code>average</code> at least). If
          using the <code>floor</code> attribute users don't need to specify
          <code>average</code>. However, <code>peak</code> and
          <code>burst</code> attributes still require <code>average</code>.
          Currently, the Linux kernel doesn't allow ingress qdiscs to have
          any classes therefore <code>floor</code> can be applied only
          on <code>inbound</code> and not <code>outbound</code>.
          </dd>
        </dl>

629
      <p>
J
John Ferlan 已提交
630 631 632 633 634
        Attributes <code>average</code>, <code>peak</code>, and
        <code>burst</code> are available
        <span class="since">since 0.9.4</span>, while the
        <code>floor</code> attribute is available
        <span class="since">since 1.0.1</span>.
635
      </p>
D
Daniel P. Berrange 已提交
636

637
    <h5><a id="elementVlanTag">Setting VLAN tag (on supported network types only)</a></h5>
638 639

<pre>
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
&lt;network&gt;
  &lt;name&gt;ovs-net&lt;/name&gt;
  &lt;forward mode='bridge'/&gt;
  &lt;bridge name='ovsbr0'/&gt;
  &lt;virtualport type='openvswitch'&gt;
    &lt;parameters interfaceid='09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f'/&gt;
  &lt;/virtualport&gt;
  <b>&lt;vlan trunk='yes'&gt;</b>
    <b>&lt;tag id='42' nativeMode='untagged'/&gt;</b>
    <b>&lt;tag id='47'/&gt;</b>
  <b>&lt;/vlan&gt;</b>
  &lt;portgroup name='dontpanic'&gt;
    <b>&lt;vlan&gt;</b>
      <b>&lt;tag id='42'/&gt;</b>
    <b>&lt;/vlan&gt;</b>
  &lt;/portgroup&gt;
&lt;/network&gt;
</pre>
658 659

    <p>
660 661 662 663 664 665 666 667 668 669 670 671
      If (and only if) the network connection used by the guest
      supports VLAN tagging transparent to the guest, an
      optional <code>&lt;vlan&gt;</code> element can specify one or
      more VLAN tags to apply to the guest's network
      traffic <span class="since">Since 0.10.0</span>. Network
      connections that support guest-transparent VLAN tagging include
      1) type='bridge' interfaces connected to an Open vSwitch bridge
      <span class="since">Since 0.10.0</span>, 2) SRIOV Virtual
      Functions (VF) used via type='hostdev' (direct device
      assignment) <span class="since">Since 0.10.0</span>, and 3)
      SRIOV VFs used via type='direct' with mode='passthrough'
      (macvtap "passthru" mode) <span class="since">Since
672
      1.3.5</span>. All other connection types, including standard
673 674 675
      linux bridges and libvirt's own virtual networks, <b>do not</b>
      support it. 802.1Qbh (vn-link) and 802.1Qbg (VEPA) switches
      provide their own way (outside of libvirt) to tag guest traffic
676 677 678 679 680 681 682 683 684 685 686 687
      onto a specific VLAN. Each tag is given in a
      separate <code>&lt;tag&gt;</code> subelement
      of <code>&lt;vlan&gt;</code> (for example: <code>&lt;tag
      id='42'/&gt;</code>). For VLAN trunking of multiple tags (which
      is supported only on Open vSwitch connections),
      multiple <code>&lt;tag&gt;</code> subelements can be specified,
      which implies that the user wants to do VLAN trunking on the
      interface for all the specified tags. In the case that VLAN
      trunking of a single tag is desired, the optional
      attribute <code>trunk='yes'</code> can be added to the toplevel
      <code>&lt;vlan&gt;</code> element to differentiate trunking of a
      single tag from normal tagging.
688
    </p>
689
    <p>
690 691 692 693 694 695 696 697 698 699 700
      For network connections using Open vSwitch it is also possible
      to configure 'native-tagged' and 'native-untagged' VLAN modes
      <span class="since">Since 1.1.0.</span> This is done with the
      optional <code>nativeMode</code> attribute on
      the <code>&lt;tag&gt;</code> subelement: <code>nativeMode</code>
      may be set to 'tagged' or 'untagged'. The <code>id</code>
      attribute of the <code>&lt;tag&gt;</code> subelement
      containing <code>nativeMode</code> sets which VLAN is considered
      to be the "native" VLAN for this interface, and
      the <code>nativeMode</code> attribute determines whether or not
      traffic for that VLAN will be tagged.
701
    </p>
702 703 704 705 706 707 708 709 710 711 712 713 714
    <p>
      <code>&lt;vlan&gt;</code> elements can also be specified in
      a <code>&lt;portgroup&gt;</code> element, as well as directly in
      a domain's <code>&lt;interface&gt;</code> element. In the case
      that a vlan tag is specified in multiple locations, the setting
      in <code>&lt;interface&gt;</code> takes precedence, followed by
      the setting in the <code>&lt;portgroup&gt;</code> selected by
      the interface config. The <code>&lt;vlan&gt;</code>
      in <code>&lt;network&gt;</code> will be selected only if none is
      given in <code>&lt;portgroup&gt;</code>
      or <code>&lt;interface&gt;</code>.
    </p>

715
    <h5><a id="elementsPortgroup">Portgroups</a></h5>
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734

<pre>
...
  &lt;forward mode='private'/&gt;
    &lt;interface dev="eth20"/&gt;
    &lt;interface dev="eth21"/&gt;
    &lt;interface dev="eth22"/&gt;
    &lt;interface dev="eth23"/&gt;
    &lt;interface dev="eth24"/&gt;
  &lt;/forward&gt;
  <b>&lt;portgroup name='engineering' default='yes'&gt;
    &lt;virtualport type='802.1Qbh'&gt;
      &lt;parameters profileid='test'/&gt;
    &lt;/virtualport&gt;
    &lt;bandwidth&gt;
      &lt;inbound average='1000' peak='5000' burst='5120'/&gt;
      &lt;outbound average='1000' peak='5000' burst='5120'/&gt;
    &lt;/bandwidth&gt;
  &lt;/portgroup&gt;</b>
735
  <b>&lt;portgroup name='sales' trustGuestRxFilters='no'&gt;
736 737 738 739 740 741 742 743 744 745 746
    &lt;virtualport type='802.1Qbh'&gt;
      &lt;parameters profileid='salestest'/&gt;
    &lt;/virtualport&gt;
    &lt;bandwidth&gt;
      &lt;inbound average='500' peak='2000' burst='2560'/&gt;
      &lt;outbound average='128' peak='256' burst='256'/&gt;
    &lt;/bandwidth&gt;
  &lt;/portgroup&gt;</b>
...</pre>

    <p>
L
Laine Stump 已提交
747
      <span class="since">Since 0.9.4</span>
748 749
      A portgroup provides a method of easily putting guest
      connections to the network into different classes, with each
L
Laine Stump 已提交
750 751
      class potentially having a different level/type of service.
      <span class="since">Since 0.9.4</span> Each
752 753 754
      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
755
      attributes and subelements associated with it. The currently supported
756
      subelements are <code>&lt;bandwidth&gt;</code>
J
John Ferlan 已提交
757
      (described <a href="formatnetwork.html#elementQoS">here</a>)
758 759 760 761 762 763 764 765 766 767 768
      and <code>&lt;virtualport&gt;</code>
      (documented <a href="formatdomain.html#elementsNICSDirect">here</a>).
      If a domain interface definition specifies a portgroup (by
      adding a <code>portgroup</code> attribute to
      the <code>&lt;source&gt;</code> 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 <code>default='yes'</code>, 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 <code>&lt;bandwidth&gt;</code>
769 770 771 772 773 774 775 776 777

      specified directly in the domain XML will take precedence over
      any setting in the chosen portgroup. if
      a <code>&lt;virtualport&gt;</code> 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.
778
    </p>
779 780 781 782 783 784
    <p>
      portgroups also support the optional
      parameter <code>trustGuestRxFilters</code> which can be used to
      set that attribute of the same name for each domain interface
      using this portgroup (<span class="since">since
      1.2.10</span>). See
785
      the <a href="formatdomain.html#elementsNICS">Network
786 787 788 789 790 791
      interfaces</a> section of the domain XML documentation for more
      details. Note that an explicit setting of this attribute in the
      portgroup overrides the network-wide setting, and an explicit
      setting in the individual domain interface will override the
      setting in the portgroup.
    </p>
792

793
    <h5><a id="elementsStaticroute">Static Routes</a></h5>
794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
    <p>
      Static route definitions are used to provide routing information
      to the virtualization host for networks which are not directly
      reachable from the virtualization host, but *are* reachable from
      a guest domain that is itself reachable from the
      host <span class="since">since 1.0.6</span>.
    </p>

    <p>
      As shown in <a href="formatnetwork.html#examplesNoGateway">this
      example</a>, it is possible to define a virtual network
      interface with no IPv4 or IPv6 addresses.  Such networks are
      useful to provide host connectivity to networks which are only
      reachable via a guest.  A guest with connectivity both to the
      guest-only network and to another network that is directly
      reachable from the host can act as a gateway between the
      networks.  A static route added to the "host-visible" network
      definition provides the routing information so that IP packets
      can be sent from the virtualization host to guests on the hidden
      network.
    </p>

    <p>
      Here is a fragment of a definition which shows the static
      route specification as well as the  IPv4 and IPv6 definitions
      for network addresses which are referred to in the
      <code>gateway</code> gateway address specifications.  Note
      that the third static route specification includes the
      <code>metric</code> attribute specification with a value of 2.
      This particular route would *not* be preferred if there was
      another existing rout on the system with the same address and
      prefix but with a lower value for the metric. If there is a
826
      route in the host system configuration that should be overridden
827 828 829 830 831 832 833 834
      by a route in a virtual network whenever the virtual network is
      running, the configuration for the system-defined route should
      be modified to have a higher metric, and the route on the
      virtual network given a lower metric (for example, the default
      metric of "1").
    </p>

    <pre>
835 836 837
...
  &lt;ip address="192.168.122.1" netmask="255.255.255.0"&gt;
    &lt;dhcp&gt;
838
      &lt;range start="192.168.122.128" end="192.168.122.254"/&gt;
839 840
    &lt;/dhcp&gt;
  &lt;/ip&gt;
841 842
  &lt;route address="192.168.222.0" prefix="24" gateway="192.168.122.2"/&gt;
  &lt;ip family="ipv6" address="2001:db8:ca2:2::1" prefix="64"/&gt;
843
  &lt;route family="ipv6" address="2001:db8:ca2:3::" prefix="64" gateway="2001:db8:ca2:2::2"/&gt;
844
  &lt;route family="ipv6" address="2001:db9:4:1::" prefix="64" gateway="2001:db8:ca2:2::3" metric='2'/&gt;
845
...
846 847
    </pre>

848
    <h3><a id="elementsAddress">Addressing</a></h3>
D
Daniel P. Berrange 已提交
849 850

    <p>
851 852 853
      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
854 855 856
      services. These elements are only valid for isolated networks
      (no <code>forward</code> element specified), and for those with
      a forward mode of 'route' or 'nat'.
D
Daniel P. Berrange 已提交
857 858 859
    </p>

    <pre>
860 861 862 863
...
&lt;mac address='00:16:3E:5D:C7:9E'/&gt;
&lt;domain name="example.com"/&gt;
&lt;dns&gt;
864
  &lt;txt name="example" value="example value"/&gt;
865 866 867
  &lt;forwarder addr="8.8.8.8"/&gt;
  &lt;forwarder domain='example.com' addr="8.8.4.4"/&gt;
  &lt;forwarder domain='www.example.com'/&gt;
J
Jiri Denemark 已提交
868 869
  &lt;srv service='name' protocol='tcp' domain='test-domain-name' target='.'
    port='1024' priority='10' weight='10'/&gt;
870 871 872 873 874
  &lt;host ip='192.168.122.2'&gt;
    &lt;hostname&gt;myhost&lt;/hostname&gt;
    &lt;hostname&gt;myhostalias&lt;/hostname&gt;
  &lt;/host&gt;
&lt;/dns&gt;
875
&lt;ip address="192.168.122.1" netmask="255.255.255.0" localPtr="yes"&gt;
876
  &lt;dhcp&gt;
877 878 879
    &lt;range start="192.168.122.100" end="192.168.122.254"/&gt;
    &lt;host mac="00:16:3e:77:e2:ed" name="foo.example.com" ip="192.168.122.10"/&gt;
    &lt;host mac="00:16:3e:3e:a9:1a" name="bar.example.com" ip="192.168.122.11"/&gt;
880 881
  &lt;/dhcp&gt;
&lt;/ip&gt;
882
&lt;ip family="ipv6" address="2001:db8:ca2:2::1" prefix="64" localPtr="yes"/&gt;
883
&lt;route family="ipv6" address="2001:db9:ca1:1::" prefix="64" gateway="2001:db8:ca2:2::2"/&gt;
884
</pre>
D
Daniel P. Berrange 已提交
885 886

    <dl>
887 888 889 890 891 892 893 894 895 896 897 898 899 900
      <dt><code>mac</code></dt>
      <dd>The <code>address</code> attribute defines a MAC
        (hardware) address formatted as 6 groups of 2-digit
        hexadecimal numbers, the groups separated by colons
        (eg, <code>"52:54:00:1C:DA:2F"</code>).  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. <span class="since">Since 0.8.8</span>
      </dd>
901 902 903 904 905
      <dt><code>dns</code></dt>
      <dd> The dns element of a network contains configuration
        information for the virtual network's DNS
        server <span class="since">Since 0.9.3</span>.

906 907 908 909 910 911 912 913 914 915 916 917
        <p>
          The dns element can have an optional <code>enable</code>
          attribute <span class="since">Since 2.2.0</span>.
          If <code>enable</code> is "no", then no DNS server will be
          setup by libvirt for this network (and any other
          configuration in <code>&lt;dns&gt;</code> will be ignored).
          If <code>enable</code> is "yes" or unspecified (including
          the complete absence of any <code>&lt;dns&gt;</code>
          element) then a DNS server will be setup by libvirt to
          listen on all IP addresses specified in the network's
          configuration.
        </p>
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933
        <p>
          The dns element
          can have an optional <code>forwardPlainNames</code>
          attribute <span class="since">Since 1.1.2</span>.
          If <code>forwardPlainNames</code> is "no", then DNS resolution
          requests for names that are not qualified with a domain
          (i.e. names with no "." character) will not be forwarded to
          the host's upstream DNS server - they will only be resolved if
          they are known locally within the virtual network's own DNS
          server. If <code>forwardPlainNames</code> is "yes",
          unqualified names <b>will</b> be forwarded to the upstream DNS
          server if they can't be resolved by the virtual network's own
          DNS server.
        </p>

        Currently supported sub-elements of <code>&lt;dns&gt;</code> are:
934
        <dl>
935
          <dt><code>forwarder</code></dt>
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
          <dd>The dns element can have 0 or
            more <code>&lt;forwarder&gt;</code> elements.  Each
            forwarder element defines an alternate DNS server to use
            for some, or all, DNS requests sent to this network's DNS
            server. There are two attributes - <code>domain</code>,
            and <code>addr</code>; at least one of these must be
            specified in any <code>&lt;forwarder&gt;</code>
            element. If both <code>domain</code> and <code>addr</code>
            are specified, then all requests that match the given
            domain will be forwarded to the DNS server at addr. If
            only <code>domain</code> is specified, then all matching
            domains will be resolved locally (or via the host's
            standard DNS forwarding if they can't be resolved
            locally). If an <code>addr</code> is specified by itself,
            then all DNS requests to the network's DNS server will be
            forwarded to the DNS server at that address with no
            exceptions. <code>addr</code> <span class="since">Since
            1.1.3</span>, <code>domain</code> <span class="since">Since
            2.2.0</span>.
955
          </dd>
956 957 958 959 960 961 962 963
          <dt><code>txt</code></dt>
          <dd>A <code>dns</code> element can have 0 or more <code>txt</code> 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. <span class="since">Since 0.9.3</span>
          </dd>
964 965 966 967 968 969 970 971
          <dt><code>host</code></dt>
          <dd>The <code>host</code> element within <code>dns</code> is the
            definition of DNS hosts to be passed to the DNS service. The IP
            address is identified by the <code>ip</code> attribute and the names
            for that IP address are identified in the <code>hostname</code>
            sub-elements of the <code>host</code> element.
            <span class="since">Since 0.9.3</span>
          </dd>
972
        </dl>
973 974 975 976 977
        <dl>
          <dt><code>srv</code></dt>
          <dd>The <code>dns</code> element can have also 0 or more <code>srv</code>
            record elements. Each <code>srv</code> record element defines a DNS SRV record
            and has 2 mandatory and 5 optional attributes. The mandatory attributes
978 979 980 981
            are service <code>name</code> and <code>protocol</code> (tcp, udp)
            and the optional attributes are <code>target</code>,
            <code>port</code>, <code>priority</code>, <code>weight</code> and
            <code>domain</code> as defined in DNS server SRV RFC (RFC 2782).
982 983 984
            <span class="since">Since 0.9.9</span>
          </dd>
        </dl>
985
      </dd>
986 987
      <dt><code>ip</code></dt>
      <dd>The <code>address</code> attribute defines an IPv4 address in
988 989 990 991 992 993 994 995 996 997 998 999
        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 IPv4 address
        will be their IPv4 default route. For IPv6, the default route is
        established via Router Advertisement. For IPv4 addresses, the
        <code>netmask</code> 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, the
        significant bits of the network address can be specified with the
        <code>prefix</code> attribute, which is an integer (for example,
        <code>netmask='255.255.255.0'</code> could also be given as
        <code>prefix='24'</code>). The <code>family</code> attribute is used
1000
        to specify the type of address - <code>ipv4</code> or
1001 1002
        <code>ipv6</code>; if no <code>family</code> is given,
        <code>ipv4</code> is assumed. More than one address of each family can
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
        be defined for a network. The optional <code>localPtr</code> attribute
        (<span class="since">since 3.0.0</span>) configures the DNS server to
        not forward any reverse DNS requests for IP addresses from the network
        configured by the <code>address</code> and
        <code>netmask</code>/<code>prefix</code> attributes. For some unusual
        network prefixes (not divisible by 8 for IPv4 or not divisible by 4 for
        IPv6) libvirt may be unable to compute the PTR domain automatically.
        The <code>ip</code> element is supported <span class="since">since
        0.3.0</span>. IPv6, multiple addresses on a single network,
        <code>family</code>, and <code>prefix</code> are supported
        <span class="since">since 0.8.7</span>. The <code>ip</code> element may
        contain the following elements:
G
Gene Czarcinski 已提交
1015

1016 1017
        <dl>
          <dt><code>tftp</code></dt>
1018 1019 1020 1021 1022
          <dd>The optional <code>tftp</code> element and its mandatory
            <code>root</code> attribute enable TFTP services. The attribute
            specifies the path to the root directory served via TFTP. The
            <code>tftp</code> element is not supported for IPv6 addresses,
            and can only be specified on a single IPv4 address per network.
1023 1024 1025 1026
            <span class="since">Since 0.7.1</span>
          </dd>

          <dt><code>dhcp</code></dt>
1027 1028 1029 1030 1031 1032
          <dd>The presence of this element enables DHCP services on the
            virtual network. The <code>dhcp</code> element is supported for
            both IPv4 (<span class="since">since 0.3.0</span>) and IPv6
            (<span class="since">since 1.0.1</span>), but only for one IP
            address of each type per network. The following sub-elements are
            supported:
1033 1034 1035 1036
            <dl>
              <dt><code>range</code></dt>
              <dd>The <code>start</code> and <code>end</code> attributes on the
                <code>range</code> element specify the boundaries of a pool of
G
Gene Czarcinski 已提交
1037
                addresses to be provided to DHCP clients. These two addresses
1038
                must lie within the scope of the network defined on the parent
G
Gene Czarcinski 已提交
1039 1040 1041
                <code>ip</code> element.  There may be zero or more
                <code>range</code> elements specified.
                <span class="since">Since 0.3.0</span>
1042 1043
              </dd>
              <dt><code>host</code></dt>
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
              <dd>Within the <code>dhcp</code> element there may be zero or
                more <code>host</code> elements. These specify hosts which will
                be given names and predefined IP addresses by the built-in DHCP
                server. Any IPv4 <code>host</code> element must specify the MAC
                address of the host to be assigned a given name (via the
                <code>mac</code> attribute), the IP to be assigned to that host
                (via the <code>ip</code> attribute), and the name itself (the
                <code>name</code> attribute). The IPv6 <code>host</code>
                element differs slightly from that for IPv4: there is no
                <code>mac</code> attribute since a MAC address has no defined
                meaning in IPv6. Instead, the <code>name</code> attribute is
                used to identify the host to be assigned the IPv6 address. For
                DHCPv6, the name is the plain name of the client host sent by the
                client to the server. Note that this method of assigning a
                specific IP address can also be used for IPv4 instead of the
                <code>mac</code> attribute.
                <span class="since">Since 0.4.5</span>
1061 1062
              </dd>
              <dt><code>bootp</code></dt>
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
              <dd>The optional <code>bootp</code> element specifies BOOTP
                options to be provided by the DHCP server for IPv4 only. Two
                attributes are supported: <code>file</code> is mandatory and
                gives the file to be used for the boot image;
                <code>server</code> is optional and gives the address of the
                TFTP server from which the boot image will be fetched.
                <code>server</code> defaults to the same host that runs the
                DHCP server, as is the case when the <code>tftp</code> element
                is used. The BOOTP options currently have to be the same for
                all address ranges and statically assigned addresses. <span
                class="since">Since 0.7.1</span> (<code>server</code>
                <span class="since">since 0.7.3</span>)
1075 1076 1077 1078
              </dd>
            </dl>
          </dd>
        </dl>
1079
      </dd>
D
Daniel P. Berrange 已提交
1080
    </dl>
1081

1082
    <h2><a id="examples">Example configuration</a></h2>
1083

1084
    <h3><a id="examplesNAT">NAT based network</a></h3>
1085

D
Daniel P. Berrange 已提交
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
    <p>
      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.
    </p>

1096
    <pre>
1097 1098
&lt;network&gt;
  &lt;name&gt;default&lt;/name&gt;
1099
  &lt;bridge name="virbr0"/&gt;
1100 1101 1102
  &lt;forward mode="nat"/&gt;
  &lt;ip address="192.168.122.1" netmask="255.255.255.0"&gt;
    &lt;dhcp&gt;
1103
      &lt;range start="192.168.122.2" end="192.168.122.254"/&gt;
1104 1105
    &lt;/dhcp&gt;
  &lt;/ip&gt;
1106
  &lt;ip family="ipv6" address="2001:db8:ca2:2::1" prefix="64"/&gt;
1107
&lt;/network&gt;</pre>
1108

G
Gene Czarcinski 已提交
1109 1110 1111 1112 1113 1114 1115

    <p>
      Below is a variation of the above example which adds an IPv6
      dhcp range definition.
    </p>

    <pre>
1116 1117
&lt;network&gt;
  &lt;name&gt;default6&lt;/name&gt;
1118
  &lt;bridge name="virbr0"/&gt;
1119 1120 1121
  &lt;forward mode="nat"/&gt;
  &lt;ip address="192.168.122.1" netmask="255.255.255.0"&gt;
    &lt;dhcp&gt;
1122
      &lt;range start="192.168.122.2" end="192.168.122.254"/&gt;
1123 1124
    &lt;/dhcp&gt;
  &lt;/ip&gt;
1125
  &lt;ip family="ipv6" address="2001:db8:ca2:2::1" prefix="64"&gt;
1126
    &lt;dhcp&gt;
1127
      &lt;range start="2001:db8:ca2:2:1::10" end="2001:db8:ca2:2:1::ff"/&gt;
1128 1129 1130
    &lt;/dhcp&gt;
  &lt;/ip&gt;
&lt;/network&gt;</pre>
G
Gene Czarcinski 已提交
1131

1132
    <h3><a id="examplesRoute">Routed network config</a></h3>
1133

D
Daniel P. Berrange 已提交
1134 1135 1136 1137 1138 1139 1140 1141 1142
    <p>
      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
      <code>eth1</code> host network device.
    </p>

1143
    <pre>
1144 1145
&lt;network&gt;
  &lt;name&gt;local&lt;/name&gt;
1146
  &lt;bridge name="virbr1"/&gt;
1147 1148 1149
  &lt;forward mode="route" dev="eth1"/&gt;
  &lt;ip address="192.168.122.1" netmask="255.255.255.0"&gt;
    &lt;dhcp&gt;
1150
      &lt;range start="192.168.122.2" end="192.168.122.254"/&gt;
1151 1152
    &lt;/dhcp&gt;
  &lt;/ip&gt;
1153
  &lt;ip family="ipv6" address="2001:db8:ca2:2::1" prefix="64"/&gt;
1154
&lt;/network&gt;</pre>
1155

G
Gene Czarcinski 已提交
1156
    <p>
E
Eric Blake 已提交
1157
      Below is another IPv6 variation.  Instead of a dhcp range being
G
Gene Czarcinski 已提交
1158
      specified, this example has a couple of IPv6 host definitions.
1159 1160 1161 1162 1163
      Note that most of the dhcp host definitions use an "id" (client
      id or DUID) since this has proven to be a more reliable way
      of specifying the interface and its association with an IPv6
      address.  The first is a DUID-LLT, the second a DUID-LL, and
      the third a DUID-UUID.  <span class="since">Since 1.0.3</span>
G
Gene Czarcinski 已提交
1164 1165 1166
    </p>

    <pre>
1167 1168
&lt;network&gt;
  &lt;name&gt;local6&lt;/name&gt;
1169
  &lt;bridge name="virbr1"/&gt;
1170 1171 1172
  &lt;forward mode="route" dev="eth1"/&gt;
  &lt;ip address="192.168.122.1" netmask="255.255.255.0"&gt;
    &lt;dhcp&gt;
1173
      &lt;range start="192.168.122.2" end="192.168.122.254"/&gt;
1174 1175
    &lt;/dhcp&gt;
  &lt;/ip&gt;
1176
  &lt;ip family="ipv6" address="2001:db8:ca2:2::1" prefix="64"&gt;
1177
    &lt;dhcp&gt;
1178 1179 1180
      &lt;host name="paul" ip="2001:db8:ca2:2:3::1"/&gt;
      &lt;host id="0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66" ip="2001:db8:ca2:2:3::2"/&gt;
      &lt;host id="0:3:0:1:0:16:3e:11:22:33" name="ralph" ip="2001:db8:ca2:2:3::3"/&gt;
J
Jiri Denemark 已提交
1181 1182
      &lt;host id="0:4:7e:7d:f0:7d:a8:bc:c5:d2:13:32:11:ed:16:ea:84:63"
        name="badbob" ip="2001:db8:ca2:2:3::4"/&gt;
1183 1184 1185
    &lt;/dhcp&gt;
  &lt;/ip&gt;
&lt;/network&gt;</pre>
G
Gene Czarcinski 已提交
1186

1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
    <p>
      Below is yet another IPv6 variation.  This variation has only
      IPv6 defined with DHCPv6 on the primary IPv6 network.  A static
      link if defined for a second IPv6 network which will not be
      directly visible on the bridge interface but there will be a
      static route defined for this network via the specified
      gateway. Note that the gateway address must be directly
      reachable via (on the same subnet as) one of the &lt;ip&gt;
      addresses defined for this &lt;network&gt;.
      <span class="since">Since 1.0.6</span>
    </p>

    <pre>
1200 1201
&lt;network&gt;
  &lt;name&gt;net7&lt;/name&gt;
1202
  &lt;bridge name="virbr7"/&gt;
1203
  &lt;forward mode="route"/&gt;
1204
  &lt;ip family="ipv6" address="2001:db8:ca2:7::1" prefix="64"&gt;
1205
    &lt;dhcp&gt;
1206
      &lt;range start="2001:db8:ca2:7::100" end="2001:db8:ca2::1ff"/&gt;
J
Jiri Denemark 已提交
1207 1208
      &lt;host id="0:4:7e:7d:f0:7d:a8:bc:c5:d2:13:32:11:ed:16:ea:84:63"
        name="lucas" ip="2001:db8:ca2:2:3::4"/&gt;
1209 1210
    &lt;/dhcp&gt;
  &lt;/ip&gt;
1211
  &lt;route family="ipv6" address="2001:db8:ca2:8::" prefix="64" gateway="2001:db8:ca2:7::4"/&gt;
1212
&lt;/network&gt;</pre>
1213

1214
    <h3><a id="examplesPrivate">Isolated network config</a></h3>
1215

D
Daniel P. Berrange 已提交
1216 1217 1218 1219 1220 1221 1222 1223
    <p>
      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 <code>forward</code> element in the XML
      description.
    </p>

1224
    <pre>
1225 1226
&lt;network&gt;
  &lt;name&gt;private&lt;/name&gt;
1227
  &lt;bridge name="virbr2"/&gt;
1228 1229
  &lt;ip address="192.168.152.1" netmask="255.255.255.0"&gt;
    &lt;dhcp&gt;
1230
      &lt;range start="192.168.152.2" end="192.168.152.254"/&gt;
1231 1232
    &lt;/dhcp&gt;
  &lt;/ip&gt;
1233
  &lt;ip family="ipv6" address="2001:db8:ca2:3::1" prefix="64"/&gt;
1234
&lt;/network&gt;</pre>
1235

1236
    <h3><a id="examplesPrivate6">Isolated IPv6 network config</a></h3>
G
Gene Czarcinski 已提交
1237 1238 1239

    <p>
      This variation of an isolated network defines only IPv6.
1240 1241 1242 1243 1244
      Note that most of the dhcp host definitions use an "id" (client
      id or DUID) since this has proven to be a more reliable way
      of specifying the interface and its association with an IPv6
      address.  The first is a DUID-LLT, the second a DUID-LL, and
      the third a DUID-UUID.  <span class="since">Since 1.0.3</span>
G
Gene Czarcinski 已提交
1245 1246 1247
    </p>

    <pre>
1248 1249
&lt;network&gt;
  &lt;name&gt;sixnet&lt;/name&gt;
1250 1251
  &lt;bridge name="virbr6"/&gt;
  &lt;ip family="ipv6" address="2001:db8:ca2:6::1" prefix="64"&gt;
1252
    &lt;dhcp&gt;
1253 1254 1255
      &lt;host name="peter" ip="2001:db8:ca2:6:6::1"/&gt;
      &lt;host id="0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66" ip="2001:db8:ca2:6:6::2"/&gt;
      &lt;host id="0:3:0:1:0:16:3e:11:22:33" name="dariusz" ip="2001:db8:ca2:6:6::3"/&gt;
J
Jiri Denemark 已提交
1256 1257
      &lt;host id="0:4:7e:7d:f0:7d:a8:bc:c5:d2:13:32:11:ed:16:ea:84:63"
        name="anita" ip="2001:db8:ca2:6:6::4"/&gt;
1258 1259 1260
    &lt;/dhcp&gt;
  &lt;/ip&gt;
&lt;/network&gt;</pre>
G
Gene Czarcinski 已提交
1261

1262
    <h3><a id="examplesBridge">Using an existing host bridge</a></h3>
1263 1264

    <p>
L
Laine Stump 已提交
1265
      <span class="since">Since 0.9.4</span>
1266 1267 1268 1269 1270 1271 1272 1273
      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).
    </p>

    <pre>
1274 1275 1276 1277 1278
&lt;network&gt;
  &lt;name&gt;host-bridge&lt;/name&gt;
  &lt;forward mode="bridge"/&gt;
  &lt;bridge name="br0"/&gt;
&lt;/network&gt;</pre>
1279

1280
    <h3><a id="examplesDirect">Using a macvtap "direct" connection</a></h3>
1281 1282

    <p>
L
Laine Stump 已提交
1283 1284
      <span class="since">Since 0.9.4, QEMU and KVM only, requires
      Linux kernel 2.6.34 or newer</span>
1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
      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.
    </p>

    <pre>
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313
&lt;network&gt;
  &lt;name&gt;direct-macvtap&lt;/name&gt;
  &lt;forward mode="bridge"&gt;
    &lt;interface dev="eth20"/&gt;
    &lt;interface dev="eth21"/&gt;
    &lt;interface dev="eth22"/&gt;
    &lt;interface dev="eth23"/&gt;
    &lt;interface dev="eth24"/&gt;
  &lt;/forward&gt;
&lt;/network&gt;</pre>
1314

1315
    <h3><a id="examplesNoGateway">Network config with no gateway addresses</a></h3>
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327

    <p>
    A valid network definition can contain no IPv4 or IPv6 addresses.  Such a definition
    can be used for a "very private" or "very isolated" network since it will not be
    possible to communicate with the virtualization host via this network.  However,
    this virtual network interface can be used for communication between virtual guest
    systems.  This works for IPv4 and <span class="since">(Since 1.0.1)</span> IPv6.
    However, the new ipv6='yes' must be added for guest-to-guest IPv6
    communication.
    </p>

    <pre>
1328 1329 1330
&lt;network ipv6='yes'&gt;
  &lt;name&gt;nogw&lt;/name&gt;
  &lt;uuid&gt;7a3b7497-1ec7-8aef-6d5c-38dff9109e93&lt;/uuid&gt;
1331
  &lt;bridge name="virbr2" stp="on" delay="0"/&gt;
1332 1333
  &lt;mac address='00:16:3E:5D:C7:9E'/&gt;
&lt;/network&gt;</pre>
1334

1335 1336
  </body>
</html>