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:
- 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
- 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)
- 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