We're using a ubuntu-18.04 template on a virtualization environment. Therefore, before creating the template, we always empty the /etc/machine-id file so it's recreated upon the first boot.

The problem is that if several ubuntu-18-based VMs are started at once, systemd-machine-id-setup will generate the same ID for all of them, resulting in IP duplication. I checked these servers and they all have the same content in the /etc/machine-id file.

IP duplication

If machines are powered-on spaced in time, different IPs are assigned, thus I assume systemd-machine-id-setup is generated based on current time (possibly). This isn't acceptable for us because of the problem in the image above.

Is there a way to make the OS generate the /etc/machine-id on boot based on an alternative binary?

--- UPDATE 1 ---

On @GeraldSchneider's tip, I switched back from netplan to ifdownup and the IPs stopped duplicating, so definitely this is a netplan issue.

no duplicated IPs

Even if this could solve the problem, I'm curious if there's a way to set an alternative way to generate the /etc/machine-id file so no duplications happen using netplan.

  • 1
    Have you looked at /etc/machine-id to see if it is actually the same on each system? The machine ID file is not normally used to obtain an IP address. How are you assigning IP addresses? Jul 16 '19 at 14:37
  • @MichaelHampton yes, the machine-id file has exactly the same value on the machines that are powered-on within the same time lapse. If machines are powered-on on different time lapses, the file content varies. IP addresses are assigned via DHCP. Actually, this file seems to be used to acquire IP addresses: jaylacroix.com/…
    – nKn
    Jul 17 '19 at 7:45
  • Which versions of ESXi are you running? It might possibly be important. Jul 17 '19 at 14:55
  • It's not VMware, it's oVirt. However, it happens on both infrastructures, so I assume this is an Ubuntu 18 issue, not infrastructure.
    – nKn
    Jul 18 '19 at 7:30
  • 1
    You can also switch the netplan DUID back to MAC instead of machine-id using dhcp-identifier: mac, it seems this is a common issue with netplan and the changed DUID.
    – Lenniey
    Jul 18 '19 at 14:13

...I'm curious if there's a way to set an alternative way to generate the /etc/machine-id file...

Per the machine-id manual page,

...Otherwise, the value in /etc/machine-id will be used. If this file is empty or missing, systemd will attempt to use the D-Bus machine ID from /var/lib/dbus/machine-id, the value of the kernel command line option container_uuid, the KVM DMI product_uuid (on KVM systems), and finally a randomly generated UUID.

And also, towards the bottom of the page,

The simple configuration file format of /etc/machine-id originates in the /var/lib/dbus/machine-id file introduced by D-Bus. In fact, this latter file might be a symlink to /etc/machine-id.

Therefore, it is also possible to set the machine-id using dbus-uuidgen, as can be seen in the following answer:

Per the dbus-uuidgen manual page,

If you run dbus-uuidgen with no options it just prints a new uuid made up out of thin air.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.