Score:0

Loading a KVM guest with static IP using XML file

cn flag

I have an XML template for the image I am loading on KVM using ansible. For now, the image loads without IP. I would like to know if there is a way to add static IP on the XML template so that my VM loads with static IP on eth0 interface.

I tried the below in XML but it shows ERR "libvirtError: unsupported configuration: Invalid attempt to set network interface guest-side IP route and/or address info, not supported by QEMU"

<interface type='bridge'>
      <source bridge='veth0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
      <ip address='172.x.x.x' netmask='255.255.254.0' gateway='172.x.x.1' dns-nameserver='x.x.x.x'>
      </ip>
    </interface>

Please suggest a way, Thanks

in flag
It is up to guest OS to set guest IP, often that is done with DHCP, in bridged mode that DHCP would be your main DHCP, you could controll it based on MAC.
ranji avatar
cn flag
Hi, Thanks ! DHCP works. But in my case, I have deployed 50 VMs and each VM has multiple interfaces. So I am looking at if there is a way around to do this static IP setting using virsh command or using the template to reduce the work.
in flag
Not sure if I can explain it clearer, There is no way in virsh to configure "static ip" in guest. The closest is to have DHCP in guest, and then virsh/qemu can give out the configured IP to the guest by DHCP - however, since you are using bridged network virsh/qemu is no longer in control of the interface, and you need to configure this on your networks DHCP server - you can use the guests MAC address to do so.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.