VMs from Templates all get the same IP from DHCP

I was creating a bunch of VMs in my VMWare vSphere Lab, and thought I might as well use a template to simplify things.
So I created a new VM, installed the latest Ubuntu server (20.04) image on it. Once I had it all up to date, I shut it down and cloned it to a template. Easy enough.

Then I created 4 VMs from the template. Powered them all up, aaaand they all got the same IP from DHCP. What?

I spent a good while rebooting VMs, deleting and re-adding Network Interfaces, refreshing DHCP leases from within the VM as well as deleting leases from my DHCP Server. But the problem remained.

I did notice that all the VMs claimed to have the same clientID on the DHCP server, which led me to figure out how the client ID was derived.

The Client ID in Ubuntu 20.04 (possibly other systemd-network +netplan distro’s) is a simple text file, /etc/machine-id. This file is cloned as part of the Templating process in vSphere, so it stays the same across VMs.

So the fix is to generate a new client ID.

So before you create your template, make sure to:

echo -n > /etc/machine-id
rm /var/lib/dbus/machine-id
ln -s /etc/machine-id /var/lib/dbus/machine-id

Then shut the VM down to create your Template.

Ref: https://kb.vmware.com/s/article/82229