Product SiteDocumentation Site

2.58. net-define

Adds a new persistent virtual network to libvirt, without starting it, using settings from an XML file.
You will need to manually start this virtual network when needed using net-start, unless you enable automatic starting for it. If you enable automatic starting, the virtual network will be started when the libvirt daemon starts.
To enable automatic starting of this virtual network, use the net-autostart command.
net-define --file file-name
Name Required? Description
--file file-name
The full path (and file name) to an XML file containing the network settings required.
The word "--file" itself is optional.
Table 2.4. Options

Available from libvirt 0.2.0 onwards
Platform or Hypervisor specific notes
None yet
virsh # net-define /root/examplenetwork.xml
Creates a new, persistent, virtual network using the settings from the XML file /root/examplenetwork.xml.
virsh # net-define --file /root/examplenetwork.xml
Same as the above example.
Example in context
Starting with an XML file we've already created, using the required XML format:
  <bridge name="virbr100" />
  <forward mode="route" />
  <ip address="" netmask="" />
# ls -al /root/examplenetwork.xml
-rw-r--r--. 1 root root 162 Nov  7 16:43 /root/examplenetwork.xml
We start virsh interactively, then create the transient virtual network:
# virsh
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit
virsh # net-list
Name                 State      Autostart
default              active     yes
virsh # net-define /root/examplenetwork.xml
Network examplenetwork defined from /root/examplenetwork.xml
Defined. Now we confirm:
virsh # net-list --all
Name                 State      Autostart
default              active     yes
examplenetwork       inactive   no
Newly defined virtual networks aren't automatically started, so we manually start it now:
virsh # net-start examplenetwork
Network examplenetwork started
virsh # net-list
Name                 State      Autostart
default              active     yes
examplenetwork       active     no
We check the details of the started network from virsh. This shows us the generated UUID, and anything else that may be in effect (ie Spanning Tree Protocol).
virsh # net-dumpxml examplenetwork
  <forward mode='route'/>
  <bridge name='virbr100' stp='on' delay='0' />
  <ip address='' netmask=''>
If the virtualisation server is running Linux, we can check how it appears to the host OS:
# ifconfig virbr100
virbr100  Link encap:Ethernet  HWaddr A6:45:97:AE:8E:08  
          inet addr:  Bcast:  Mask:
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:11 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:2653 (2.5 KiB)
See also