geerlingguy / packer-drupal-vm

DEPRECATED - Drupal VM Packer base box builder.
https://app.vagrantup.com/geerlingguy/boxes/drupal-vm
8 stars 6 forks source link

Fix identical machine-ids causing dhcp servers to to use same IPs #4

Closed oxyc closed 4 years ago

oxyc commented 4 years ago

This took me a long time to finally figure out! For a few years now I've been using Vagrants DHCP feature to assign IPs to VMs, but about a year ago (since https://github.com/geerlingguy/packer-drupal-vm/commit/f389b8e4c65c1f06a94663fe2e92a64c2597ca33 i guess), all VMs started getting the same IP.

As it turns out this is because Ubuntu 18.04 changed how it identifies itself to DHCP servers, using machine-ids instead of mac addresses. There's quite a few reports on this if you search for "truncate -s 0 /etc/machine-id"

I'm not sure this is the correct fix but it's inspired by Google search results. Packer example does it a bit simpler but not sure.

I've verified that if I run this on an existing VM, it's DHCP assigned IP finally becomes unique

sudo rm -f /etc/machine-id
sudo dbus-uuidgen --ensure=/etc/machine-id
sudo rm /var/lib/dbus/machine-id
sudo ln -s /etc/machine-id /var/lib/dbus/machine-id

exit
vagrant halt; vagrant up

I had a PR open to Drupal VM for DHCP https://github.com/geerlingguy/drupal-vm/pull/1559 but nowadays I just patch it with composer-patches.

geerlingguy commented 4 years ago

Well that's a fun one!

I am happy to accept this patch—would you mind terribly making the same change in the ubuntu (and is Debian the same) things over in https://github.com/geerlingguy/packer-boxes ?

oxyc commented 4 years ago

Sure thing! I also just finished building the box locally and confirmed it worked with linked clones etc.