If you’re using KVM (Kernel-based Virtual Machine) for virtualization on your Linux system, you’ll often need to configure a bridged network. A bridged network allows your virtual machines (VMs) to connect to the physical network as if they were directly connected, giving them access to the internet and other network services. In this guide, we’ll show you how to set up a bridged network for KVM on Arch Linux.
Before you begin, make sure you have the following installed and configured:
- Arch Linux: You’ll need a system running Arch Linux as the host operating system.
- KVM: Install KVM and its dependencies on your Arch Linux system. Follow this guide to set up KVM on Arch Linux.
- A working network connection: Ensure your Arch Linux system has a working network connection, either via Ethernet or Wi-Fi.
How to Set Up a Bridged Network for KVM
Install Necessary Packages
To set up a bridged network, you’ll need a few additional packages:
- bridge-utils: Provides tools for configuring and managing network bridges.
- dnsmasq: A lightweight DNS, DHCP, and TFTP server that we’ll use to provide IP addresses to the VMs.
Install these packages using the following command:
sudo pacman -S bridge-utils dnsmasq
Create the Network Bridge for KVM
First, let’s create a network bridge. In this example, we’ll use
br0 as the bridge name and
eno1 as the physical network interface connected to the host. Replace
eno1 with your network interface name if it’s different.
- Create a new file
/etc/systemd/network/br0.netdevand add the following configuration:
[NetDev] Name=br0 Kind=bridge
- Create another file
/etc/systemd/network/br0.networkwith the following content:
[Match] Name=br0 [Network] DHCP=yes
- Modify your existing network interface configuration by creating a file
/etc/systemd/network/eno1.networkwith the following content:
[Match] Name=eno1 [Network] Bridge=br0
- Restart the systemd-networkd service to apply the changes:
sudo systemctl restart systemd-networkd
- Enable the new bridge interface with the following command:
sudo ip link set br0 up
- Verify the bridge configuration by running
ip addr showand checking for the
Configure dnsmasq for DHCP and DNS Services
To provide IP addresses to the VMs and handle DNS requests, we’ll use dnsmasq. Create a new configuration file
/etc/dnsmasq.d/br0.conf with the following content:
interface=br0 dhcp-range=192.168.10.100,192.168.10.200,12h domain=example.lan
192.168.10.200 with the desired IP address range for your VMs, and
example.lan with your preferred domain name.
Restart the dnsmasq service to apply the changes:
sudo systemctl restart dnsmasq
- Enable the dnsmasq service to start automatically on boot:
sudo systemctl enable dnsmasq
Configure KVM to Use the Bridged Network
Now that we’ve set up the bridged network, we need to configure KVM to use it for the virtual machines.
- Edit the default KVM network configuration by opening
/etc/libvirt/qemu/networks/default.xmlin a text editor.
- Replace the existing configuration with the following content, which defines the
br0bridge as the default network for KVM:
<network> <name>default</name> <forward mode='bridge'/> <bridge name='br0'/> </network>
- Restart the libvirtd service to apply the changes:
sudo systemctl restart libvirtd
- Refresh the default network configuration in KVM:
sudo virsh net-destroy default sudo virsh net-define /etc/libvirt/qemu/networks/default.xml sudo virsh net-start default sudo virsh net-autostart default
Your KVM virtual machines will now use the
br0 bridged network by default, allowing them to communicate with the physical network as if they were directly connected.
Verify the Configuration
To verify that your KVM virtual machines are using the bridged network, create a new VM or start an existing one. Once the VM is up and running, check its network configuration to confirm that it has received an IP address from the
br0 bridge’s DHCP server (dnsmasq).
You can do this by logging into the VM and running the following command:
ip addr show
Look for an IP address in the range you specified in the dnsmasq configuration (e.g.,
192.168.10.200). If the VM has an IP address in this range, it’s using the bridged network.
Additionally, test the VM’s network connectivity by pinging external hosts or accessing the internet through a web browser. If the VM can connect to external hosts, your bridged network setup is successful.
In this guide, we’ve shown you how to set up a bridged network for KVM on Arch Linux. A bridged network allows your virtual machines to connect to the physical network as if they were directly connected, making it easier to manage and maintain network services for your VMs.
For more information on setting up and configuring KVM on Arch Linux, check out our other related guides: