2

I have a Vagrantfile which starts up 3 vms. I need two of the VM's to not have any internet access, yet they should be on the same network as the 3rd vm which does have internet.

Desired state:
vm1 => NAT & 192.168.45.11
vm2 => 192.168.45.12
vm3 => 192.168.45.13

# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "Debian-7-2"
  config.vm.box_url= "https://dl.dropboxusercontent.com/u/197673519/debian-7.2.0.box"

  config.vm.synced_folder ".", "/vagrant_data"

  config.vm.provider :virtualbox do |vb|
     vb.customize ["modifyvm", :id, "--memory", "512"]
  end

  config.vm.define "r", primary: true  do |router|
     router.vm.box = "Debian-7-2"
     config.vm.network :private_network, ip: "192.168.45.11"
  end

   config.vm.define "r1" do |roomate1|
     roomate1.vm.box = "Debian-7-2"
     config.vm.network :private_network, ip: "192.168.45.12"
   end

   config.vm.define "r2" do |roomate2|
     roomate2.vm.box = "Debian-7-2"
     config.vm.network :private_network, ip: "192.168.45.13"
   end

end

What I find is that even though I configured vm2 and vm3 to have only 1 network interface, they boot up with 2 network interfaces. (host-only & NAT). I don't want the NAT interface.

enter image description here

How would you configure vagrant to start a VM without nat, thus denying internet access to the VM?

spuder
  • 17,437
  • 19
  • 87
  • 153
  • This isn't the right forum for this type of question. SO deals mostly with code specific questions, not how to configure software like this. On the other hand, if you had some VCL written and were wondering how to code the behavior it would be another story. – wheaties Jan 03 '14 at 19:00
  • wheaties, I see your point. Not sure which overflow would be better since my question is similar to these other questions which seem to be allowed. http://stackoverflow.com/questions/17117063/how-can-i-create-a-vm-in-vagrant-with-virtualbox-with-two-cpus?rq=1, http://stackoverflow.com/questions/18457306/enable-internet-access-inside-vagrant?rq=1 – spuder Jan 03 '14 at 19:11

1 Answers1

3
config.vm.provider :virtualbox do |vb|
  vb.customize [
    "controlvm", :id,
    "setlinkstate1", "off",
  ]
end

That may do what you are looking for - That should simply 'disconnect the cable' for the NAT network.

Apr
  • 63
  • 6
tayworm
  • 146
  • 3
  • 1
    I made a slight correction to your answer. It does in-fact disconnect the network cable to the NAT interface after the vm is up. However vagrant then is unable to connect to the vm. I'll need to rethink my strategy. https://gist.github.com/spuder/8274987 – spuder Jan 05 '14 at 22:38