Skip to content
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

Modify configure_networks to support udev's predicatable network interface names on Ubuntu/Debian #7253

Closed

Conversation

hnakamur
Copy link

@hnakamur hnakamur commented Apr 23, 2016

This pull request is another try to fix to #7241 and #6871.
This is based on Add networking cap for Ubuntu guest by gMagicScott · Pull Request #6724 · mitchellh/vagrant and modified so that:

  • Use ip route | awk '$1=="default"{print $NF;exit}' to get the main_interface.
  • Use ls /sys/class/net | grep -v -E '^(lo$|docker|lxc)' to get available_interfaces then remove the main_interface from them.
  • Use if [/bin/cat /sys/class/net/#{interface}/operstate= up ]; then /sbin/ifdown #{interface} 2> /dev/null; fi to bring down a network interface.
  • Modify network interface templates to support both naming style like eth0 and enp0s8.
  • Use hostnamectl --static status to get the current hostname on distributions with systemd.

Tested with following Vagrantfiles.

Ubuntu Xenial with predicatable network interface names

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/xenial64"
  config.vm.network "private_network", ip: "192.168.33.13"
end

Ubuntu Trusty with old network interface names

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.network "private_network", ip: "192.168.33.9"
end

Debian Wheezy with old network interface names

Vagrant.configure(2) do |config|
  config.vm.box = "debian/wheezy64"
  config.vm.network "private_network", ip: "192.168.33.16"
end

Debian Jessie with old network interface names

Vagrant.configure(2) do |config|
  config.vm.box = "debian/jessie64"
  config.vm.network "private_network", ip: "192.168.33.17"
end

Tested with

  • Vagrant 1.8.1
  • VirtualBox 5.0.16
  • box versions
    • debian/jessie64 (virtualbox, 8.4.0)
    • debian/wheezy64 (virtualbox, 7.10.0)
    • ubuntu/trusty64 (virtualbox, 20160406.0.0)
    • ubuntu/xenial64 (virtualbox, 20160420.3.0)

Note you need to use VirtualBox 5.0.16, not the latest 5.0.18.
Bug #1573058 “Ubuntu 16.04 current not booting in Vagrant (gurum...” : Bugs : cloud-images

@hnakamur
Copy link
Author

Confirmed ubuntu/xenial64 (virtualbox, 20160420.3.0) on Vagrant 1.8.1 with this patch works well with VirtualBox 5.0.20

@sethvargo sethvargo added this to the 1.8.2 milestone Apr 29, 2016
@hnakamur
Copy link
Author

hnakamur commented May 2, 2016

I also created a patch for vagrant 1.8.1
https://gist.github.com/hnakamur/f23e35083bf60d5c573392bfdad94466

available_interfaces = data.chomp.split("\n") if type == :stdout
end
available_interfaces.delete(main_interface)
@logger.debug("debian configure_networks. available_interfaces=#{available_interfaces.inspect}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still need the debug logging? Should "require log4r" and logger references be removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrisvire I removed the debug logging. Thanks!

@@ -6,6 +6,23 @@ def self.change_host_name(machine, name)
super
end

def initialize(machine, new_hostname)
super
@logger = Log4r::Logger.new("vagrant::plugins::guest")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still some logging

main_interface = data.chomp if type == :stdout
end
available_interfaces = []
comm.execute("ls /sys/class/net | grep -v -E '^(lo$|docker|lxc)'") do |type, data|
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ^(lo$|docker|lxc) should be ^(lo$|docker|lxc|lxd). The lxd project recently started calling their bridge interfaces lxdbrX instead of lxcbrX.

Copy link
Author

@hnakamur hnakamur May 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for a good catch!
I add a commit to ignore ^lxd and another commit to ignore ^veth
7802c21

@hnakamur
Copy link
Author

hnakamur commented May 10, 2016

I also updated my patch for vagrant 1.8.1 to ignore network interfaces whose name matches the regex ^lxd, ^veth as well as ^lo$, ^docker and ^lxc
https://gist.github.com/hnakamur/f23e35083bf60d5c573392bfdad94466

@sni
Copy link
Contributor

sni commented May 13, 2016

Using this patch makes my ubuntu12-04 vm hang on "Configuring and enabling network interfaces..."

main_interface = data.chomp if type == :stdout
end
available_interfaces = []
comm.execute("ls /sys/class/net | grep -v -E '^(lo$|docker|lx[cd]|veth)'") do |type, data|
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somewhat related, CoreOS also uses systemd naming, maybe we want to unify it? https://github.com/mitchellh/vagrant/pull/6610/files

Copy link
Author

@hnakamur hnakamur May 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think commas in the regex (e[n,t][h,s,p][[:digit:]]([a-z][[:digit:]])? in https://github.com/mitchellh/vagrant/pull/6610/files should be deleted to say the least.

After reading the pages above, I think ^(en|eth) or ^e(n|th) would do for the whitelist approach.
However PredictableNetworkInterfaceNames says:

You create your own manual naming scheme, for example by naming your interfaces "internet0", "dmz0" or "lan0"

So I think the blacklist approach may be better.

On the other hand, you can change the network interface name for lxd from the default lxdbr0 to some other value. So the ideal way is detecting the type of network interfaces, not checking the names. But I had not found the way to do that, so I took the blacklist approach this time.

@hnakamur
Copy link
Author

@sni Could you share your Vagrantfile? Did you use the patch for Vagrant 1.8.1 or for master?

@sni
Copy link
Contributor

sni commented May 17, 2016

My Vagrantfile contains nothing special, except i create a bridged interface like:

config.vm.network "public_network", type: "dhcp", :bridge => "eth0"

@klardotsh
Copy link

klardotsh commented Jun 1, 2016

Any word on this? There's been at least a few bug reports about this behavior and the PR has been outstanding for now literally months. I find it a little hard to believe this has sat for so long - private IP addresses on Xenial guests (my broken use case) can't be that rare, can they?

If there's anything I can do to test or build this (though I'm more a JS/Python guy than Ruby), please let me know. #7155 is an increasingly problematic bug for me and my team as we look to upgrade our infrastructure from Trusty to Xenial with local testing.

@spotlightishere
Copy link

Thank you so much for this patch, it took forever to find but finally ended my public network suffering!

@domnulnopcea
Copy link

is this going to be merged?

@lobsterdore
Copy link

This is a showstopper for a lot of people I think, the bug addressed by this fix is stopping me from adopting Xenial at all.

@chasebolt
Copy link

I would like to see this merged as well

@endeavour
Copy link

Me too

@ghost ghost locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.