Cloud and Self-Hosting
How to Reset the Machine ID on an Ubuntu Server
By Amjid Ali · · Updated · 4 min read

In this article
To reset the machine ID on Ubuntu, delete the old ID files, generate a new one with systemd-machine-id-setup, relink the D-Bus copy and reboot:
sudo rm -f /etc/machine-id /var/lib/dbus/machine-id
sudo systemd-machine-id-setup
sudo ln -sf /etc/machine-id /var/lib/dbus/machine-id
sudo reboot
This works on Ubuntu 26.04, 24.04, 22.04 and 20.04, and on Debian. The most common reason to do it is a cloned VM that gets the same DHCP IP address as the original, a problem that shows up quickly when you clone Ubuntu templates on Proxmox or VMware.
What the machine ID is
/etc/machine-id holds a unique 128-bit ID written as 32 lowercase hexadecimal characters, for example 4f1c2a9e7b3d4e6f8a0b1c2d3e4f5a6b. systemd creates it when Ubuntu is installed and services rely on it:
- systemd-networkd (used by netplan on Ubuntu Server) builds the DHCP client identifier from it.
- journald stores logs in
/var/log/journal/<machine-id>/. - D-Bus reads
/var/lib/dbus/machine-id, which on Ubuntu is normally a symlink to/etc/machine-id.
See your current ID:
cat /etc/machine-id
hostnamectl | grep "Machine ID"
The systemd documentation says the ID should be treated as confidential and not exposed on untrusted networks, so do not paste it in public forums.
Step by step: reset the machine ID
1. Back up the current ID (optional)
sudo cp /etc/machine-id /root/machine-id.bak
2. Remove the old ID and the D-Bus copy
sudo rm -f /etc/machine-id /var/lib/dbus/machine-id
Removing both matters. systemd-machine-id-setup copies an existing D-Bus ID from /var/lib/dbus/machine-id if it finds a valid one, so if that file is a real file rather than a symlink, you would get the old ID straight back.
3. Generate a new machine ID
sudo systemd-machine-id-setup
The tool only writes a new ID when /etc/machine-id is missing or empty; running it with the old ID still in place does nothing. Expected output:
Initializing machine ID from random generator.
On a KVM virtual machine (Proxmox, libvirt) you may instead see Initializing machine ID from SMBIOS/DMI UUID., because systemd can use the VM's UUID. Proxmox gives a full or linked clone a new SMBIOS UUID, so the result is still unique; if you copy disk images between VMs by hand with the same UUID, set a new UUID in the VM settings as well.
4. Relink the D-Bus machine ID
sudo ln -sf /etc/machine-id /var/lib/dbus/machine-id
5. Reboot and verify
sudo reboot
After the reboot:
cat /etc/machine-id
ls -l /var/lib/dbus/machine-id
The ID should be different from your backup, and the D-Bus file should show -> /etc/machine-id. If the VM uses DHCP, check it now has its own address with ip -4 addr.
Preparing a VM template (the better way)
Fixing each clone by hand is tedious. Clean the template once so every clone generates its own ID on first boot:
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 shutdown -h now
Keep the file empty rather than deleted. The systemd documentation recommends an empty /etc/machine-id in images used for many machines; systemd fills it with a new ID at boot. Convert the VM to a template while it is shut down and do not boot it again before cloning, or it will generate an ID that every clone inherits.
If the template uses cloud-init (common with Proxmox cloud-init images), use its clean command, which sets /etc/machine-id to uninitialized so systemd generates a new ID on the next boot, and clears cloud-init state at the same time:
sudo cloud-init clean --logs --machine-id
sudo shutdown -h now
Alternative fix for duplicate DHCP IPs: use the MAC address
If you only care about DHCP, you can tell netplan to identify the VM by its MAC address, which Proxmox and VMware make unique per clone. Edit your netplan file (often /etc/netplan/50-cloud-init.yaml or /etc/netplan/00-installer-config.yaml):
network:
version: 2
ethernets:
ens18:
dhcp4: true
dhcp-identifier: mac
Apply it:
sudo netplan apply
Use your real interface name from ip link (ens18 is the usual name on Proxmox). This avoids the duplicate lease but leaves the duplicate machine ID in place, so it is still worth resetting the ID on clones. For a fixed address instead of DHCP, see how to set a static IP on Ubuntu 24.04.
What resetting the machine ID does not change
- SSH host keys: clones share
/etc/ssh/ssh_host_*. Regenerate them:
sudo rm /etc/ssh/ssh_host_*
sudo dpkg-reconfigure openssh-server
sudo systemctl restart ssh
- Hostname: set a new one with
sudo hostnamectl set-hostname new-nameand update/etc/hosts. - Old journal logs: they stay in the old
/var/log/journal/<old-id>/folder. Remove it if you do not need the history.
Troubleshooting
The ID did not change: /etc/machine-id was not empty or missing when you ran systemd-machine-id-setup, or /var/lib/dbus/machine-id was a real file with the old ID. Repeat step 2, removing both, then step 3.
Clones still get the same IP after the reset: the DHCP server still holds the old lease. Release it on the client with sudo networkctl reconfigure ens18 (or reboot), and delete the stale lease on the DHCP server (pfSense: Status > DHCP Leases).
Software licence or monitoring agent stopped working: some tools register the machine by its ID. Re-register the agent after the reset; this is expected on a cloned machine.
Related guides
- Proxmox VE guide for building and cloning Ubuntu VMs
- Import an OVA into Proxmox, another case where a reset is worth doing
- Ubuntu Server installation guide
Frequently asked questions
How do I reset the machine ID on Ubuntu?+
Run sudo rm -f /etc/machine-id /var/lib/dbus/machine-id, then sudo systemd-machine-id-setup to create a new ID, then sudo ln -sf /etc/machine-id /var/lib/dbus/machine-id so D-Bus uses the same value, and reboot. Check the result with cat /etc/machine-id or hostnamectl.
What is the machine ID in Ubuntu?+
It is a unique 128-bit identifier stored in /etc/machine-id as 32 lowercase hexadecimal characters. systemd creates it at installation or first boot, and services use it to identify the system: journald names its log folder after it, and systemd-networkd derives the DHCP client identifier (DUID) from it by default.
Why do my cloned Ubuntu VMs get the same IP address?+
Because they share the same /etc/machine-id. On Ubuntu Server, netplan with systemd-networkd sends a DHCP client identifier based on the machine ID, not the MAC address, so the DHCP server sees two clones as the same client and gives them the same lease. Reset the machine ID on each clone, or set dhcp-identifier: mac in netplan.
Does systemd-machine-id-setup change an existing machine ID?+
No. It only initialises /etc/machine-id if the file is missing or empty. If you run it while the old ID is still in the file, nothing changes. It also copies an existing D-Bus machine ID from /var/lib/dbus/machine-id if it finds one, so delete both files first.
How do I prepare an Ubuntu VM template so every clone gets a new machine ID?+
Before you shut the template down, empty the file with sudo truncate -s 0 /etc/machine-id and make sure /var/lib/dbus/machine-id is a symlink to it (or removed). Each clone then generates a new ID on its first boot. If the template uses cloud-init, sudo cloud-init clean --machine-id does the same job.
Does resetting the machine ID change SSH host keys?+
No. SSH host keys in /etc/ssh are separate files. Cloned VMs share them too, which makes SSH clients warn when IPs move between clones. Regenerate them with sudo rm /etc/ssh/ssh_host_* followed by sudo dpkg-reconfigure openssh-server.
Sources
- machine-id(5), systemd documentation
- systemd-machine-id-setup(1), systemd documentation
- Netplan YAML reference (dhcp-identifier), Netplan documentation
- machine-id is not reset when instance-id changes (bug 2003121), Launchpad (cloud-init)
Keep reading
Cloud and Self-HostingHow to increase ubuntu — vg volume size lvmIf you want to increase the logical volume size of Ubuntu after installation or whenever you need you can do it by the following; First... · 2 min read
Cloud and Self-HostingHow to Install Ubuntu 22.04 Server // Latest GuideUbuntu 22.04 has come with various changes, before installing ubuntu 22.04 let us first see what are the changes; What is new in Ubuntu 22.04... · 1 min read
Cloud and Self-HostingUbuntu Server Installation GuideDepending upon your hardware or Virtualization platform you can choose the relevant method to install Ubuntu Server. Simply Visit Ubuntu Website to down... · 2 min read