Can I have my KVM guests on the same subnet as the host?
Aug 23
Using virtual network "default" I get the guests on their own subnet, NAT'ed to the host's subnet.
Using a separate bridge, it seems possible to have guests on the same subnet as the host, but apparently this requires a dedicated physical nic on the host?
I have experimented with macvtap vepa or bridge, but could not get a link this way.
Is it possible to have the guests appear just like any other physical machine on the same subnet as the host? And if so, how? I need this as my application uses broadcast communication.
I am using QEMU/KVM, on rhel and ubuntu. Guests are also rhel or ubuntu. I define/manage the VMs using virt-install, virsh (and virt-manager for testing/debugging). The server does not have any extra nic's available for these purposes, only the one used by the host itself.
1 answer
Accepted answer · original discussion
Aug 23
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.
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
Aug 23