You can always manually configure the ip address of your guest VM especially you are going to expose the guest VM in your KVM or you can configure to use DHCP to assign a static ip address base on the virtual machine virtual MAC address.
- List the available network by default the network name is default.
sudo virsh net-list
- To view the network configuration and identified the virtual interface and ip address range.
sudo virsh net-dumpxml default
You can see that the ip subnet in the default configuration is 192.168.122.0/24
- Next we need to identified the mac address of the virtual machine. If you forgot the VM name you can use the command virsh list to see the list of VMs you have.
# To list the VMs you have.
sudo virsh list
# To retrieve the virtual mac address assigned to your vm
sudo virsh dumpxml <VM NAME> | grep -i “<mac”
Once we have gotten all the necessary information it is time to add the ip address to the VM so that whenever the VM is restarted it will always get the assign ip address.
- Edit the default network configuration.
# To edit the default network configure.
sudo virsh net-edit default
# Add the MAC address, VM NAME and ip address to the config file under <range…/>
<host mac=’MAC ADDRESS’ name=’VM NAME’ ip=’ip_address’/>
Once that is done restart the network to start the DHCP.
# Destroy the current configuration
sudo virsh net-destroy default
# Start the network configuration
sudo virsh net-start default
This should be enough for the server to get the ip address. However if this doesn’t work then restart the libvirtd.service and restart the VM.
sudo systemctl restart libvirtd.service
That’s all you need to assign a static ip address to the VM without manually configuring the VM network.