Fix Duplicate Ip Addresses When Working With Proxmox VM Templates

Original –

TLDR

Make sure your vms have different mac addresses and machine ids. The machine id can be found in /etc/machine-id


If you are working with vm templates in proxmox, chances are you have already experienced this issue: duplicate ip addresses when cloning your template.

In my case, my Unifi Dream Machine informed me about this issue. The first thing I did (and you probably would too) was checking the mac adresses of my vms. They were different, so I dug deeper and opened Google to see if someone else had this error too. And boy, there were tons of issues and tons of solutions.

Many of them sadly didn't work for me - so I googled further. And finally I found the solution (of course, on reddit, where else?).

Looks like Ubuntu (22.04?) uses the machine identifier (found in /etc/machine-id) as the dhcp identifier, not the mac address. I am not really sure why the machine id was the same on my clones, since I thought proxmox would clean it up when converting vms to templates.

So, what's the solution?

Glad you asked. You just need to truncate the /etc/machine-id file. Important: truncate, not delete!

In my case, I use cloud templates of Ubuntu. They are really nice to use since you can prepare things like ssh keys, network addresses, etc. relatively easily. Before creating my template, I already installed qemu-guest-agent into my cloud image.

I did this using the following command:

virt-customize -a jammy-server-cloudimg-amd64.img --install qemu-guest-agent

I updated the command to not only install the guest agent but also truncate the machine id:

virt-customize -a jammy-server-cloudimg-amd64.img --install qemu-guest-agent --truncate /etc/machine-id

Other solutions?

If the above solution does not work for you, there are other ways to fix this issue.

Change the dhcp identifier

To change the dhcp identifier, you need to update your netplan config.

network:
  ethernets:
    enp0s3:
      dhcp4: true
      dhcp-identifier: mac
  version: 2

Of course, you should update the interface name.