formatnetwork.html.in 41.6 KB
Newer Older
1 2 3 4
<html>
  <body>
    <h1>Network XML format</h1>

5 6 7
    <ul id="toc">
    </ul>

D
Daniel P. Berrange 已提交
8 9 10 11 12 13
    <p>
      This page provides an introduction to the network XML format. For background
      information on the concepts referred to here, consult the <a href="archnetwork.html">network driver architecture</a>
      page.
    </p>

14
    <h2><a name="elements">Element and attribute overview</a></h2>
D
Daniel P. Berrange 已提交
15 16 17

    <p>
      The root element required for all virtual networks is
18 19 20 21 22 23 24 25
      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 已提交
26 27
    </p>

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

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

    <pre>
36
      &lt;network ipv6='yes'&gt;
D
Daniel P. Berrange 已提交
37 38 39 40 41 42 43
        &lt;name&gt;default&lt;/name&gt;
        &lt;uuid&gt;3e3fce45-4f53-4fa7-bb32-11f34168b82b&lt;/uuid&gt;
        ...</pre>

    <dl>
      <dt><code>name</code></dt>
      <dd>The content of the <code>name</code> element provides
M
Matthew Booth 已提交
44 45 46 47 48
        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 已提交
49 50
      <dt><code>uuid</code></dt>
      <dd>The content of the <code>uuid</code> element provides
M
Matthew Booth 已提交
51 52 53 54
        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>
55 56 57 58 59 60
      <dt><code>ipv6='yes'</code></dt>
      <dd>The new, optional parameter <code>ipv6='yes'</code> enables
        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>
D
Daniel P. Berrange 已提交
61 62
    </dl>

63
    <h3><a name="elementsConnect">Connectivity</a></h3>
D
Daniel P. Berrange 已提交
64 65 66 67 68 69 70 71

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

    <pre>
        ...
72
        &lt;bridge name="virbr0" stp="on" delay="5"/&gt;
L
Laine Stump 已提交
73
        &lt;domain name="example.com"/&gt;
M
Matthew Booth 已提交
74 75
        &lt;forward mode="nat" dev="eth0"/&gt;
        ...</pre>
D
Daniel P. Berrange 已提交
76 77 78 79

    <dl>
      <dt><code>bridge</code></dt>
      <dd>The <code>name</code> attribute on the <code>bridge</code> element
M
Matthew Booth 已提交
80 81 82 83 84
        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 <code>vir</code>, but the name
85 86 87 88 89 90 91 92 93
        <code>virbr0</code> is reserved for the "default" virtual
        network.  This element should always be provided when defining
        a new network with a <code>&lt;forward&gt;</code> mode of
        "nat" or "route" (or an isolated network with
        no <code>&lt;forward&gt;</code> element).
        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 已提交
94
        <span class="since">Since 0.3.0</span>
D
Daniel P. Berrange 已提交
95
      </dd>
96 97
      <dt><code>domain</code></dt>
      <dd>
98 99 100 101 102 103
        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>
104
      </dd>
D
Daniel P. Berrange 已提交
105 106
      <dt><code>forward</code></dt>
      <dd>Inclusion of the <code>forward</code> element indicates that
107
        the virtual network is to be connected to the physical
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
        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>
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156

            <p><span class="since">Since 1.0.3</span> it is possible to
            specify a public IPv4 address range to be used for the NAT by
            using the <code>&lt;nat&gt;</code> and
            <code>&lt;address&gt;</code> subelements.
            <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;
...
            </pre>
            An singe IPv4 address can be set by setting
            <code>start</code> and <code>end</code> attributes to
            the same value.
            </p>
157 158 159 160 161 162 163 164 165 166
          </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
167 168 169 170 171 172
            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>
173 174 175 176 177 178 179
          </dd>

          <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
180 181 182 183 184 185 186 187 188 189 190
            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>)
191 192 193 194 195 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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
            (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>
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
          <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,
            use the traditional <code>&lt; hostdev&gt;</code> device
            definition. <span class="since"> Since 0.10.0</span>

            <p>Note that this "intelligent passthrough" of network
            devices is very similar to the functionality of a
            standard <code>&lt; hostdev&gt;</code> device, the
            difference being that this method allows specifying a MAC
            address, vlan tag, and <code>&lt;virtualport &gt;</code>
            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>
286 287 288 289
        </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 已提交
290
        for this network <span class="since">Since 0.9.4</span>:
291 292 293 294 295 296 297 298 299 300 301
        <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>
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
        <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>
318 319 320 321 322 323 324 325 326
        <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
327 328 329 330 331 332 333
        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
334
        or, if it can't find an unused interface, fail the operation.</p>
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

        <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
          <code>&lt; type&gt;</code> (must always be <code>'pci'</code>,
          <code>&lt;domain&gt;</code>, <code>&lt;bus&gt;</code>,
          <code>&lt;slot&gt;</code>, and <code>&lt;function&gt;</code>
          attributes.
        </p>
        <pre>
...
  &lt;forward mode='hostdev' managed='yes'&gt;
    &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>

368
      </dd>
D
Daniel P. Berrange 已提交
369
    </dl>
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
    <h5><a name="elementQoS">Quality of service</a></h5>

<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>
        This part of network XML provides setting quality of service. Incoming
        and outgoing traffic can be shaped independently. The
        <code>bandwidth</code> element can have at most one <code>inbound</code>
        and at most one <code>outbound</code> 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
        <code>inbound</code> only, and vice versa. Each of these elements have one
        mandatory attribute <code>average</code>. It specifies average bit rate on
        interface being shaped. Then there are two optional attributes:
        <code>peak</code>, which specifies maximum rate at which bridge can send
        data, and <code>burst</code>, amount of bytes that can be burst at
        <code>peak</code> speed. Accepted values for attributes are integer
        numbers, The units for <code>average</code> and <code>peak</code> attributes
        are kilobytes per second, and for the <code>burst</code> just kilobytes.
        The rate is shared equally within domains connected to the network.
397 398
        Moreover, <code>bandwidth</code> element can be included in
        <code>portgroup</code> element.
399 400
        <span class="since">Since 0.9.4</span>
      </p>
D
Daniel P. Berrange 已提交
401

402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
    <h5><a name="elementVlanTag">Setting VLAN tag (on supported network types only)</a></h5>

<pre>
  ...
  &lt;devices&gt;
    &lt;interface type='bridge'&gt;
      <b>&lt;vlan trunk='yes'&gt;</b>
        <b>&lt;tag id='42'/&gt;</b>
        <b>&lt;tag id='47'/&gt;</b>
      <b>&lt;/vlan&gt;</b>
      &lt;source bridge='ovsbr0'/&gt;
      &lt;virtualport type='openvswitch'&gt;
        &lt;parameters interfaceid='09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f'/&gt;
      &lt;/virtualport&gt;
    &lt;/interface&gt;
  &lt;devices&gt;
  ...</pre>

    <p>
      If (and only if) the network type 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
      traffic of all guests using this
      network <span class="since">Since 0.10.0</span>. (openvswitch
      and type='hostdev' SR-IOV networks do support transparent vlan
      tagging of guest traffic; everything else, including standard
      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
      onto specific vlans.) As expected, the <code>tag</code>
      attribute specifies which vlan tag to use. If a network has more
      than one <code>&lt;vlan&gt;</code> element defined, it is
      assumed that the user wants to do VLAN trunking using all the
      specified tags. In the case that vlan trunking with a single tag
      is desired, the optional attribute <code>trunk='yes'</code> can
      be added to the vlan element.
    </p>
    <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>

452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
    <h5><a name="elementsPortgroup">Portgroups</a></h5>

<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>
  <b>&lt;portgroup name='sales'&gt;
    &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 已提交
484
      <span class="since">Since 0.9.4</span>
485 486
      A portgroup provides a method of easily putting guest
      connections to the network into different classes, with each
L
Laine Stump 已提交
487 488
      class potentially having a different level/type of service.
      <span class="since">Since 0.9.4</span> Each
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
      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 <code>&lt;bandwidth&gt;</code>
      (documented <a href="formatdomain.html#elementQoS">here</a>)
      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>
506 507 508 509 510 511 512 513 514

      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.
515 516
    </p>

517
    <h3><a name="elementsAddress">Addressing</a></h3>
D
Daniel P. Berrange 已提交
518 519

    <p>
520 521 522
      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
523 524 525
      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 已提交
526 527 528 529
    </p>

    <pre>
        ...
530
        &lt;mac address='00:16:3E:5D:C7:9E'/&gt;
L
Laine Stump 已提交
531
        &lt;domain name="example.com"/&gt;
532 533
        &lt;dns&gt;
          &lt;txt name="example" value="example value" /&gt;
534
          &lt;srv service='name' protocol='tcp' domain='test-domain-name' target='.' port='1024' priority='10' weight='10'/&gt;
L
Laine Stump 已提交
535 536 537
          &lt;host ip='192.168.122.2'&gt;
            &lt;hostname&gt;myhost&lt;/hostname&gt;
            &lt;hostname&gt;myhostalias&lt;/hostname&gt;
M
Martin Kletzander 已提交
538
          &lt;/host&gt;
539
        &lt;/dns&gt;
M
Matthew Booth 已提交
540 541 542 543 544 545 546
        &lt;ip address="192.168.122.1" netmask="255.255.255.0"&gt;
          &lt;dhcp&gt;
            &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;
          &lt;/dhcp&gt;
        &lt;/ip&gt;
547
        &lt;ip family="ipv6" address="2001:db8:ca2:2::1" prefix="64" /&gt;
D
Daniel P. Berrange 已提交
548 549 550
      &lt;/network&gt;</pre>

    <dl>
551 552 553 554 555 556 557 558 559 560 561 562 563 564
      <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>
565 566 567 568 569 570 571 572 573 574 575 576 577
      <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>
        Currently supported elements are:
        <dl>
          <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>
578 579 580 581 582 583 584 585
          <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>
586
        </dl>
587 588 589 590 591 592 593 594 595 596 597
        <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
            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).
            <span class="since">Since 0.9.9</span>
          </dd>
        </dl>
598
      </dd>
599 600 601 602 603
      <dt><code>ip</code></dt>
      <dd>The <code>address</code> 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
G
Gene Czarcinski 已提交
604 605 606 607
        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>
608 609 610 611 612 613 614 615
        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 <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 to specify the type of address - 'ipv4' or 'ipv6'; if no
        <code>family</code> is given, 'ipv4' is assumed. A network can have more than
G
Gene Czarcinski 已提交
616 617
        one of each family of address defined, but only a single IPv4 address can have a
        <code>dhcp</code> or <code>tftp</code> element. <span class="since">Since 0.3.0 </span>
618
        IPv6, multiple addresses on a single network, <code>family</code>, and
G
Gene Czarcinski 已提交
619 620 621 622
        <code>prefix</code> are support <span class="since">Since 0.8.7</span>.
        Similar to IPv4, one IPv6 address per network can also have
        a <code>dhcp</code> definition.  <span class="since">Since 1.0.1</span>

623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
        <dl>
          <dt><code>tftp</code></dt>
          <dd>Immediately within
            the <code>ip</code> element there is an optional <code>tftp</code>
            element. The presence of this element and of its attribute
            <code>root</code> enables TFTP services.  The attribute specifies
            the path to the root directory served via TFTP. <code>tftp</code> is not
            supported for IPv6 addresses, and can only be specified on a single IPv4 address
            per network.
            <span class="since">Since 0.7.1</span>
          </dd>

          <dt><code>dhcp</code></dt>
          <dd>Also within the <code>ip</code> element there is an
            optional <code>dhcp</code> element. The presence of this element
            enables DHCP services on the virtual network. It will further
            contain one or more <code>range</code> elements. The
G
Gene Czarcinski 已提交
640 641 642 643
            <code>dhcp</code> element 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.
644 645 646 647
            <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 已提交
648
                addresses to be provided to DHCP clients. These two addresses
649
                must lie within the scope of the network defined on the parent
G
Gene Czarcinski 已提交
650 651 652 653 654
                <code>ip</code> element.  There may be zero or more
                <code>range</code> elements specified.
                <span class="since">Since 0.3.0</span>
                <code>range</code> can be specified for one IPv4 address,
                one IPv6 address, or both. <span class="since">Since 1.0.1</span>
655 656 657
              </dd>
              <dt><code>host</code></dt>
              <dd>Within the <code>dhcp</code> element there may be zero or more
G
Gene Czarcinski 已提交
658
                <code>host</code> elements.  These specify hosts which will be given
659
                names and predefined IP addresses by the built-in DHCP server. Any
G
Gene Czarcinski 已提交
660
                IPv4 <code>host</code> element must specify the MAC address of the host to be assigned
661 662 663 664
                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 to be given that host by the DHCP server (via the
                <code>name</code> attribute).  <span class="since">Since 0.4.5</span>
G
Gene Czarcinski 已提交
665 666 667 668 669 670 671 672
                An 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 instead of the <code>mac</code>
                attribute for IPv4.  <span class="since">Since 1.0.1</span>
673 674 675
              </dd>
              <dt><code>bootp</code></dt>
              <dd>The optional <code>bootp</code>
G
Gene Czarcinski 已提交
676 677
                element specifies BOOTP options to be provided by the DHCP
                server for IPv4 only.
678 679 680 681 682 683 684 685 686 687 688 689
                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 (<code>server</code> since 0.7.3).</span>
              </dd>
            </dl>
          </dd>
        </dl>
690
      </dd>
D
Daniel P. Berrange 已提交
691
    </dl>
692

693
    <h2><a name="examples">Example configuration</a></h2>
694

695
    <h3><a name="examplesNAT">NAT based network</a></h3>
696

D
Daniel P. Berrange 已提交
697 698 699 700 701 702 703 704 705 706
    <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>

707 708
    <pre>
      &lt;network&gt;
M
Matthew Booth 已提交
709 710 711 712 713 714 715 716
        &lt;name&gt;default&lt;/name&gt;
        &lt;bridge name="virbr0" /&gt;
        &lt;forward mode="nat"/&gt;
        &lt;ip address="192.168.122.1" netmask="255.255.255.0"&gt;
          &lt;dhcp&gt;
            &lt;range start="192.168.122.2" end="192.168.122.254" /&gt;
          &lt;/dhcp&gt;
        &lt;/ip&gt;
717
        &lt;ip family="ipv6" address="2001:db8:ca2:2::1" prefix="64" /&gt;
718 719
      &lt;/network&gt;</pre>

G
Gene Czarcinski 已提交
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742

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

    <pre>
      &lt;network&gt;
        &lt;name&gt;default6&lt;/name&gt;
        &lt;bridge name="virbr0" /&gt;
        &lt;forward mode="nat"/&gt;
        &lt;ip address="192.168.122.1" netmask="255.255.255.0"&gt;
          &lt;dhcp&gt;
            &lt;range start="192.168.122.2" end="192.168.122.254" /&gt;
          &lt;/dhcp&gt;
        &lt;/ip&gt;
        &lt;ip family="ipv6" address="2001:db8:ca2:2::1" prefix="64" &gt;
          &lt;dhcp&gt;
            &lt;range start="2001:db8:ca2:2:1::10" end="2001:db8:ca2:2:1::ff" /&gt;
          &lt;/dhcp&gt;
        &lt;/ip&gt;
      &lt;/network&gt;</pre>

743
    <h3><a name="examplesRoute">Routed network config</a></h3>
744

D
Daniel P. Berrange 已提交
745 746 747 748 749 750 751 752 753
    <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>

754 755
    <pre>
      &lt;network&gt;
M
Matthew Booth 已提交
756 757 758 759 760 761 762 763
        &lt;name&gt;local&lt;/name&gt;
        &lt;bridge name="virbr1" /&gt;
        &lt;forward mode="route" dev="eth1"/&gt;
        &lt;ip address="192.168.122.1" netmask="255.255.255.0"&gt;
          &lt;dhcp&gt;
            &lt;range start="192.168.122.2" end="192.168.122.254" /&gt;
          &lt;/dhcp&gt;
        &lt;/ip&gt;
764
        &lt;ip family="ipv6" address="2001:db8:ca2:2::1" prefix="64" /&gt;
765 766
      &lt;/network&gt;</pre>

G
Gene Czarcinski 已提交
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
    <p>
      Below is another IPv6 varition.  Instead of a dhcp range being
      specified, this example has a couple of IPv6 host definitions.
    </p>

    <pre>
      &lt;network&gt;
        &lt;name&gt;local6&lt;/name&gt;
        &lt;bridge name="virbr1" /&gt;
        &lt;forward mode="route" dev="eth1"/&gt;
        &lt;ip address="192.168.122.1" netmask="255.255.255.0"&gt;
          &lt;dhcp&gt;
            &lt;range start="192.168.122.2" end="192.168.122.254" /&gt;
          &lt;/dhcp&gt;
        &lt;/ip&gt;
        &lt;ip family="ipv6" address="2001:db8:ca2:2::1" prefix="64" &gt;
          &lt;dhcp&gt;
            &lt;host name="paul"   ip="2001:db8:ca2:2:3::1" /&gt;
            &lt;host name="bob"    ip="2001:db8:ca2:2:3::2" /&gt;
          &lt;/dhcp&gt;
        &lt;/ip&gt;
      &lt;/network&gt;</pre>

790
    <h3><a name="examplesPrivate">Isolated network config</a></h3>
791

D
Daniel P. Berrange 已提交
792 793 794 795 796 797 798 799
    <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>

800 801
    <pre>
      &lt;network&gt;
M
Matthew Booth 已提交
802 803 804 805 806 807 808
        &lt;name&gt;private&lt;/name&gt;
        &lt;bridge name="virbr2" /&gt;
        &lt;ip address="192.168.152.1" netmask="255.255.255.0"&gt;
          &lt;dhcp&gt;
            &lt;range start="192.168.152.2" end="192.168.152.254" /&gt;
          &lt;/dhcp&gt;
        &lt;/ip&gt;
809
        &lt;ip family="ipv6" address="2001:db8:ca2:3::1" prefix="64" /&gt;
810 811
      &lt;/network&gt;</pre>

G
Gene Czarcinski 已提交
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829
    <h3><a name="examplesPrivate6">Isolated IPv6 network config</a></h3>

    <p>
      This variation of an isolated network defines only IPv6.
    </p>

    <pre>
      &lt;network&gt;
        &lt;name&gt;sixnet&lt;/name&gt;
        &lt;bridge name="virbr6" /&gt;
        &lt;ip family="ipv6" address="2001:db8:ca2:6::1" prefix="64" &gt;
          &lt;dhcp&gt;
            &lt;host name="peter"   ip="2001:db8:ca2:6:6::1" /&gt;
            &lt;host name="dariusz" ip="2001:db8:ca2:6:6::2" /&gt;
          &lt;/dhcp&gt;
        &lt;/ip&gt;
      &lt;/network&gt;</pre>

830 831 832
    <h3><a name="examplesBridge">Using an existing host bridge</a></h3>

    <p>
L
Laine Stump 已提交
833
      <span class="since">Since 0.9.4</span>
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
      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>
      &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>

    <h3><a name="examplesDirect">Using a macvtap "direct" connection</a></h3>

    <p>
L
Laine Stump 已提交
851 852
      <span class="since">Since 0.9.4, QEMU and KVM only, requires
      Linux kernel 2.6.34 or newer</span>
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
      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>
      &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>

883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902
    <h3><a name="examplesNoGateway">Network config with no gateway addresses</a></h3>

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

903 904
  </body>
</html>