Error when adding network interface to VM on KVM host using virsh
Since you already know the exact XML you want for the NIC, you should just avoid the virsh attach-interface
command and instead use virsh attach-device
. The attach-device
command accepts the full XML document directly for the new device. attach-interface
is just a dumb wrapper around attach-device
which generates XML for you. So since you have the XML already there's no point in using attach-interface
Related videos on Youtube
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on September 18, 2022Comments
-
Admin almost 2 years
I'm attempting to script adding a network interface to a centos 6 guest. I know the interface can be set up using the virt-manager gui but it's highly desirable for it to be added as part of an Ansible playbook using virsh attach-interface or alternatively as part of virt-install.
The desired interface should look like this (although with a new mac adress)
<interface type='direct'> <mac address='52:54:00:39:f8:3a'/> <source dev='enp3s0' mode='bridge'/> <target dev='macvtap8'/> <model type='virtio'/> <alias name='net0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface>
I have been unable to replicate this using virsh attach-interface or virt-install. I've tried using the following
virsh attach-interface 16 --type direct --source enp3s0 --model virtio --config --live
but this, unfortunately, doesn't set the source mode so I end up with the following interface
<interface type='direct'> <mac address='52:54:00:e1:d8:2c'/> <source dev='enp3s0' mode='vepa'/> <target dev='macvtap15'/> <model type='virtio'/> <alias name='net1'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/> </interface>
in an ideal world I would like to be able to do something like
virsh attach-interface 16 --type direct --source enp3s0 --model virtio --mode bridge --config --live
but this returns the following error and I can't find the correct option to specify for this operation.
error: command 'attach-interface' doesn't support option --mode
-
Admin over 7 yearsI never use macvtap, but actual Linux bridge. This makes VM setup a bit easier and more reliable, and you don't necessarily have to create a libvirt virtual network either.
-