Bridge Networks For KVM On Ubuntu 22.04 Server

If you’ve been trying to create bridge networks for your virtual machines on KVM you may have stumbled upon a few roadblocks. With Ubuntu 20+ Server the default NetworkManager is replaced with the systemd-networkd. You can always install NetworkManager on your server but in this post we’ll describe how to create bridge networks using Netplan.

On earlier versions we were accustomed to using nmtui which is the frontend interface for the NetworkManager. However, if your system is using systemd-networkd the changes made using the nmtui interface have no effect. Netplan is the frontend tool for system-networkd and NetworkManager, and we’ll use it to create our bridge network.


The Network

We identify the ethernet interface on our system. This is usually the network interface that appears as eth0.

The enp0s31f6 network is a wired ethernet interface used by the device. If you notice the IP address for our device is 10.0.0.14.

So if you imagine a basic network it would look something like this when we begin.

We have our machine which is allocated an internal IP address which is 10.0.0.14. Our router which has a public IP address (111.125.213.119 in this case) and the server.

Now, when we make a request for a domain (www.google.com) to the router the router forwards the request by updating the source IP with it’s public IP. Similarly, when we get a response back, it updates the response where it replaces the response header with the destination IP instead of the routers public IP.

This way the request and response contain the IP addresses of our computer (10.0.0.14) and the destination server (142.250.199.174) of the domain we requested.

This translation of addresses is managed by what we call a NAT.


Virtual Routers and Switches

When we run KVM, libvirt and VirtManager, VirtManager handles the creation (via the libvirt APIs) of a virtual router and switch.

VirtManager > Virtual Networks lists the virtual networks in the system. On a fresh system this would contain a default network called “default”. This default network is managed by the default virtual router and switch which allocates IP addresses to the virtual machines and this router will manage the network address translation for all the request that flow from the machine with 10.0.0.14 to the virtual machines generated by it.

The ip addresses assigned to the virtual machines is managed by the DHCP service on the virtual router.

In this scenario all our virtual machine are accessible only via the our physical server on 10.0.0.14. If we want our virtual machines accessible publicly we’ll need a bridge network.


Bridge Networks

Our goal is to ensure that our virtual machines are accessible publicly just like that physical server for that we rearrange our network where the physical server (the host) is connected to the internet via a virtual switch.

What we’re doing here is creating a virtual networking interface which enslaves the physical ethernet interface and we’ll do this with netplan.

We jump to the /etc/netplan/ and replace the existing yaml file with this

Here we create a new bridge interface with the name bri0 and add the ethernet interface as a slave and run the following command for the changes to take effect.

$ sudo netplan apply

Now we check the network configuration on our system

We notice that our ethernet interface is enslaved and the bri0 network becomes the primary router.

Previous
Previous

Setup Hashicorp’s Nomad And Consul Using Ansible

Next
Next

Coreutils Feature Shorts - Automatic Budget Rollovers