hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.17k stars 4.43k forks source link

Setting a static IP on Fedora 36 fails, uses DHCP instead #12762

Open der-eismann opened 2 years ago

der-eismann commented 2 years ago

Starting with version 36 Fedora stopped supporting ifcfg files by default. Support can be restored by installing the NetworkManager-initscripts-ifcfg-rh package, but depending on the scenario this might not be possible. You can see this in the debug output:

mv -f '/tmp/vagrant-network-entry-enp5s0-1652284350-0' '/etc/sysconfig/network-scripts/ifcfg-enp5s0'
...
DEBUG ssh: stderr: mv: cannot move '/tmp/vagrant-network-entry-enp5s0-1652284350-0' to
  '/etc/sysconfig/network-scripts/ifcfg-enp5s0': No such file or directory

NetworkManager managed systems should use keyfiles instead.

Vagrant version

Vagrant 2.2.19

Host operating system

Fedora 35

Guest operating system

Fedora 36

Vagrantfile

Vagrant.configure("2") do |config|
    config.vm.box = system_config['basebox']
    config.vm.boot_timeout = 3000

    config.ssh.username = "dev"
    config.ssh.private_key_path = "config/ssh/dev"
    config.ssh.forward_agent = true

    config.vm.provider :libvirt do |libvirt|
        libvirt.cpus = configuration["cpus"]
        libvirt.memory = configuration['ram']
        libvirt.nic_model_type = 'virtio'
        libvirt.disk_bus = 'virtio'
        libvirt.keymap = 'de'
        libvirt.qemu_use_session = false
        libvirt.machine_type = 'q35'
    end

    config.vm.network :private_network, ip: configuration['guest_ip'], nic_type: "virtio"

Debug output

https://gist.github.com/der-eismann/e9165908def8df95574c8e67ab3f102b

Expected behavior

The guest should receive a static IP as usual

Actual behavior

The guest receives a dynamic IP via DHCP instead

Steps to reproduce

  1. Create Fedora 36 guest with simple Vagrantfile
rmsc commented 2 years ago

I'm also experiencing a this but in MicroOS (#12777). In the case of MicroOS there's no way of installing a working version of ifup or ifdown, so there's no workaround possible.

From what I understood, Vagrant lets the VM OS configure the interface (using dhcp) before trying to set a the static address.

I naively tried this, but it didn't work as expected (vagrant also tries to use ifup/ifdown):

  config.vm.network "private_network", :type => 'dhcp', ip: 10.0.0.123

Since the dhcp server is there anyway, couldn't we just use it to assign our "static" IP? And perhaps even set the hostname?

CDFN commented 1 year ago

Having same issue. I've found out that recently Fedora deprecated usage of /etc/sysconfig/network-scripts/* scripts. Instead keyfiles are used, they are stored under /etc/NetworkManager/system-connections/. Example configuration for static IP:

[connection]
id=Wired connection 2
uuid=0fc877a1-e3a9-30d3-951b-aa05544ff3e6
type=ethernet
autoconnect-priority=-999
interface-name=eth1
timestamp=1683239079

[ethernet]

[ipv4]
address1=10.0.1.3/32
method=manual

[ipv6]
addr-gen-mode=default
method=auto

which works perfectly for me.

Here's note left in /etc/sysconfig/network-scripts/readme-ifcfg-rh.txt:

NetworkManager stores new network profiles in keyfile format in the
/etc/NetworkManager/system-connections/ directory.

Previously, NetworkManager stored network profiles in ifcfg format
in this directory (/etc/sysconfig/network-scripts/). However, the ifcfg
format is deprecated. By default, NetworkManager no longer creates
new profiles in this format.

Connection profiles in keyfile format have many benefits. For example,
this format is INI file-based and can easily be parsed and generated.

Each section in NetworkManager keyfiles corresponds to a NetworkManager
setting name as described in the nm-settings(5) and nm-settings-keyfile(5)
man pages. Each key-value-pair in a section is one of the properties
listed in the settings specification of the man page.

If you still use network profiles in ifcfg format, consider migrating
them to keyfile format. To migrate all profiles at once, enter:

# nmcli connection migrate

This command migrates all profiles from ifcfg format to keyfile
format and stores them in /etc/NetworkManager/system-connections/.

Alternatively, to migrate only a specific profile, enter:

# nmcli connection migrate <profile_name|UUID|D-Bus_path>

For further details, see:
* nm-settings-keyfile(5)
* nmcli(1)
CDFN commented 1 year ago

If someone needs ad-hoc workaround, you can add following provisioner for your VM:

  config.vm.provision "shell", inline: <<-SHELL
    nmcli conn modify 'Wired connection 2' ipv4.addresses $(cat /etc/sysconfig/network-scripts/ifcfg-eth1 | grep IPADDR | cut -d "=" -f2)
    nmcli conn modify 'Wired connection 2' ipv4.method manual
    service NetworkManager restart
  SHELL

This is likely to break when using more interfaces than just one for private network.