terrywang / vagrantboxes

Handcrafted Arch Linux Vagrant base box with :heart:
250 stars 29 forks source link

Host only adapter cannot be configured when its name not is a standard eth* name #9

Closed root-io closed 9 years ago

root-io commented 9 years ago

https://github.com/mitchellh/vagrant/issues/4288

terrywang commented 9 years ago

From Linux guest perspective, ethX to enpXsY naming scheme change is due to the move from SysV init to systemd (systemd-udevd).

The following distributions have already switched to systemd

Before Vagrant fixes this in its own code, an easy temporary workaround is to pass net.ifnames=0 to kernel boot parameters to revert to the old NIC naming scheme.

That's why I updated the Arch Linux and Oracle Linux 7.0 base box with the information.

root-io commented 9 years ago

Thanks for clarification :)

ibizaman commented 9 years ago

I wanted to set a private_network in my Vagrantfile and vagrant complained that eth1 did not exist. My goal was to ssh in the vagrant box with putty so I needed an ip (so no vagrant ssh).

But there's a workaround: by parsing the output of vagrant ssh-config, you can get the ip address and the port (127.0.0.1 and 2222 for me). So no need for eth1!

terrywang commented 9 years ago

@ibizaman 127.0.0.1 port 2222 was the default Vagrant networking mode. It is set through a port forwarding rule of the first virtual NIC. It is how vagrant ssh connects to the vagrant box.

Please note private network in Vagrant is different networking mode. Private network is equivalent to Host-only networking in VirtualBox.

ibizaman commented 9 years ago

My bad, you are totally right!

I suppose the port changes when there are multiple vagrant boxes active? Parsing vagrant ssh-config should be useful then, right?

terrywang commented 9 years ago

@ibizaman You are right. I haven't used vagrant ssh-config to be honest ;-D

When using port forwarding with NAT networking, we can use auto_correct in Vagrantfile to auto correct any collisions. Like below.

Vagrant.configure("2") do |config|
  config.vm.network "forwarded_port", guest: 80, host: 8080,
    auto_correct: true
end

In addition, VAGRANT_LOG=info vagrant up or vagrant up --debug should also be helpful if things like that happen. Hope it helps.

seekshiva commented 9 years ago

@terrywang I'm a bit of a noob in this. How do I set the kernel boot parameters?

root-io commented 9 years ago

@seekshiva

$ sed -i -e "s/GRUB_CMDLINE_LINUX=\"\"/GRUB_CMDLINE_LINUX=\"net.ifnames=0\"/g" /etc/default/grub
$ grub-mkconfig -o /boot/grub/grub.cfg
lmmarsano commented 9 years ago

@terrywang

pass net.ifnames=0 to kernel boot parameters

Another solution is

sudo ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules

PS I see a symbolic link from /etc/udev/rules.d/80-net-name-slot.rules to /dev/null. This was the old name for 80-net-setup-link.rules, and it no longer works, evidently. According to systemd documentation, the new name is the one I wrote above; I suggest updating the file name. Anyone curious should see the documentation for all 4 solutions, which include terrywang's.

I hope vagrant figures out systemd soon, so we can forget this.