Skip to content

Fixing Ubuntu 18.04 Virtual Machines that fight over the same IP address

I ran into a problem recently where virtual machines I created from a template were fighting over the same IP address. Each of them would be assigned the same IP address from my DHCP server, despite the fact that each VM created from my standard template had a unique Mac address. I had a hard time finding the culprit, so I figured I would write a post about it. In my case, I am using Proxmox, though the root-cause is not specific to any virtualization package. My virtual machines were all running Ubuntu 18.04, though this may impact other distributions too. The root cause ended up being due to something called a “machine-id”. Read on to find out how I solved this.

When you install a Linux distribution that utilizes machine-id (Ubuntu 18.04 is such a distribution) it will get a unique machine-id generated and stored in the following file:


In addition, the machine-id may (or may not) also be stored in the following file:


It’s also common for /var/lib/dbus/machine-id to be a symbolic link to /etc/machine-id.

What’s happening, is that for some reason, the machine-id is being used to request an IP address from DHCP, rather than the Mac address. I am not sure why this is the case, why someone thought this was a good idea, or the reasons why Ubuntu 18.04 is set up this way. I haven’t done a lot of reading on this yet, I did only enough research to solve the problem. I’ll probably study this a bit more at some point, but I wanted to get this blog entry posted quickly in case someone else is fighting this.

Here’s what you’ll need to do.

To best solve this problem, remove the contents of /etc/machine-id so that it is an empty file:

sudo truncate -s 0 /etc/machine-id

Then, delete /var/lib/dbus/machine-id:

sudo rm /var/lib/dbus/machine-id

Finally, make a symbolic link:

sudo ln -s /var/lib/dbus/machine-id /etc/machine-id

When you reboot the system, it should generate a new machine-id. It’s important to note that you cannot simply delete the machine-id file, it needs to exist, and be empty. For whatever reason, if the file doesn’t exist, it will never get recreated. But if it’s empty, it will. If you’re like me and attempting to create a virtual machine image or template for rolling out servers, what you’ll do is perform the above steps before you create the image. One would think that cloud-init should take care of this for us, since that’s its entire purpose (provisioning resources to be unique). For some reason, cloud-init doesn’t have a mechanism to solve this and it’s up to us to ensure this aspect of our templates/images is set up manually.

Published inBlog


  1. David Halliday David Halliday

    This seems like the more normal way to do this

    sudo rm /etc/machine-id
    sudo systemd-machine-id-setup
    sudo reboot


  2. Paolo B. Paolo B.

    Probably correct steps are this

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

  3. Aaron Newsome Aaron Newsome

    Thanks for the post Jay. Your ln -s command has the two file positions swapped. /etc/machine-id should be first.

  4. Fernando V Fernando V

    Thanks Jay! I ran into this issue and couldn’t figure out why this was happening with different MAC addresses.

  5. Thanks a million! You are my hero! I spent the whole day trying to figure out why the cloned images (clonezilla, physical servers) kept using the same mac addresses!

    I found out that I have to delete the symbolic link and recreate it for the solution to work correctly, although I don’t understand why!

  6. Jeeyessos Jeeyessos

    Good job Jay!

  7. Ian Ian

    It’s Jay, recognize him from his collaborations with Tom Lawrence!
    Thanks, Jay for this and all you do.

  8. Ben H Ben H

    Hi Jay! This was very helpful but I think the two file paths are swapped in the last command, I think it should be:

    sudo ln -s /etc/machine-id /var/lib/dbus/machine-id

    that made the link work in the same direction as before for me.

  9. Giovanni Lovato Giovanni Lovato

    Thanks Jay for this post, I’ve finally got why I received the same IP address for different virtual machines! The use of a machine-id is indeed very useful for VMs, since you can replace NICs without affecting their leases. More info at:

  10. FlyingAvatar FlyingAvatar

    What’s the point of symlink step? It fails because the original file was never removed.

Comments are closed.