Vagrant issue - able to communicate between private networks - vagrant

I've run into an issue while using Vagrant.
I have to boxes and I've configured them to be part of different virtualbox internal networks (relevant config below):
Dataplane port
vsrx1.vm.network 'private_network', auto_config: false, nic_type: '82540EM', virtualbox__intnet: **"seg1"**
end
Dataplane port
vsrx3.vm.network 'private_network', auto_config: false, nic_type: '82540EM', virtualbox__intnet: **"seg2"**
end
However, the hosts are able to communicate with one another (they have IPs from the same subnet), although they belong to different private networks.
Does anyone know why?
Thanks,
Cristian

From the vagrant book
NAT Requirement As the First Network Interface
With VirtualBox,
Vagrant requires the first network device attached to the virtual
machine to be a NAT device. The NAT device is used for port
forwarding, which is how Vagrant gets SSH access to the virtual
machine.
Therefore, any host-only or bridged networks will be added as
additional network devices and exposed to the virtual machine as
“eth1,” “eth2,” and so on. “eth0” or “en0” is generally always the NAT
device.
It isn’t currently possible to override this requirement, but it is
important to understand that it is in place.
this first network interface is not set from Vagrantfile, if you ssh into the VM and check the network of the VM, you will see this first network interface used by the host to communicate with the VM (so you can ssh)

Related

Vagrant IP Address Collision Issue

I'm having an issue bringing a previously working vagrant box up.
When I run the up command with the line box.vm.network "private_network", ip: "10.0.0.10" in it, I get the error:
The specified host network collides with a non-hostonly network!
This will cause your specified IP to be inaccessible. Please change
the IP or name of your host only network so that it no longer matches that of
a bridged or non-hostonly network.
Bridged Network Address: '10.0.0.0'
Host-only Network 'en0: Wi-Fi (Wireless)': '10.0.0.0'
But when I change that same line to box.vm.network "private_network", ip: "10.0.1.10" it works fine (change number after 3rd period 1 from 0).
In my VirtualBox Host Network Manager, I've got
vboxnet1 with the IPv4 Address/Mask 10.0.0.1/24 and vboxnet2 with 10.0.1.1/24. Can anyone give me some help as to why I only seem to be able to use the second? I have no other virtual machines running right now.
Has your network configuration changed recently on the host? Maybe a wifi router, LAN adapter, bridge, VPN tunnel, etc is using 10.0.0.x address space. Typing ifconfig in a Terminal window will reveal all your network interfaces and their IP allocations.

How to see the interfaces set up with virtualbox when using vagrant

I've set up a default vagrant setup, and I'd like to be able to find out what i can from the host about the guest.
For virtualbox setups, what happens is there are some pseudo interfaces that you can use to route and firewall the guest outgoing connections. But, when using vagrant, i noticed the availability of a private space eth0 which is NATted through the host interface. Searching using iproute2 and looking through the procfs does not show any interface at all.
A while back I found the vbox driver bypasses all the usual methods to inspect interfaces from the host machine. Is there a way to find out more about the interfaces on the guest from the host, and which chain should i target to firewall traffic from this?
Strangely just to answer: to find the existence of the ip address in procfs, you'll have to check the /proc/net/fib_trie. Unfortunately, anecdotally, this doesn't work on some procfs.

How to set the IP Address of a Virtualbox guest manually

For sake of automation I need to be able to manually set the IP address of my Virtualbox guest (which is an OS X) to a fixed IP.
Can this be done using VBoxManage? I need to avoid the GUI.
Thanks
in your virtual machine setting, you can find networking adapters. You have some choice :
Network Address Translation (NAT): Used to share the host's IP address
If all you want is to browse the Web, download files and view e-mail inside the guest, then this default mode should be sufficient for you, and you can safely skip the rest of this section.
Bridged networking
This is for more advanced networking needs such as network simulations and running servers in a guest. When enabled, VirtualBox connects to one of your installed network cards and exchanges network packets directly, circumventing your host operating system's network stack.
Host-only networking
This can be used to create a network containing the host and a set of virtual machines, without the need for the host's physical network interface. Instead, a virtual network interface (similar to a loopback interface) is created on the host, providing connectivity among virtual machines and the host.
if you want specific IP for your virtual machine you can set in your guest vm ( ifconfig in linux & ipconfig in windows) and choose NAT in network adapter setting .
https://www.virtualbox.org/manual/ch06.html

vagrant customize VM after provisioning

is it possible to customize the VM after it has been provisioned? I know you can execute things like:
config.vm.provider "virtualbox" do |v|
v.customize "post-boot", ["controlvm", :id, "nic1", "hostonly", "vboxnet0"]
end
But that is executed before provisioning the machine. What I want to do is:
Create the VM. The VM is actually a virtual appliance.
Provision the VM.
Reconfigure eth0 to be of type host-net instead of NAT.
Is this possible?
Thanks
From the vagrant book
With VirtualBox, Vagrant requires the first network device attached to
the virtual machine to be a NAT device. The NAT device is used for
port forwarding, which is how Vagrant gets SSH access to the virtual
machine.
Therefore, any host-only or bridged networks will be added as
additional network devices and exposed to the virtual machine as
“eth1,” “eth2,” and so on. “eth0” or “en0” is generally always the NAT
device.
It isn’t currently possible to override this requirement, but it is
important to understand that it is in place.
If you need to change, you'll need to change in virtual box directly

Is it possible to make localhost work through a Virtual Machine?

I am using a Macbook running 10.6. I am using VMware Fusion to run an Ubuntu Server minimal virtual machine. Ubuntu Server is running your basic LAMP stack.
I do my development in Mac OS. I have VMware share a directory from Mac OS to the Ubuntu Server. Ubuntu Server uses that directory for apache.
I access my server is Mac OS in firefox using the ip address of my virtual machine. This is a pain because I have to find out what the ip address is of my virtual machine each time I boot it up. I could set a static ip address but this causes problems if I move my Macbook from network to network.
Is there any configuration (NAT or Bridged or something) that would let me access my virtual machine from the Mac OS using localhost or something similar?
Thanks
NAT should be OK. Your VM is on a different subnet that way, you can give it the static IP you like, and it won't interfere with the (dynamic) IP on your real network.
What you are looking for is the host-only networking adapter as opposed to the NAT or bridged adapters. This creates a network interface on the virtual machine that only connects the actual host. It is perfectly safe to set an IP address for this interface that does not change, and there will be no tricky NAT getting in the way. It's a little network that only exists for communication between the real host and the virtual host. It's exact purpose is so you can do development like this. I use the same feature on VirtualBox all the time, but VMWare has it as well.
Now, with a host-only adapter you might be worried that your VM now has no access to the Internet. The answer is simple. Just make two adapters. eth0, eth1. Make one of them a bridged or NAT adapter for Internet access. Make the other one the host-only adapter for your development. Most modern Linux distros will automatically route accordingly. I know for a fact that Ubuntu does, because I do it all the time. Again, this is with VirtualBox. Your mileage may vary with VMWare, but I can't imagine it's that different.
I'm using Virtual Box and typing in the computer local address (for instance 192.168.1.100) instead of localhost did the trick.
Maybe I'm misunderstanding your question but why not just add an entry in your hosts file for the virtual machine? That way you can access it with some arbitrarily assigned name (like testmachine) instead of the IP.
This is the first tutorial I found through google: http://decoding.wordpress.com/2009/04/06/how-to-edit-the-hosts-file-in-mac-os-x-leopard/
This would work best if your VM has a static IP, BTW (either no DHCP or configure the DHCP server to give that MAC the same IP every time). That way you don't have to worry about changing the hosts entry every time the DHCP server gives the VM a different IP.

Resources