Software & AppsOperating SystemLinux

How To Configure Multipass and Virt-Manager for Bridged Networking

Ubuntu 15

In this article, we will delve into the process of configuring Multipass and Virt-Manager for bridged networking. This setup is useful for creating virtual machines (VMs) that can interact with your host machine and other VMs on the same network.

Introduction to Multipass and Virt-Manager

Multipass is a lightweight VM manager that uses cloud images to simulate a fresh install of Ubuntu. It’s a great tool for developers who need to test their applications in a clean environment.

Virt-Manager is a desktop user interface for managing virtual machines. It primarily targets KVM VMs but also manages Xen and LXC (Linux Containers).

Prerequisites

Before we start, ensure that you have Multipass and Virt-Manager installed on your system. If not, you can install them using the following commands:

For Multipass:

sudo snap install multipass

For Virt-Manager:

sudo apt install virt-manager

Step 1: Create a Bridged Ethernet Interface

First, we need to create a bridged Ethernet interface on your host machine. This interface will allow your VMs to communicate with your host machine and other VMs on the same network.

You can create a bridged interface (e.g., br0) using the nm-connection-editor tool. Open a terminal and run the following command:

nm-connection-editor

In the Network Connections window, click on the “+” button to add a new connection. Select “Bridge” from the list and click on “Create”. Name the bridge (e.g., br0) and add your Ethernet interface to the bridge.

Step 2: Set the Local Driver for Multipass

Next, we need to set the local driver for Multipass to libvirt. This can be done by running the following command:

sudo multipass set local.driver=libvirt

In this command, set is used to modify the Multipass configuration. local.driver=libvirt tells Multipass to use the libvirt driver.

Step 3: Create a Multipass Instance

Now, let’s create a Multipass instance using the multipass launch command:

multipass launch --name vm01

In this command, launch is used to create a new VM. --name vm01 specifies the name of the VM.

Step 4: Create a New User

Log into the VM using the multipass connect command and create a new user (other than the default “ubuntu” user). Make the new user a member of sudo:

multipass connect vm01
sudo adduser newuser
sudo usermod -aG sudo newuser

Step 5: Install openssh-server

Next, install openssh-server on the VM using the virt-manager console. This will allow you to connect to the VM via SSH:

sudo apt install openssh-server

Step 6: Change the NIC in Virt-Manager

Shut down the VM and change the Network Interface Card (NIC) in virt-manager to the bridged Ethernet interface. To do this, open virt-manager, select your VM, and click on “Show virtual hardware details”. Then, select the NIC and change the “Device model” to “virtio” and the “Source device” to your bridged interface (e.g., br0).

Step 7: Restart the VM

Restart the VM, and it should receive an IP from your DHCP server and be directly accessible from other workstations or VMs on the network via SSH.

Step 8: Modify the VM’s Configuration File

After making these changes, the multipass connect method of connecting to the VM will no longer work. To address this, you can configure Multipass to use the new bridged interface by modifying the VM’s configuration file.

The configuration file for the VM can be found in the .multipass directory in your home directory. Look for a file named after your VM (e.g., vm01.yaml). Open this file in a text editor and locate the network section. Update the mode value to bridge and specify the name of your bridged interface (e.g., br0). Save the file and exit the text editor.

After modifying the configuration file, you should be able to use multipass connect vm01 to connect to the VM again.

Conclusion

Configuring Multipass and Virt-Manager for bridged networking may seem complex, but it’s a straightforward process once you understand the steps involved. This setup provides a flexible and efficient environment for testing and development. Happy coding!

What is the purpose of configuring Multipass and Virt-Manager for bridged networking?

Configuring Multipass and Virt-Manager for bridged networking allows virtual machines to communicate with the host machine and other virtual machines on the same network. This setup is useful for testing and development purposes, as it creates a more realistic and interconnected environment.

How can I install Multipass and Virt-Manager on my system?

To install Multipass, you can use the command sudo snap install multipass in the terminal. For Virt-Manager, you can use sudo apt install virt-manager. Make sure you have the appropriate package manager for your system (e.g., apt for Ubuntu-based systems).

How do I create a bridged Ethernet interface on my host machine?

To create a bridged Ethernet interface, you can use the nm-connection-editor tool. Open a terminal and run nm-connection-editor. In the Network Connections window, click on the "+" button to add a new connection. Select "Bridge" from the list, name the bridge (e.g., br0), and add your Ethernet interface to the bridge.

How do I set the local driver for Multipass to libvirt?

You can set the local driver for Multipass to libvirt by running the command sudo multipass set local.driver=libvirt in the terminal. This command modifies the Multipass configuration to use the libvirt driver.

How can I change the Network Interface Card (NIC) in Virt-Manager?

In Virt-Manager, select your virtual machine, click on "Show virtual hardware details", and then select the NIC. Change the "Device model" to "virtio" and the "Source device" to your bridged Ethernet interface (e.g., br0).

How do I connect to the virtual machine after making the necessary changes?

After making the changes, you can connect to the virtual machine using multipass connect vm_name, where vm_name is the name of your virtual machine. This command will establish an SSH connection to the virtual machine.

How can I modify the VM’s configuration file to use the new bridged interface?

The VM’s configuration file can be found in the .multipass directory in your home directory. Look for a file named after your VM (e.g., vm01.yaml). Open this file in a text editor and locate the network section. Update the mode value to bridge and specify the name of your bridged interface (e.g., br0). Save the file and exit the text editor.

Can I use Multipass and Virt-Manager for other Linux distributions, not just Ubuntu?

Yes, you can use Multipass and Virt-Manager with other Linux distributions. However, the installation process may vary depending on the distribution. Make sure to consult the official documentation or resources specific to your distribution for installation instructions.

Leave a Comment

Your email address will not be published. Required fields are marked *