Assigning static IP to guest VM on NAT host network using virsh
Posted by Suyash Singh
on October 30, 2022First, find out the MAC address of the VM you want to assign the static IP addresses to:
$ virsh dumpxml $VM_NAME | grep 'mac address'
Then, update the ip address for the virtual mac of the VM
$ virsh net-update default add ip-dhcp-host "<host mac='11:22:33:44:55:66' name='FOO' ip='192.168.1.134' />" --live --config
This would always assign 192.168.1.134
to the VM FOO
running with a mac 11:22:33:44:55:66
.
Finally, restart your VM to get the VM running with the specified IP.
$ virsh shutdown foo
$ virsh start foo
To troubleshoot any issues, begin by checking the IP assigned to the VM by dhcp
$ virsh net-dhcp-leases default