What I'd like to do is to set the guests' network configuration (IP address, subnet, gateway, broadcast address) from the host system. The used network setup is in bridge
mode. How can I configure the network from the host rather than configuring the client itself to a static network configuration?
If I execute:
virsh edit vm1
there is a <network>
block as well and I tried to configure the network interface from there, but unfortunately the guest VM doesn't seem to use it and as such is offline to the network (since it uses automatic network configuration only)... Guest VMs are both, Linux and Windows based. Any help would be highly appreciated.
If you don't want to do any configuration inside the guest, then the only option is a DHCP server that hands out static IP addresses. If you use
bridge
mode, that will probably be some external DHCP server. Consult its manual to find out how to serve static leases.But at least in forward modes
nat
orroute
, you could use libvirt's built-indnsmasqd
(More recent versions of libvirtd support the dnsmasq's "dhcp-hostsfile" option). Here is how:First, find out the MAC addresses of the VMs you want to assign static IP addresses:
Then edit the network
Find the
<dhcp>
section, restrict the dynamic range and add host entries for your VMsThen, reboot your VM (or restart its DHCP client, e.g.
ifdown eth0; ifup eth0
)Update: I see there are reports that the change might not get into effect after "virsh net-edit". In that case, try this after the edit:
... and restart the VM's DHCP client.
If that still doesn't work, you might have to
Note: There is no way the KVM host could force a VM with unknown OS and unknown config to use a certain network configuration. But if know know that the VM uses a certain network config protocol - say DHCP - you can can use that. This is what this post assumes.
Some OS (e.g. some Linux distros) also allow to pass network config options into the guest e.g. via the kernel command line. But that is very specific to the OS, and i see no advantage over the DHCP method.
virsh net-update
is a good command for you (you don't need to restart/destroy your network etc)see: https://www.redhat.com/archives/libvir-list/2012-September/msg01380.html
I have been able to make
dnsmasq
'see' the newly added IP-MAC mapping by simply sending a-HUP
signal to thednsmasq
process. After that, rebooting the new guest was enough to have the correct IP assigned to it, without the need to restartlibvirtd
nor the network itself.The official libvirt documentation (http://wiki.libvirt.org/page/Networking#Applying_modifications_to_the_network) mentions this unofficial Perl script that automates the whole process: https://gist.github.com/bendiken/032ea1bddb9ffafe98b4
I haven't tried this script myself, because I figured out that the hostsfile was already updated and just sending the -HUP signal was enough.
The host is running Debian 7.8 and packages versions are: