0

I am trying to set up a server environment as follows:

  • Physical Host machine: (192.168.0.106)
  • Physical Laptop: (192.168.0.130)

On the host machine, I am trying to use vagrant to set up 2 Virtual Machines

  • Virtual Machine 1 (VM_IP_1). Vagrant is set up to port forward 5555:8080. This machine will be running some sort of webserver, on port 8080
  • Virtual Machine 2 (VM_IP_2).

I am trying to accomplish the following:

  1. From Physical Host Machine, I want to be able to open up a web browser, navigate to VM_IP_1:5555, and connect to the web server, displaying some web page
  2. From Laptop Machine, I want to be able to open up a web browser, navigate to VM_IP_1:5555, and connect to the web server, displaying some web page (same as 1)
  3. From Virtual Machine 2, I want to be able to open up a web browser, navigate to VM_IP_1:5555, and connect to the web server, displaying some web page (same as 1).

Is this even possible? I've spent the last 2 days, tinkering, trying to automate it, but no luck.

Basically, I want to simulate a non-trivial network architecture consisting of web servers, load balancers, databases, etc. I want to be able to test as if my single powerful server was a simulation of a network (i.e it would run 4 VMs) but also have the flexibility and re usability of my vagrant automation to be able to deploy to production something like (2 powerful servers, each running 2 VMS for a total of 4)

Everyone should be able to communicate with everyone (assuming I have the ports forwarded correctly - routing tables too)

Here are the VagrantFiles I've been playing around with. Tried with private_network but I don't think that's right. There's Host Only but I don't think that's right eitherI am thinking that maybe I need to have some sort of reverse port_forwarding from VM 2. But that doesn't sound right.

VagrantFile VM 1
   config.vm.network 'public_network', ip: '192.168.0.140'
   config.vm.network 'forwarded_port', guest: 8080, host: 5555

VagrantFile VM 2
   config.vm.network 'public_network', ip: '192.168.0.150'

EDIT: As I discovered, it seems that the forwarded_port seems to be pretty much useless when using 'public_network'. I am not sure I 100% understand why, but I can do everything as I outlined above if I change from port 5555 to 8080

keyboard
  • 17
  • 5

1 Answers1

1

I usually work with private network to achieve this, I am not sure why you're saying its right.

This is a quick example of a 3 VM setup with a load-balancer and 2 app servers (running node) so you can get the idea.

Private network is just a virtualbox internal network that is more secure than a bridge network (i.e. a vagrant public network)

Using a static IP anyway is your way to go, I am glad you figure that forward port is not necessary when using static IP (I've been saying this too many times and more)

Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
  • I was facing the same problem as before - I was too preoccupied with forwarding ports, when it was not necessary. Using `private_network`, I can't access `VM1` using my Physical Laptop, which is expected. As I understand it, it makes sense to use `private_network` if your VMs will only talk to each other on the host on which they are running on. If VM1 wants to talk to VM3 (on another Physical Host), then public network will need to be used. At least that's my understanding - that is the restriction of using `private_network` – keyboard Jun 30 '17 at 02:35
  • yes correct, `public_network` in virtual box is a bridge connection so you can connect from another host within the same network. – Frederic Henri Jun 30 '17 at 04:50