Product SiteDocumentation Site

Chapter 7. Network Interfaces

7.1. Overview
7.2. XML Interface Description Format
7.3. Retrieving Information About Interfaces
7.3.1. Enumerating Interfaces
7.3.2. Alternative method of enumerating interfaces
7.3.3. Obtaining a virInterfacePtr for an Interface
7.3.4. Retrieving Detailed Interface Info
7.4. Managing interface configuration files
7.4.1. Defining an inteface configuration
7.4.2. Undefining an inteface configuration
7.5. Interface lifecycle management
7.5.1. Activating an interface
7.5.2. Activating an interface
7.6. Interface object memory management
This section covers the management of physical network interfaces using the libvirt API.

7.1. Overview

The configuration of network interfaces on physical hosts can be examined and modified with functions in the virInterface API. This is useful for setting up the host to share one physical interface bewteen multiple guest domains you want connected directly to the network (briefly - enslave a physical interface to the bridge, then create a tap device for each VM you want to share the interface), as well as for general host network interface management. In addition to physical hardware, this API can also be used to configure bridges, bonded interfaces, and vlan interfaces.
The virInterface API is *not* used to configure virtual networks (used to conceal the guest domain's interface behind a NAT); virtual networks are instead configured using the virNetwork API described in chapter 6.
Each host interface is represented in the API by a virInterfacePtr - a pointer to an "interface object" - and each of these has a single unique identifier:
name: a string unique among all interfaces (active or inactive) on a host. This is the same string used by the operating system to identify the interface (eg: "eth0" or "br1").
Each interface object also has a second, non-unique index that can be duplicated in other interfaces on the same host:
mac: an ASCII string representation of the MAC address of this interface. Since multiple interfaces can share the same MAC address (for example, in the case of VLANs), this is *not* a unique identifier. However, it can still be used to search for an interface.
All interfaces configured with libvirt should be considered as persistent, since libvirt is actually changing the host's own persistent configuration data (usually contained in files somewhere under /etc), and not the interface itself. However, there are API functions to start and stop interfaces, and those actions cause the new configuration to be applied to the interface immediately.
When a new interface is defined (with virInterfaceDefineXML), or the configuration of an existing interface is changed (again, with virInterfaceDefineXML), this configuration will be stored on the host, but the live configuration of the interface itself will not be changed until either the interface is started (with virInterfaceCreate), or the host is rebooted.