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.

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.

📖 This is just one chapter’s insight from Mastering KVM Virtualization. Get the full breakdown and unlock more advanced topics. Download the eBook.

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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here