Proxmox cloned VM gets the same IP? Reset the machine-id (Ubuntu and Debian)

Cloned Ubuntu VMs in Proxmox get the same DHCP address because they share /etc/machine-id, which systemd uses as the DHCP client ID. Reset the machine-id on the clone and reboot, or prepare the template so every clone gets its own.

Share
Two cloned Proxmox VMs getting the same IP address from DHCP

When you clone an Ubuntu VM in Proxmox and both copies get the same IP from DHCP, the cause is almost always /etc/machine-id. The clone has a new MAC address, but it has the same machine-id as the original, and systemd-networkd builds its DHCP client ID from the machine-id. Your router sees the same client ID and hands out the same lease.

The fix on the clone:

sudo truncate -s 0 /etc/machine-id
sudo rm -f /var/lib/dbus/machine-id
sudo ln -s /etc/machine-id /var/lib/dbus/machine-id
sudo reboot

On boot, systemd generates a new machine-id, the DHCP client ID changes, and the clone gets its own address. Below is why it happens, how to check it, and how to prepare a template so it never happens again.

Why clones share an IP even with a new MAC

DHCP servers can identify a client in two ways: by MAC address, or by a client identifier the client sends. On Ubuntu Server (and Debian with systemd-networkd), the client identifier is a DUID derived from /etc/machine-id. Most home routers and many DHCP servers prefer the client identifier when it's there.

A cloned VM keeps the same disk, so it keeps the same machine-id. Proxmox gives the clone a new MAC, but the DHCP server still sees the same client ID and thinks it's the same machine. Result: two VMs fighting over one IP.

The systemd machine-id documentation says the ID must be unique per installation and recommends emptying it in images that get copied.

Check whether two VMs share a machine-id

Run this on the original and on the clone:

cat /etc/machine-id

If both print the same 32-character string, that's your problem. Also check the MAC addresses, just to rule them out:

ip link show

In Proxmox, every clone gets a new random MAC by default. If you copied a VM config by hand, check Hardware > Network Device: clear the MAC field and click OK, and Proxmox generates a new one.

Resetting the MAC address of a Proxmox VM network device

Fix an existing clone

On the cloned VM (console or SSH):

sudo truncate -s 0 /etc/machine-id
sudo rm -f /var/lib/dbus/machine-id
sudo ln -s /etc/machine-id /var/lib/dbus/machine-id
sudo reboot

Why each line:

  • truncate -s 0 empties the file instead of deleting it. An empty /etc/machine-id tells systemd to generate a new one at the next boot. A missing file can cause problems on some systems.
  • /var/lib/dbus/machine-id is an older copy used by D-Bus. Making it a symlink keeps both in sync from now on.

After the reboot, cat /etc/machine-id shows a new value and the VM requests a new lease. If the router still hands out the old IP, release the old lease in the router's DHCP list or wait for it to expire.

Commands to reset machine-id on a cloned VM

Also reset the SSH host keys and hostname

A clone has the same SSH host keys as the original. It works, but your SSH client can't tell the two machines apart, and it's bad practice. Regenerate them on the clone:

sudo rm -f /etc/ssh/ssh_host_*
sudo ssh-keygen -A
sudo systemctl restart ssh

On Debian and older Ubuntu the service may be called sshd. Then set a unique hostname:

sudo hostnamectl set-hostname web02

Update /etc/hosts if it still lists the old name.

Prepare the template so clones are unique

The cleaner fix is to do this once on the template, so every clone generates its own ID on first boot. Right before you convert the VM to a template:

sudo truncate -s 0 /etc/machine-id
sudo rm -f /var/lib/dbus/machine-id
sudo ln -s /etc/machine-id /var/lib/dbus/machine-id
sudo rm -f /etc/ssh/ssh_host_*
sudo cloud-init clean --logs   # only if the template uses cloud-init
sudo poweroff

Then in Proxmox: right-click the VM and choose Convert to template. Don't boot the template again after this, or it generates a machine-id and you're back to square one. With cloud-init, new SSH host keys are created on each clone's first boot. Without cloud-init, run sudo ssh-keygen -A on the clone's first boot (from the Proxmox console), otherwise the SSH server won't start.

If you build VMs from Ubuntu cloud images with cloud-init, Proxmox's Cloud-Init tab sets hostname, user, SSH key and network per clone. Combined with an empty machine-id in the template, clones come up unique without any manual steps. I covered automated VM creation in the Terraform and Proxmox tutorial.

Alternative: make DHCP use the MAC address

If you'd rather have DHCP key on the MAC, tell netplan to send the MAC as the client identifier. In /etc/netplan/50-cloud-init.yaml (or your netplan file), under the interface:

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

Apply with sudo netplan apply. The netplan reference lists dhcp-identifier as the option for this. I'd still reset the machine-id though: other things use it too, like journald, some monitoring agents and license checks.

My take

Reset the machine-id in the template, not in every clone. It takes one minute and saves you from chasing duplicate IPs, duplicate SSH fingerprints and confused monitoring later. After cloning, install the QEMU guest agent so Proxmox shows each clone's IP on the Summary page, which makes spotting duplicates easy. If you need a fixed address instead, see how to change the IP address in Proxmox.

FAQ

Why does my cloned Proxmox VM have the same IP as the original?

The clone has the same /etc/machine-id, and systemd-networkd uses it to build the DHCP client ID. The DHCP server sees the same ID and assigns the same IP, even though the MAC is different.

How do I reset the machine-id on Ubuntu?

Run sudo truncate -s 0 /etc/machine-id, replace /var/lib/dbus/machine-id with a symlink to /etc/machine-id, and reboot. systemd creates a new ID at boot.

Does Proxmox give a cloned VM a new MAC address?

Yes, by default each clone gets a new random MAC. If you copied a config manually, clear the MAC in Hardware > Network Device and Proxmox generates one.

Do I need to reset the machine-id on Windows clones?

No, Windows doesn't use /etc/machine-id. For Windows templates, run Sysprep with Generalize before converting to a template.

Will resetting the machine-id break anything?

Not on a fresh clone. On a VM that's been running for a while, it resets the persistent journal location and anything that keys on the machine-id, like some monitoring agents, which then register as a new machine.