How To Convert /etc/machine-id Into A Default-duid For IPv6 Static DHCP?

Home » CentOS » How To Convert /etc/machine-id Into A Default-duid For IPv6 Static DHCP?
CentOS No Comments


The use-case is deploying C7 VMs with a pre-set machine-id and default-duid based on the machine-id to facilitate static DHCP with IPv6. The default-duid is found in and IPv6
DHCP uses default-duid like IPv4 DHCP uses MAC addresses for static DHCP.

How does one convert /etc/machine-id to a default-duid (in bash)?

1) /etc/machine-id -> DUID:

Use sha256 hash of machine-id, use first 128 bits, add colons and prepend 00:04:

$ MACHINE_ID_SHA256=`cat /etc/machine_id | sha256sum | cut -c1-32`
$ TMPID=$(sed -e ‘s/.\{2\}/&:/g;s/.$//’ <<<$MACHINE_ID_SHA256) $ DUID:04:`echo $TMPID` Correct? 2) convert $DUID to a default-duid. Example value of default-duid can be found in /var/lib/NetworkManager/ Will stick the pre-set default-duid in /etc/dhclient6.leases so it gets picked up by NM once the VM is deployed and started.

So going from e.g.
/etc/machine-id 52d8c0f2a04a462a9c9ac1a906446d85
to duid 00:04:a6:89:54:e8:bf:e2:13:71:82:3d:ea:33:4d:a5:2f:75
to default-duid ???


So how does one create the default-duid from the duid? The default-duid seems escaped octal with some chars here and there. The NetworkManager code at [2] that does the duid->default-duid conversion is above my pay grade. Anyone know how do this conversion preferably in bash?

TIA, Patrick