The documentation recommends you do this using virsh net update
, but you'll need to read it very carefully to figure out exactly how -- because they provide you with only a
single example to work with.
Only the following virtual network components can be changed using net-update:
ip-dhcp-host
ip-dhcp-range (add/delete only, no modify)
forward-interface (add/delete only)
portgroup
dns-host
dns-txt
dns-srv
For example, to change the reserved IP address of a particular host from "192.168.122.45" to "192.168.122.48" on the "default" virtual network you'd do this:
virsh net-update default modify ip-dhcp-host \
"<host mac='52:54:00:00:00:01' \
name='myguest' ip='192.168.122.48' />" \
--live --config
So all it really does is replace XML for the section identified ("ip-dhcp-host" for a specific host) with the XML submitted.
For anything else, you're stuck with virsh net-edit
, which, although it has a nice ui (for me, vim),
will require restarting the modified libvirt network to take effect -- disconnecting any running hosts
and requiring that they get rebooted (sure, you could go in and cycle systemd-networkd, but really?).
If you do need to go the more disruptive route, the process is:
$ virsh net-edit default
$ virsh net-destroy default
$ virsh net-start default
But sometimes (okay, often) for reasons unknown (unknowable?) that doesn't work. In those cases the fastest solution is to simply tear down the virtual network:
- dump the network config with
virsh net-dumpxml default >/tmp/default.xml
- stop the network
virsh net-destroy default
- undefine the network
virsh net-undefine default
- make changes to default.xml
- recreate network
virsh net-define /tmp/default.xml
- start network
virsh net-start default
- confirm all is well
virsh net-dumpxml default
- set to autostart
virsh net-autostart default
User wk. "Why I can't save network changes with virsh". Serverfault. Answer no. 8. February 3, 2014. Retrieved November 25, 2020.
That's a lot of work, and considerable disruption (again, connected guests will need to be restarted).
I guess you could say I'm not a fan of this process. Thanks libvirt project!
Note: The Red Hat Enterprise Linux 7 Virtualization Deployment and Administration Guide has an entire chapter on Virtual Networking that covers the management of KVM virtual networks in helpful detail. Because those details are becoming less relevant in the Red Hat ecosystem as the company continues promote containerization of workloads and OpenShift to manage infrastructure in the cloud, they don't appear in the doc for Red Hat Enterprise Linux 8 (and future releaes).