New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debian/stretch64 9.6.0 box configured with private_network and dhcp gets wrong IP-address with systemd-networkd #10585

Closed
nestthvt opened this Issue Jan 11, 2019 · 0 comments

Comments

Projects
None yet
2 participants
@nestthvt
Copy link

nestthvt commented Jan 11, 2019

Vagrant version

Vagrant 2.1.5

Host operating system

Windows 7

Guest operating system

debian/stretch64 (virtualbox, 9.6.0)

Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "debian/stretch64"
  config.vm.network "private_network", type: "dhcp"

  config.vm.provision "shell", inline: <<-SHELL
    sudo systemctl enable systemd-networkd.service
  SHELL 
end

Debug output

Important lines from the 'vagrant up'-debug ouput after reboot:

 INFO ssh: Execute: sudo systemctl status systemd-networkd.service (sudo=false)
DEBUG ssh: stderr: 41e57d38-b4f7-4e46-9c38-13873d338b86-vagrant-ssh
DEBUG ssh: Exit status: 0
DEBUG ssh: Uploading: D:/WS/Temp/vagrant-debian-configure-networks20190111-1224-1wc9fyk to /tmp/vagrant-network-entry-1547201289
DEBUG ssh: Re-using SSH connection.
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: mkdir -p /etc/systemd/network
mv -f '/tmp/vagrant-network-entry-1547201289' '/etc/systemd/network/50-vagrant-eth1.network'

Vagrant stores following network-configuration into the vm:

D:\WS\Vagrant\BugRepro>vagrant ssh -c "cat /etc/systemd/network/50-vagrant-eth1.network"
[Match]
Name=eth1
[Network]
DHCP=no
Address=172.28.128.1/24
Connection to 127.0.0.1 closed.

Which results in an invalid IP-address:

D:\WS\Vagrant\BugRepro>vagrant ssh -c "ip addr show"
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:8d:c0:4d brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe8d:c04d/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:37:59:f8 brd ff:ff:ff:ff:ff:ff
    inet 172.28.128.1/24 brd 172.28.128.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe37:59f8/64 scope link
       valid_lft forever preferred_lft forever
Connection to 127.0.0.1 closed.

Expected behavior

  • DHCP should be set to yes
  • a dynamic IP adress should be assigned in the range given by the used "VirtualBox-Host-Only Ethernet Adapter"

Actual behavior

  • DHCP should be set to no.
  • a static invalid IP-address is configured (address is the one of the used "VirtualBox-Host-Only Ethernet Adapter")

Steps to reproduce

  1. create a new directory and store the given Vagrantfile to it
  2. running machine and enable the systemd-netword-service (will be done automatically)
  3. restart the machine and check the assigned IP-address
  4. inspect the created network-config-file under /etc/systemd/network/

References

Problem is similar to #9570

The IP-Address will be set in case dhcp is enabled by C:\HashiCorp\Vagrant\embedded\gems\2.1.5\gems\vagrant-2.1.5\plugins\providers\virtualbox\action\network.rb:259:


          # Default IP is in the 20-bit private network block for DHCP based networks
          options[:ip] = "172.28.128.1" if options[:type] == :dhcp && !options[:ip]

If the IP-adress is set, dhcp will be disabled by 'C:\HashiCorp\Vagrant\embedded\gems\2.1.5\gems\vagrant-2.1.5\plugins\guests\debian\cap\configure_networks.rb:92':

            if network[:ip]
              mask = network[:netmask]
              if mask && IPAddr.new(network[:ip]).ipv4?
                begin
                  mask = IPAddr.new(mask).to_i.to_s(2).count("1")
                rescue IPAddr::Error
                  # ignore and use given value
                end
              end
              address = [network[:ip], mask].compact.join("/")
              net_conf << "DHCP=no"
              net_conf << "Address=#{address}"
              net_conf << "Gateway=#{network[:gateway]}" if network[:gateway]
            else
              net_conf << "DHCP=yes"
            end

@briancain briancain added this to the 2.2.4 milestone Jan 11, 2019

@briancain briancain added the has-pr label Jan 11, 2019

@briancain briancain closed this in 65a7261 Jan 12, 2019

briancain added a commit that referenced this issue Jan 12, 2019

Merge pull request #10586 from briancain/debian-systemd-networkd-dhcp…
…-static-ips

Fixes #10585: Properly set DHCP for systemd-networkd ips

gitebra pushed a commit to gitebra/vagrant that referenced this issue Jan 14, 2019

Merge commit '7927c39da90dae3f5be79e36ad9df3b4ad834ac1'
* commit '7927c39da90dae3f5be79e36ad9df3b4ad834ac1':
  Update CHANGELOG
  Fixes hashicorp#10585: Properly set DHCP for systemd-networkd ips
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment