1

Trying to create a KVM with MacVTap interface, but there is no ip assigned to it
Referring to these docs to create the kvm.

Followed the creation of network properly, i.e added interface in the domain XML, but no success in VM getting an IP address from the local network's DHCP

Here is the dumpxml of the kvm created:

<domain type='kvm' id='10'>
  <name>vm1</name>
  <uuid>08f1ffa4-7928-408e-962f-4918bc5aeea4</uuid>
  <memory unit='KiB'>1048576</memory>
  <currentMemory unit='KiB'>1048576</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <resource>
    <partition>/machine</partition>
  </resource>
  <os>
    <type arch='x86_64' machine='pc-i440fx-5.2'>hvm</type>
    <boot dev='hd'/>
  </os>
  <cpu mode='custom' match='exact' check='full'>
    <model fallback='forbid'>qemu64</model>
    <feature policy='require' name='x2apic'/>
    <feature policy='require' name='hypervisor'/>
    <feature policy='require' name='lahf_lm'/>
    <feature policy='disable' name='svm'/>
  </cpu>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/vm1.qcow2' index='1'/>
      <backingStore/>
      <target dev='vda' bus='virtio'/>
      <alias name='virtio-disk0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </disk>
    <controller type='usb' index='0' model='piix3-uhci'>
      <alias name='usb'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'>
      <alias name='pci.0'/>
    </controller>
    <interface type='direct'>
      <mac address='52:54:00:5a:ef:03'/>
      <source dev='wlp2s0' mode='bridge'/>
      <target dev='macvtap8'/>
      <model type='rtl8139'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </interface>
    <input type='mouse' bus='ps2'>
      <alias name='input0'/>
    </input>
    <input type='keyboard' bus='ps2'>
      <alias name='input1'/>
    </input>
    <audio id='1' type='none'/>
    <memballoon model='virtio'>
      <alias name='balloon0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </memballoon>
  </devices>
  <seclabel type='dynamic' model='apparmor' relabel='yes'>
    <label>libvirt-08f1ffa4-7928-408e-962f-4918bc5aeea4</label>
    <imagelabel>libvirt-08f1ffa4-7928-408e-962f-4918bc5aeea4</imagelabel>
  </seclabel>
  <seclabel type='dynamic' model='dac' relabel='yes'>
    <label>+64055:+108</label>
    <imagelabel>+64055:+108</imagelabel>
  </seclabel>
</domain>

I am currently on Ubuntu 22.04, and am using libvirt domain XML to create KVMs.
wlp2s0 provides internet to the host and also should be used for DHCP.

The end goal is to get the kvm to act like another machine on the local network that the host is connected to using MacVTap

Does anyone know what could be going wrong here?

  • Just having a quick look at your config, are you you trying to use a Wifi Interface as the master for the macvtap? My understanding, is that wifi interfaces can not have additional mac addresses. You could try promisc mode or monitor mode, but I believe the draw back with both modes with Wifi interfaces, is you wont be able to transmit, unless the device firmware allows it. I have not tried to use wifi with macvtap, this is all just theory. Hopefully osmeone who knows more about wifi and macvtaps combination can confirm. – Luke Attard Dec 07 '23 at 10:32
  • That's Right, I am using a Wi-Fi interface. Can you please explain why it differs from the wired one? Also, why do I need the master interface to be able to have additional Mac addresses? – swastik sarkar Dec 17 '23 at 14:41

1 Answers1

-2

mactapv is a special interface does not allow guest to host communication. So if your trying to obtain dhcp client ip in the same network as the host you need a bridged network adapter.

Else you can use mactapv to tunnel to another network with a dhcp service running in that network.

  • Macvtap, is a virtual layer 2 device, it has a unique mac address, and therefore can be on the same network as the host. As it is a layer2 device, it does not need to be assisgned an ip address in the host. As it is a layer2 device it can be used to give the guest access to dhcp if setup correctly. – Luke Attard Dec 07 '23 at 09:10
  • Are you suggesting to use a TUN interface? Please elaborate on your second point. @jezz-williams

    Can you please explain, what you mean by setup correctly? Isn't it just setting the network interface (associated with the network with DHCP) as the master ? @luke-attard

    – swastik sarkar Dec 17 '23 at 14:48
  • The macvtap driver isolates its traffic, so guest to guest cannot communicate to each other on the physical network. But i stand corrected on host to macvtap communication it can be achieved with additional configuration. My point was its easier to create a bridge network in netplan that allows host to guest communication than to setup additional routing for host to macvtap on the physical interface. If you create a bridge network then all guests and host on the bridge will be able to communicate. – Jezz Williams Dec 19 '23 at 23:26
  • In order for host to guest comms to work with macvtap driver the same network interface you need a physical switch that supports hairpin mode. Look up how to create a software bridge (br0) which can then be used for guests instead of eth1. Let me know if you are using netplan or networkmanager – Jezz Williams Dec 20 '23 at 09:29