Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant: how to configure multiple NICs within a Vagrantfile?

The official doc gives example only for 1 IP:

http://docs.vagrantup.com/v2/networking/private_network.html

Vagrant.configure("2") do |config|   config.vm.network "private_network", ip: "192.168.50.4" end 

Googling around I could find only 1 example of Multiple IPs:

https://groups.google.com/forum/#!topic/vagrant-up/hqtdOEjjlsw

Vagrant::Config.run do |config|   config.vm.define :web001 do |config|     config.vm.box = "base"     config.vm.forward_port("http", 5000, 8881)     config.vm.forward_port("ssh", 22, 2222)     config.vm.host_name = "web001.example.com"     config.vm.network("33.33.33.10")     config.vm.network("33.33.33.20", {:adapter=>2})   end end  

but it doesn't work for me...

Any help would be greatly appreciated....

like image 837
Pierluigi Vernetto Avatar asked May 30 '14 15:05

Pierluigi Vernetto


People also ask

How do I run multiple Vagrant boxes?

In case of running multiple instances of the same project, you need multiple copies of the project directory, as Vagrant stores the box state in the . vagrant directory under the project. Show activity on this post. Show activity on this post.

What does Vagrant configure 2 mean?

Vagrant.configure("2") do |config| # ... end. The "2" in the first line above represents the version of the configuration object config that will be used for configuration for that block (the section between the do and the end ). This object can be very different from version to version.

Which interface should the network bridge to Vagrant?

Default Network Interface If more than one network interface is available on the host machine, Vagrant will ask you to choose which interface the virtual machine should bridge to. A default interface can be specified by adding a :bridge clause to the network definition.

How do I set up a Vagrant network?

Configure port forwarding To set up a forwarded port so you can access Apache on your guest, add the config. vm.network parameter to your Vagrantfile. Below is the full file with port forwarding. Reload so that these changes can take effect.


1 Answers

Using Vagrant 1.6.1 and private networking with Virtualbox you can create multiple private ips just by repeating the config.vm.network definition:

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! VAGRANTFILE_API_VERSION = "2"  Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|   config.vm.box = "precise64"    config.vm.network "private_network", ip: "192.168.50.4"   config.vm.network "private_network", ip: "192.168.50.5"   config.vm.network "private_network", ip: "192.168.50.6"   config.vm.network "private_network", ip: "192.168.50.7"  end 
like image 167
tlcowling Avatar answered Oct 14 '22 11:10

tlcowling