Product SiteDocumentation Site

2.57. net-create

Creates a running, transient virtual network, using settings from an XML file.
Usage
net-create --file file-name
Options
Name Required? Description
--file file-name
required
The full path (and file name) to an XML file containing the network settings required.
The word "--file" itself is optional.
Table 2.3. Options

Availability
Available from libvirt 0.2.0 onwards
Platform or Hypervisor specific notes
None yet
Examples
virsh # net-create /root/examplenetwork.xml
Creates a new, transient, virtual network using the settings from /root/examplenetwork.xml.
virsh # net-create --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:
<network>
  <name>examplenetwork</name>
  <bridge name="virbr100" />
  <forward mode="route" />
  <ip address="10.10.120.1" netmask="255.255.255.0" />
</network>
# 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-create /root/examplenetwork.xml
Network examplenetwork created from /root/examplenetwork.xml
Created. Now we confirm:
virsh # net-list
Name                 State      Autostart
-----------------------------------------
default              active     yes
examplenetwork       active     no
We check the details of the created 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
<network>
  <name>examplenetwork</name>
  <uuid>97ce3914-231e-4026-0a78-822e1e2e7226</uuid>
  <forward mode='route'/>
  <bridge name='virbr100' stp='on' delay='0' />
  <ip address='10.10.120.1' netmask='255.255.255.0'>
  </ip>
</network>
Then, after exiting virsh, we check how it appears to the host Linux OS:
# ifconfig virbr100
virbr100  Link encap:Ethernet  HWaddr 02:95:C3:06:A5:BF  
          inet addr:10.10.120.1  Bcast:10.10.120.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
          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