2

I am trying to add fixed address to specific virtual host, therefor I closed virtual machine and used sudo virsh net-edit somenet. After adding line

<host mac='52:54:00:26:61:22' name='virt.example.com' ip='192.168.111.111' />

I saved and quit. Then I checked again with same command and previous state was restored, my changes were gone.

Same time, when I look into /etc/libvirt/qemu/networks/somenet.xml, my changes are applied.

If I start my virtual machine again, it gets IP from DHCP pool (192.168.111.170), but not the address I defined above.

When I restart libvirt-service after changes, situation seems same: in config file are my changes, with virsh I see vanilla state and virtual machine gets wrong IP.

What is wrong here?

Edit. Adding full XML here. Here is conf I see below /etc:

<network>
  <name>somenet</name>
  <uuid>80d85710-23bb-1ab6-79e6-cd65c6739714</uuid>
  <bridge name='virbr1' stp='on' delay='0' />
  <mac address='52:54:00:90:75:1A'/>
  <domain name='example.com'/>
  <ip address='192.168.111.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.111.100' end='192.168.111.254' />
      <host mac='52:54:00:26:61:22' name='virt.example.com' ip='192.168.111.111' />
    </dhcp>
  </ip>
</network>

Here is conf I see with virsh:

<network>
  <name>somenet</name>
  <uuid>80d85710-23bb-1ab6-79e6-cd65c6739714</uuid>
  <bridge name='virbr1' stp='on' delay='0' />
  <mac address='52:54:00:90:75:1A'/>
  <ip address='192.168.111.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.111.128' end='192.168.111.254' />
    </dhcp>
  </ip>
</network>
2
  • Post the complete XML here. – Michael Hampton Feb 3 '14 at 14:42
  • @MichaelHampton: posted. – wk. Feb 3 '14 at 15:32
12

Changes made to a network take place the next time the network is started. You need to perform this series of operations.

virsh net-edit somenet
virsh net-destroy somenet
virsh net-start somenet

For confirmation of this, see functionality of virsh net-edit

Note that restarting a network like this will terminate network connectivity for any VMs using this network. They won't regain connectivity when you start the network again; you have to restart the domains or manually move the VMs interface to the new bridge with brctl.

Edit: The libvirt wiki describes this situation and also points to a script to use to re-establish network connections.

2
  • So, do I understand it correctly: on the fly I can not add new fix-ip hosts to the working network without ruing others VM connections in same network? – wk. Feb 5 '14 at 9:47
  • Unfortunately, you're right. You can't do it. – sciurus Feb 5 '14 at 17:41
9

I did not found out "why", but I did find way to get it work. So, if anyone has same problem, solution was like that:

  • dumped network config with virsh net-dumpxml /tmp/somenet.xml
  • stopped network virsh net-destroy somenet
  • inactivated network virsh net-undefine somenet
  • made needed changes in /tmp/somenet.xml
  • created network again virsh net-create /tmp/somenet.xml
  • tried to set network autostarting virsh net-autostart somenet, but failed with error: Requested operation is not valid: cannot set autostart for transient network
  • found help on Thomas Schulte's blog (in German)
  • solution was to edit conf again and make some unsignificant change virsh net-edit somenet, I just added another empty line.
  • now virsh net-autostart somenet worked as well

And finally, my virtual host got right IP!

1
  • 2
    Wow, this worked. It's insane this is still a problem in 2019, and should be reported as a bug. – gertvdijk Apr 26 '19 at 13:19
3

Anytime that you use virsh net-edit {{network}} it will require you to restart the network. Therefore you would have to execute the commands:

virsh net-edit {{network}} virsh net-destroy {{network}} virsh net-start {{network}}

However

It is important to mention that every time that you do this anyone that currently uses that virtual-network on their VMS will loose connectivity while you are restarting the network.

It doesn't take more than seconds, but depending on the frequency in which you are adding static IP through DHCP-host this could cause an inconvenience for your users.

Therefore:

I would recommend using virsh net-update. (Source) This can be used to update the network configuration without having to restart the network. Specifically, it appears that you are looking for the ip-dhcp-host feature.

Example:

virsh net-update default add ip-dhcp-host \ "<host mac='52:54:00:00:00:01' \ name='bob' ip='192.168.122.45' />" \ --live --config

Hope this was helpful :)

1
  • Thank you for alternative after years, hope it will help other too! – wk. Oct 3 '17 at 17:46
2

The problem is that to create a persistent network you need to:

  1. create an XML definition of your network with you preferred editor
  2. sudo virsh net-define <XML file>
  3. sudo virsh net-start <net name>
  4. sudo virsh net-autostart <net name>

The error is to use net-create instead of net-define.

0

I had a similar problem, with a VM instance whose networking parameters had changed months ago. Today I restarted the whole 12-VMs environment, and this instance didn't want to start. The underlying hardware had been redefined, so it was out of question restoring the old values. Using virsh edit didn't help: the old parameter kept being reported & used to boot.

I found that during the reboot, the suspended image under /var/lib/libvirt/qemu/save/.save had the wrong parameters still embedded. Deleting the file allowed the VM to come back to life.

The only side effect is that the VM did not resume (as the rest of it siblings did), but had to do a full boot, and possibly that procedure was not very clean; fortunately it was a minor server that can afford this. After this, it is back on line & working fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.