Creating MacVTap interfaces to be used with KVM virtual machines

I’m using virsh manages, so let’s disable default networking

ShellScript
virsh net-list

You’re going to see default network enabled.
To disable that run

ShellScript
virsh net-destroy default
# and to disable on start-up
virsh net-autostart --network default --disable

# in case you want to enable it back
virsh net-start default

# to totally remove the network
virsh net-undefine default

That will remove virbr0 created by libvirt.
Now, we are going to create another libvirt network which then on new VM creation will be generating a macvtap and attach it to the VM.

Let’s create yaml file with network definition named macvtap-def.xml

TOML
<network>
  <name>macvtap-net</name>
  <forward mode="bridge">
    <interface dev="eno1"/>
  </forward>
</network>

You can change mode if you prefer another, also change dev to whatever you have.
Now, we can create a network based on that configuration with these commands

ShellScript
virsh net-define macvtap-def.xml
virsh net-autostart macvtap-net
virsh net-start macvtap-net

And when creating a VM with virt-install add the following

ShellScript
--network network=macvtap-net,model=virtio

That’s it!

P.S. My internet provider was not able to attach an IP to MAC address, MAC appeared and then disappeared. After netplan apply from virtual machine, he was able to attach IP to my MAC.


Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *