Creating a Virtual/Fake Bridged Interface on a Debian VM using libvirt/kvm
In this article, we will discuss the process of creating a virtual/fake bridged interface on a Debian VM using libvirt/kvm. This is particularly useful when you want to set up a virtual network environment on a Debian VM, where your VMs can communicate with each other and the host machine.
Prerequisites
Before we begin, make sure you have a Debian server installed with libvirt/kvm enabled. Additionally, you should have created a VM using libvirt/kvm. In this example, we will assume that you have already created a VM and named it <VM-Name>.
Creating the Virtual Bridge
The first step in creating a virtual bridged interface is to create the virtual bridge itself. To do this, we will edit the <file system>/etc/network/interfaces file using a text editor of your choice. In this example, we will use the nano text editor.
sudo nano /etc/network/interfaces
Add the following lines to the end of the file:
auto vm-bridge
iface vm-bridge inet static
address 192.168.100.1
netmask 255.255.255.0
broadcast 192.168.100.255
In this example, we have assigned the IP address of 192.168.100.1 to the virtual bridge interface. You can adjust this IP address to fit your network environment.
Next, we need to add the following lines to the end of the <file system>/etc/network/interfaces file:
auto vmbr0
iface vmbr0 inet manual
bridge_ports none
bridge_stp off
bridge_fd 0
bridge_maxwait 0
In this example, we have named the virtual bridge interface vmbr0. You can adjust the name to fit your network environment.
Save and exit the file, then restart the networking service:
sudo systemctl restart networking
Adding the VM to the Virtual Bridge
Now that we have created the virtual bridge, we need to add our VM to it. To do this, we will edit the VM's XML configuration file.
First, list all the VMs:
virsh list --all
Then, edit the VM's XML configuration file using the following command:
virsh edit VM-Name
Find the following lines in the configuration file:
<interface type='network'/>
Replace them with the following lines:
<interface type='bridge'/>
<source bridge='vm-bridge'/>
<model type='virtio'/>
<driver name='qemu'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
<mac address='52:54:00:12:34:56'/>
<bandwidth>
<peak bandwidth='0'/>
<average bandwidth='0'/>
</bandwidth>
<boot order='1'/>
<alias name='net0'/>
</interface>
In this example, we have set the virtual interface type to bridge and specified the name of the virtual bridge we created earlier (vm-bridge). We have also specified the MAC address of the virtual interface. You can adjust these values to fit your network environment.
Save and exit the file, then restart the VM using the following command:
virsh start VM-Name
Verifying the Virtual Bridge and VM Interface
To verify that the virtual bridge and VM interface are working properly, you can run the following commands:
ip addr show vm-bridge
ip addr show VM-Name:0
The output should show that the vm-bridge interface has the IP address you assigned earlier, and the VM's interface has a different IP address in the same subnet.
- We discussed the process of creating a virtual/fake bridged interface on a Debian VM using libvirt/kvm.
- We created a virtual bridge interface named vmbr0 and assigned it the IP address of 192.168.100.1.
- We added our previously created VM to the virtual bridge interface by editing the VM's XML configuration file and specifying the name of the virtual bridge interface.
- We verified that the virtual bridge and VM interface are working properly by running the appropriate commands.
References
- Libvirt documentation: https://libvirt.org/
- KVM documentation: https://www.linux-kvm.org/page/Main_Page
- Debian networking documentation: https://wiki.debian.org/NetworkConfiguration