How to create host-only adapter (like in VirtualBox) in Linux and use it with…
- User
How to create host-only adapter (like in VirtualBox) in Linux and use it with QEMU/virt-manager
- Assistant
How to create host-only adapter (like in VirtualBox) in Linux and use it with QEMU/virt-manager
Creating a host-only network adapter in Linux to be used with QEMU and Virt-Manager requires a few steps. The idea here is to create a bridge that only connects your host machine to the virtual machines without allowing outside network access.
Install Required Packages: Ensure QEMU, Virt-Manager, and bridge utilities are installed. You can install these on a Debian-based system (like Ubuntu) with:
sudo apt-get update
sudo apt-get install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager
Create a Bridge Interface: A bridge interface allows you to connect your VM's virtual NIC with the host's NIC.
Edit the network configuration file. Depending on your distribution, it might be:
/etc/network/interfaces/etc/netplan/*.yamlFor Debian/Ubuntu using /etc/network/interfaces:
sudo nano /etc/network/interfaces
Add the following lines to create a new bridge:
auto br0
iface br0 inet static
address 192.168.100.1
netmask 255.255.255.0
# For DHCP, you can set it up here (domain_name_server, etc.)
# Ensure no other interface uses this IP
For Netplan users (Ubuntu 18.04 and later):
Edit the YAML file in /etc/netplan/:
sudo nano /etc/netplan/01-netcfg.yaml
Add:
network:
version: 2
renderer: networkd
ethernets:
eth0: # Replace with your actual ethernet device name
dhcp4: no
dhcp6: no
bridges:
br0:
interfaces: [eth0]
addresses: [192.168.100.1/24]
optional: true
Apply these changes with sudo netplan apply.
Restart Networking: Now restart networking to apply the changes:
sudo systemctl restart networking
or, for systems using Netplan, just apply the changes with:
sudo netplan apply
Configure QEMU/KVM to Use the Bridge: When creating a new VM in Virt-Manager, select the bridge interface:
br0 or the name you gave your bridge.Connect the VM: After the VM is set up, make sure it can use the host-only network. When you start the VM, check its network configuration.
You can assign your VMs IP addresses in the range of 192.168.100.2 to 192.168.100.x where x is the maximum number of devices you want in that subnet.
Testing the Setup:
To test, you can start the VM and log into it. Try pinging the host's IP assigned to the bridge interface (e.g., 192.168.100.1) and vice versa.
Network Manager might be more graphical; you can manage the bridge through the GUI instead.This setup is very similar to VirtualBox's Host-Only Networks, allowing communication between the host and the VMs without any access to external networks.
Not yet included in a published release.