How to fix duplicate address assignment when cloning Linux VMs

For those landing here who just need the answer: sudo rm -f /etc/machine-id

Back story

In my lab, I employ both kickstarters and 'golden images' for instance deployment. The other day when I went to provision a host from one of my images, the playbook failed when it reached the configuration stage. After digging a little further I realized the instance it created never received an IP from the DHCPv6 server. When I pulled up the console, I was hit with multiple "duplicate address detected!" errors. At first I figured it must be stale leases, so I brought the interface down and deleted all the stale lease files. After bringing the interface back up I continued to receive the duplicate address error. This time I flushed everything and restarted NetworkManager. Still no dice! A hint was that this is an IPv6 native environment.

Fixing it

All of a sudden it occurred to me that since I'm cloning an image, the old DUID is likely remaining in place from my base instance. Sure enough, after taking a look at the DHCP request and comparing it to the leases table, my newly provisioned instance was requesting an IP using a DUID that was already in use.

To permanently fix the problem, I simply added a persistent environment variable: $REGEN_DUID=true. I then added a cron @reboot entry that calls the following script:

#!/bin/bash

if $REGEN_DUID == true; then

    rm -f /etc/machine-id

    logger -t duid-regen "Regenerated system DUID"
    sed -i 's/^REGEN_DUID=.*/REGEN_DUID=false/' /etc/environment

fi

When the system reboots, if the $REGEN_DUID var is true the system will wipe the existing DUID and log the action in the syslogger.

Previous Post