On 12/30/2013 11:25 AM, Andrew Martin wrote:> Is there a supported method for creating a fake network interface in a
VM's
> configuration file? I was using the below construct, however it is no
longer
> working for me in recent versions of libvirt (libvirt 1.0.2 with qemu-kvm
> 1.4.0).
I assume this wasn't working for you either because you previously had a
network named "fake" in your config, and that network wasn't
present
when you tested with the newer libvirt, or because the <address> element
created a conflict with an existing device on the same guest that was
already using the same slot?
> Is there a different, preferred method for creating a fake virtual
> interface on the guest which does not exist on the host?
> <interface type='network'>
> <mac address='aa:aa:aa:aa:aa:aa'/>
> <source network='fake'/>
> <address type='pci' domain='0x0000'
bus='0x00' slot='0x03'
> function='0x0'/>
> </interface>
On 01/14/2014 12:54 AM, Andrew Martin wrote:> I found the answer to this question:
> 1. create an XML file with a fake configuration (including a subnet not in
use elsewhere):
> <network>
> <name>fake</name>
> <bridge name='virbr1' stp='on' delay='0' />
> <ip address='192.168.0.1'
netmask='255.255.0.0'></ip>
> </network>
1) you don't need to (and probably shouldn't) specify the <bridge>
element when defining the new network - libvirt will autogenerate a
unique bridge name if one isn't provided, and stp defaults to on with a
delay of 0 anyway.
2) If this network is just a parking place, then you don't need to
specify an <ip> element either. This will save you from having an extra
dnsmasq instance started on the host to answer dns queries to
192.168.0.1 (and has the added advantage that a guest will be unable to
use this "parked" network connection to erroneously communicate with
the
host).
In other words, all you really need in the XML file is this:
<network>
<name>fake</name>
</network>
>
> 2. define the network: virsh net-define /path/to/fake.xml
> 3. autostart the network: virsh net-autostart fake
> 4. start the network now: virsh net-start fake
>
> Once done, you can add this block of XML to your VM config with "virsh
edit <vm_name>":
> <interface type='network'>
> <mac address='aa:aa:aa:aa:aa:aa'/>
> <source network='fake'/>
> <address type='pci' domain='0x0000'
bus='0x00' slot='0x03'
> function='0x0'/>
> </interface>
> Note that you should adjust the "slot" and "mac"
arguments to avoid conflicts.
It's actually easier and less error prone to just omit the <mac> and
<address> elements completely - libvirt will auto-generate
non-conflicting values for both if they aren't provided. So the
interface xml would look like this:
<interface type='network'>
<source network='fake'/>
</interface>
(you may want to add a <model type='virtio'/> to use a better
emulated
device than the default rtl8139).