[libvirt-users] connecting host and guest vm using a dummy nic

Laine Stump laine at redhat.com
Wed May 2 14:56:51 UTC 2018


On 05/01/2018 12:12 PM, daggs wrote:
> 
> I want to see if I understood you correctly, I add:
> <interface type='ethernet'>
>    <model type='e1000'/>
> </interface>
> to the vm's xml, this will result in a new nic in the vm which and in the host which I can use by the host to request dhcp from the router within the vm?
> 


Yes. As long as the emulated device in the guest is listening for DHCP
on that interface.

Also, note that (as long as your libvirt is at least version 2.1.0) if
you don't want to bother doing dhcp on the host and guest, you can
assign just a static IP address for the host side of that interface in
the libvirt XML like this:


  <interface type='ethernet'>
    <source>
       <ip address='192.168.254.2'/>
    </source>
    ...

You can even specify routes to be added automatically to the host when
that guest is started, e.g.:


  <interface type='ethernet'>
    <source>
       <ip address='192.168.254.2'/>
       <route family='ipv4' address='0.0.0.0' prefix='0'
              gateway='192.168.254.1' metric='1'/>
    </source>
    ...

(this assumes that on the guest side, the OS has configured the emulated
ethernet device to have address 192.168.254.1). This can be useful if
you want the host to use one path for traffic when the guest isn't
running, but switch when the guest *is* running. (In this case, if you
can set the default route on the host to have a metric of 2 or higher,
then the default route that goes through the guest would be preferred
when present).

(NB: if you read the documentation for configuring interfaces at
https://libvirt.org/formatdomain.html#ipconfig you'll see references on
how to configure the IP address of the *guest* in libvirt's xml. Note
that this *does not work* for qemu, but only for lxc (and possibly xen,
I don't recall right now). This is a limitation of the way that qemu/kvm
works (the fact that all guest-side IP info is configured in the guest
OS, and libvirt has no reasonable to get to it).)




More information about the libvirt-users mailing list