Technical

Cloned VMs from template receive the same DHCP IP address: fix the duplicate lease

Cloned VMs from template receive the same DHCP IP address: fix the duplicate lease

Cloned VMs from template receive the same DHCP IP address because the DHCP client identifier survives the clone. The fix is to reset the machine-id or force a new MAC, then clear the stale lease on the DHCP server.

A chaotic array of electrical wires in front of a brick building in Kathmandu, Nepal.

Why the clone gets the same lease

DHCP servers identify clients by MAC address or by a client identifier option. Proxmox clones keep the same virtual MAC unless you change it, and many Linux guests send a DHCP client ID derived from /etc/machine-id. Clone the VM and both stay identical, so the DHCP server hands back the same IP.

Fix it in the guest

Regenerate the machine-id on the cloned VM. On Debian or Ubuntu:

sudo rm /etc/machine-id /var/lib/dbus/machine-id
sudo systemd-machine-id-setup
sudo dhclient -r && sudo dhclient

If the guest uses NetworkManager, restart it instead of dhclient:

sudo systemctl restart NetworkManager
Low angle view of power lines and transformers against a clear blue sky, depicting modern electricity infrastructure.

Or force a new MAC in Proxmox

Shut down the cloned VM, open its Hardware tab, select the network device, and click Edit. Change the MAC address to a new random one. Start the VM and it’ll request a fresh lease.

Clear the stale lease on the DHCP server

If you run dnsmasq, edit /etc/dnsmasq.conf or the lease file and remove the old entry, then restart dnsmasq. For ISC DHCP, delete the lease from /var/lib/dhcp/dhcpd.leases and restart the service. The cloned VM will get a new IP on next request.

My take

Regenerating machine-id is cleaner than messing with MACs, but if you need a static IP per clone, set a DHCP reservation by MAC instead. This is a stupid default and I have no idea why Proxmox doesn’t randomize the MAC on clone automatically.

Related: Proxmox Network No Longer Available After Upgrade: Diagnose and Restore It

Leave a comment

Comments are reviewed before they appear. Your email is never published.