Linux – How to disable default DHCP on virbr0 and obtain IP from DHCP on host

dhcpdhcp-serverkvm-virtualizationlibvirtlinux

I have a Ubuntu Desktop, with Libvirt based Virtual Machines setup over
virbr0 bridge. Currently libvirt's default DHCP server (dnsmasq) provides
IP address assignments.

 root@ngadre-Inspiron-3542:/home/ngadre# virsh net-dumpxml default
<network>
  <name>default</name>
  <uuid>0cc9820a-aa74-4456-88e9-ee04256effcb</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:23:0b:1b'/>
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.122.2' end='192.168.122.254'/>
    </dhcp>
  </ip>
</network>

root@ngadre-Inspiron-3542:/home/ngadre/route-sim# brctl show virbr0
bridge name bridge id       STP enabled interfaces
virbr0      8000.525400230b1b   yes     virbr0-nic
                                         vnet0 --> NIC of VM connected to bridge

I have a dhcp server on my host ubuntu running on enp7s0

enp7s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b8:2a:72:cc:0a:db  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

I would like this DHCP server to provide IP to VM guests instead of the
libvirt default.

How to achieve this.

Best Answer

As mentioned in the comments.

It sounds like you need to bridge your VM network with the local physical ethernet device. Details about bridged networks can be found in the libvirt docs here

You can configure the guest to use the bridged interface with:

<interface type='bridge'>
  <source bridge='br0'/>
  <mac address='00:16:3e:1a:b3:4a'/>
  <model type='virtio'/>   # try this if you experience problems with VLANs
</interface>