How to create network bridge and use it with QEMU/virt-manager
- User
How to create network bridge and use it with QEMU/virt-manager
- Assistant
How to create network bridge and use it with QEMU/virt-manager
Creating a network bridge and using it with QEMU/virt-manager can enable your virtual machines (VMs) to communicate with each other and with the outside network, as if they were physical machines on the same network. Below are the steps to create a network bridge and configure it for use with QEMU/virt-manager.
Make sure you have the necessary packages installed:
sudo apt update
sudo apt install bridge-utils qemu-kvm libvirt-daemon-system libvirt-clients virt-manager
Identify your Network Interface: First, determine the name of the network interface you want to bridge. You can list network interfaces with the following command:
ip a
Typically, the interface would be something like eth0, enp3s0, etc.
Edit Networking Configuration: Depending on your Linux distribution, you'll need to modify its network configuration files.
For Ubuntu/Debian (with Netplan):
If you're using Netplan, you'll generally find configuration files in /etc/netplan/. Edit or create a file named something like 01-netcfg.yaml.
network:
version: 2
renderer: networkd
ethernets:
enp3s0: # Replace with your network interface name
dhcp4: no
bridges:
br0:
interfaces: [enp3s0]
dhcp4: yes
addresses: []
Note: Ensure you replace enp3s0 with your actual interface name.
For CentOS/RHEL (with NetworkManager):
You can use nmcli commands to create a bridge.
nmcli connection add type bridge ifname br0
nmcli connection add type bridge-slave ifname enp3s0 master br0
nmcli connection modify br0 ipv4.method auto
nmcli connection up br0
nmcli connection up enp3s0
Apply Changes:
For Ubuntu/Debian with Netplan, apply your changes with
sudo netplan apply
For CentOS/RHEL, restart the network service or reboot your system.
Create and Configure a Bridge Network in libvirt:
Use the virsh command to define a network directly.
sudo virsh net-define --file /etc/libvirt/qemu/networks/default.xml
Create the file /etc/libvirt/qemu/networks/default.xml with the following content:
<network>
<name>bridge-net</name>
<bridge name='br0'/>
<mac address='52:54:00:xx:xx:xx'/>
</network>
Be sure to replace the MAC address with an appropriate one for your network.
Start and Autostart the Network:
sudo virsh net-start bridge-net
sudo virsh net-autostart bridge-net
Open virt-manager: Start the Virtual Machine Manager:
virt-manager
Edit VM settings: For each VM you want to connect to the bridge.
br0).Save the settings and start your VM.
Check VM's Network Connection: Once the VMs are started, they should be able to get IP addresses via DHCP from your network if configured properly. You can also assign static IPs if desired.
Test Connectivity: You can test the network by trying to ping the VMs from other machines on the same network.
If you prefer managing networks via the command line or scripts, you can replace the virt-manager steps with virsh commands to manage networking and VM configurations.
If you run into issues:
brctl show or ip a./var/log/libvirt/libvirtd.log.By following these steps, you should be able to set up a network bridge and use it with QEMU and virt-manager effectively.
Not yet included in a published release.