How To

How To Create Bridged Network in Libvirt

Setting up a bridge network in a virtualization environment is essential for enabling virtual machines (VMs) to communicate both with each other and with the external network. In Linux environments managed by Libvirt, this can be accomplished through XML-based configuration.

Original content from computingforgeeks.com - post 89291

Using XML not only ensures persistence across reboots but also provides a powerful and flexible way to define and manage network settings with precision and ease.

Step 1: Create XML Configuration File

Start be creating a new XML file for your bridge network, e.g., bridge-network.xml.

vim bridge-network.xml

Below is an example XML configuration:

  • Bridge without DHCP service. You will set IP address information manually on the instance.
<network>
  <name>br0</name>
  <forward mode='bridge'/>
  <bridge name='br0'/>
  <mtu size='1500'/>
</network>
  • Bridge with DHCP service – VMs will get IP allocations from defined IP block.
<network>
  <name>br0</name>
  <forward mode='bridge'/>
  <bridge name='br0'/>
  <ip address='192.168.10.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.10.20' end='192.168.10.200'/>
    </dhcp>
  </ip>
</network>
  • With DNS Forwarding. The DNS forwarders configured are google public ones.
<network>
  <name>br0</name>
  <forward mode='bridge'/>
  <bridge name='br0'/>
  <ip address='192.168.10.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.10.20' end='192.168.10.200'/>
    </dhcp>
  </ip>
  <dns>
    <forwarder addr='8.8.8.8'/>
    <forwarder addr='8.8.4.4'/>
  </dns>
</network>

Exaplanations:

  • In this example:
  • <name>: Specifies the name of the network.
  • <forward mode='bridge'/>: Indicates that the network operates in bridge mode.
  • <bridge name='br0'/>: Specifies the name of the bridge interface to use.
  • The other settings are for IP address, DHCP and DNS forwarders accordingly

Step 2: Define the Network in Libvirt

Use the virsh command to define the network with the XML configuration file.

virsh net-define bridge-network.xml

Step 3: Start and Autostart the Network

Use the commands below to start the network and set it to start automatically

virsh net-start br0
virsh net-autostart br0

Step 4: Verify the Network

List available networks in your KVM host by running the following commands

virsh net-list --all

To output the network information as an XML dump to stdout, use:

virsh net-dumpxml <network>
# Example virsh net-dumpxml br0

You can also get basic information about the network object.

virsh net-info <network>

By leveraging Libvirt’s XML configuration for bridge networking, administrators gain a reliable and scalable approach to connecting VMs. This method balances simplicity with fine-grained control, ensuring that virtualized environments remain both flexible and resilient to future changes.

Keep reading

Install KVM and Virt-Manager on Arch Linux Virtualization Install KVM and Virt-Manager on Arch Linux Install KVM on Debian 13 / Debian 12: Complete Guide KVM Install KVM on Debian 13 / Debian 12: Complete Guide Install VirtIO Drivers on Windows 11 and Server 2025: ISO and MSI KVM Install VirtIO Drivers on Windows 11 and Server 2025: ISO and MSI How to Install KVM on Fedora 45 / 44 with virt-manager Fedora How to Install KVM on Fedora 45 / 44 with virt-manager Black Friday Mini PC Deals: Proxmox, Local AI and Home Assistant AI Black Friday Mini PC Deals: Proxmox, Local AI and Home Assistant How To Create Vagrant Box from existing Virtualbox VM Vagrant How To Create Vagrant Box from existing Virtualbox VM

Leave a Comment

Press ESC to close