Vagrant: Setting hostname in Ubuntu 18 with Vagrant conflicts with systemd-networkd dhcp

Created on 16 Oct 2018  ยท  5Comments  ยท  Source: hashicorp/vagrant

I found that setting the hostname in Ubuntu 18 with Vagrant conflicts with systemd-networkd dhcp. In particular, when I set the hostname via my Vagrantfile, I end up getting 2 IP addresses on one network adapter because both systemd-networkd and dhclient are running and getting DHCP leases.

I see the offending code in the change_host_name.rb file, but I'm not sure what a proper fix is because I'm not exactly sure why the author @hakoerber put dhclient in there to being with.

Workaround

I removed the config.vm.hostname from my Vagrantfile and put it into an Ansible script.

Vagrant version

2.1.5

Host operating system

Windows 10

Guest operating system

Ubuntu 18.04.1 LTS

Vagrantfile

config.vm.hostname = "myhost"

Expected behavior

Just set the hostname.

Actual behavior

Setting the hostname on Debian causes the dhclient process to be run. On Ubuntu 18 the DHCP is already being set with systemd-networkd configurations, so running dhclient causes the network adapter to fetch a second IP address.

Steps to reproduce

  1. Configure network adapter for systemd
  2. Set hostname with Vagrantfile
  3. vagrant up
  4. SSH into machine and run ip addr, see a primary and secondary IP for your network adapter

References

See file: change_host_name.rb

bug guesubuntu has-pr networking

Most helpful comment

Ok, that sounds nice. Thanks for the update!

All 5 comments

Hey @emusgrave!

I see the offending code in the change_host_name.rb file, but I'm not sure what a proper fix is because I'm not exactly sure why the author @hakoerber put dhclient in there to being with.

The change was initially only for debian operating systems. I did not test it with Ubuntu, because I didn't know it was used for Ubuntu in the first place.

Too bad we now have this inconsistency. Does you change work for both Ubuntu and Debian?

Hey @hakoerber - I've actually made a PR to fix this behavior. The original workaround you introduced shouldn't be required anymore with my change. Essentially after changing the hostname, Vagrant will restart networking on the guest, which should renew the DHCP lease. So in this case we won't need to use dhclient which had a bug on older versions of debian.

Ok, that sounds nice. Thanks for the update!

Hmm, doesn't look like GitHub closed the issue on merge. Anyway the fix has been merged into master! It should be out in the next release.

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hesco picture hesco  ยท  3Comments

barkingfoodog picture barkingfoodog  ยท  3Comments

rrzaripov picture rrzaripov  ยท  3Comments

mpontillo picture mpontillo  ยท  3Comments

luispabon picture luispabon  ยท  3Comments