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

Is it possible to define multiple network interfaces for a box? #641

Closed
blt opened this Issue Jan 16, 2012 · 14 comments

Comments

Projects
None yet
6 participants
@blt
Copy link

commented Jan 16, 2012

I note in the host-only networking documentation that a static IP is set for a single interface. Is is possible to define multiple interfaces, possibly with different strategies? (Say, eth0 is DHCP/NAT and eth1 static for host-only?)

@mitchellh

This comment has been minimized.

Copy link
Member

commented Jan 16, 2012

In the next version that will be coming out any day now (0.9.0), this is very easy:

config.vm.network :hostonly, "33.33.33.10"
config.vm.network :bridged
config.vm.network :hostonly, "12.13.14.15"

The above would create 3 network interfaces.

Note you can also specify specific adapters with :adapter.

Again, reminder: 0.9.0 only.

@mitchellh mitchellh closed this Jan 16, 2012

@blt

This comment has been minimized.

Copy link
Author

commented Jan 16, 2012

Interesting. The only mention of :adapter that I can find is here. Is there more documentation for it elsewhere?

@mitchellh

This comment has been minimized.

Copy link
Member

commented Jan 16, 2012

It has never worked as well as I had wanted. I implemented the feature and never documented it so that those who really needed could use it, but it allowed me to change it in the future.

I'm happy with the implementation now. I'll document it :)

@mitchellh

This comment has been minimized.

Copy link
Member

commented Jan 16, 2012

Here is an example, though:

config.vm.network :hostonly, "33.33.33.10", :adapter => 3

That will put it on the 3rd virtual adapter, but if its the 2nd active adapter the OS will still see it as "eth1"

@lefred

This comment has been minimized.

Copy link

commented Jan 18, 2012

Is it possible to keep the first nic as NAT and add extra hostonly ?

@mitchellh

This comment has been minimized.

Copy link
Member

commented Jan 18, 2012

@lefred The first NIC is always a NAT. Vagrant requires it that way. :)

@lefred

This comment has been minimized.

Copy link

commented Jan 18, 2012

@mitchellh that's what I want, but then I need further investigation, because when I specify another interface (hostonly), vagrant requires that scp to be installed on the base box (which I don't currently) and this is not required with nat only or with vagrant 0.8.x

@mitchellh

This comment has been minimized.

Copy link
Member

commented Jan 18, 2012

Ah, yes, SCP is required because Vagrant actually has to do some file uploads in order to setup the network configuration. You can see where it used (in this example on Debian) here: https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/guest/debian.rb#L35

@lefred

This comment has been minimized.

Copy link

commented Jan 19, 2012

@mitchellh I've tested, I added openssh-clients to my centos base box, but when I put this in the Vagrantfile:

config.vm.network :hostonly, "192.168.70.2", :adapter => 3

It fails :(

This is the output:

[fred@lefred percona-cluster]$ vagrant up percona1
[percona1] Importing base box 'centos6v9'...
[percona1] Matching MAC address for NAT networking...
[percona1] Clearing any previously set forwarded ports...
[percona1] Forwarding ports...
[percona1] -- 22 => 2222 (adapter 1)
[percona1] Creating shared folders metadata...
[percona1] Clearing any previously set network interfaces...
[percona1] Preparing network interfaces based on configuration...
[percona1] Running any VM customizations...
[percona1] Booting VM...
[percona1] Waiting for VM to boot. This can take a few minutes.
[percona1] VM booted and ready for use!
[percona1] Configuring and enabling network interfaces...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

/sbin/ifconfig eth1 down 2> /dev/null

on the virtualbox:

[vagrant@localhost ~]$ ifconfig -a
eth0 Link encap:Ethernet HWaddr 08:00:27:2E:95:1C
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe2e:951c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:414 errors:0 dropped:0 overruns:0 frame:0
TX packets:366 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:34276 (33.4 KiB) TX bytes:47403 (46.2 KiB)

eth3 Link encap:Ethernet HWaddr 08:00:27:11:F1:F9
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

no idead why it's eth3 ;-) but it should work.

I even tried adding the :adapter in the Vagrantfile

@mitchellh

This comment has been minimized.

Copy link
Member

commented Jan 19, 2012

Oh annoying. It looks like whatever guest OS you're using is recognizing that NIC as "eth3" while most I've tested have recognized them in order of being enabled (so even though it is adapter 3 it would be "eth1"). Vagrant has been programmed to expect the latter.

I may have to add another option for :interface. Hm.

@lefred

This comment has been minimized.

Copy link

commented Jan 19, 2012

That would be great :-)

@v6

This comment has been minimized.

Copy link

commented Jan 20, 2015

Is there any more documentation for :adapter or :interface?

I want to do everything possible using Vagrant without needing vboxmanage or saltstack or whatever.

@boriel

This comment has been minimized.

Copy link

commented Jan 27, 2015

I also need this feature. To specify which adapter will vagrant use for vagrant ssh. :) Would be very useful! 👍

@openface

This comment has been minimized.

Copy link

commented Jan 28, 2017

+1

For our project needs, we need to have Vagrant use eth2 always, because eth0 and eth1 are reserved for the web application user to configure. (it's a network appliance)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.