I'm trying to create VMs using KVM.
I am using libvirt to create the VMs, with following packages
bridge-utils libvirt-daemon-system virt-manager virt-viewer qemu-kvm qemu-efi
And the command to create vm:
virt-install --import --name guest1 \
--memory 2048 --vcpus 1 --noautoconsole \
--os-variant ubuntu22.04 --hvm \
--network network=default \
--disk=/vm-images/jammy01.img --import
virt-install --import --name guest2 \
--memory 2048 --vcpus 1 --noautoconsole \
--os-variant ubuntu22.04 --hvm \
--network network=default \
--disk=/vm-images/jammy02.img --import
virt-install --import --name guest3 \
--memory 2048 --vcpus 1 --noautoconsole \
--os-variant ubuntu22.04 --hvm \
--network network=default \
--disk=/vm-images/jammy03.img --import
The network=default is:
<network>
<name>default</name>
<uuid>9ea90610-3814-4508-b943-3e53aa5d3404</uuid>
<forward mode='nat'/>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:6a:55:17'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'/>
</dhcp>
</ip>
</network>
And netplan yaml in each machines:
network:
ethernets:
enp1s0:
dhcp4: true
version: 2
renderer: networkd
However, all the machines are having same IP even I'm using dhcp4.
Simply, I checked it with virsh net-dhcp-leases default
, and it is
Expiry Time MAC address Protocol IP address Hostname Client ID or DUID
------------------------------------------------------------------------------------------------------------------------------------------------
2023-02-22 12:07:14 00:50:52:a7:d7:92 ipv4 192.168.122.241/24 ubuntu ff:5d:e2:6c:15:00:02:00:00:ab:11:33:33:f1:46:a3:8b:cb:28
Only one ip is assigned. As the machines are provisioned, only MAC address are changed.
How can I solve this problem?
I expected, each machines will have own IP address, something like:
Expiry Time MAC address Protocol IP address Hostname Client ID or DUID
------------------------------------------------------------------------------------------------------------------------------------------------
2023-02-22 12:07:14 00:50:52:a7:d7:92 ipv4 192.168.122.241/24 ubuntu ff:5d:e2:6c:15:00:02:00:00:ab:11:33:33:f1:46:a3:8b:cb:28
2023-02-22 12:07:14 00:50:52:b7:a7:22 ipv4 192.168.122.151/24 ubuntu ff:5d:e2:6c:15:00:02:00:00:ab:11:33:33:f1:46:a3:8b:cb:28
2023-02-22 12:07:14 00:50:52:17:5b:ef ipv4 192.168.122.199/24 ubuntu ff:5d:e2:6c:15:00:02:00:00:ab:11:33:33:f1:46:a3:8b:cb:28
The problem was dhcp identifier was set into Machine Id
as default.
As I created machine by template, I have to change the machine id on /etc/machine-id
or explicitly declare the dhcp-indeitifer
that I will use MAC address as the identifier.
The last one, explicitly set MAC address as dhcp-identifier
, you could set it on /etc/netplan/NETWORK.yaml
->
network:
ethernets:
enp1s0:
dhcp4: true
dhcp-identifier: mac # This is the key of this problem.
version: 2
renderer: networkd