Can I have my KVM guests on the same subnet as the host?
Solution 1:
Process on Ubuntu 20.04:
Set up the logical network bridge on the host
Create /etc/netplan/01-kvmbridge.yaml
. Example:
network:
ethernets:
enp2s0f0:
dhcp4: false
bridges:
br0:
interfaces: [enp2s0f0]
dhcp4: true
mtu: 1500
parameters:
stp: true
forward-delay: 15
Notes: NIC name will differ depending on driver. Address assignment doesn't have to be by DHCP.
Run sudo netplan try
to test the config and sudo netplan apply
to apply it once you're satisfied it works. Note that changing a network config over ssh may not be a good idea.
Tell KVM how to access the connection
Create a file ~/kvmbridge.xml with the following contents:
<network>
<name>host-bridge</name>
<forward mode="bridge"/>
<bridge name="br0"/>
</network>
Enable the bridge:
virsh net-define ~/kvmbridge.xml
virsh net-start host-bridge
virsh net-autostart host-bridge
You should now be able to select the network host-bridge
for your VMs to have them coexist on the same network as the host.