Port forward to allow use of Bahmni virtual machine from LAN

I have successfully and quickly installed the Bahmni Vagrant environment on a Windows server 2016 Essentials system and can happily access the app through the address https://192.168.33.10/home

I have further modified the vagrantfile as follows:

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

Vagrant.configure(2) do |config|
  **config.vm.network :forwarded_port, guest: 443, host: 8070, host_ip: "127.0.0.1", guest_ip: "192.168.33.10", auto_correct: true**
  config.vm.box = "bahmni-team/bahmni"
  config.vm.box_check_update = true
  config.ssh.insert_key = false
  config.vm.network "private_network", ip: "192.168.33.10"

  config.vm.synced_folder "..", "/bahmni", :owner => "vagrant"
  config.vm.provider "virtualbox" do |v|
     v.customize ["modifyvm", :id, "--memory", 3092, "--cpus", 2, "--name", "Bahmni-RPM"]
  end
end

I have also allowed port 8070 through the widows firewall. However when I try to access the port 8070 on the server from a LAN connected PC. I just get timed out.

Could anyone suggest what I am doing wrong?

I guess you are trying to access Bahmni Vagrant box from a different machine on the network. For this you have two options:

  1. Give the Vagrant box itself a LAN I.P address so that it appears to be another machine with its own IP address that you can directly hit. Read more here: https://www.vagrantup.com/docs/networking/public_network.html

  2. Or, you can hit the HOST machine IP (on which the Vagrant box is running), and redirect a port from HOST machine to VAGRANT (like what you are trying to do). In this case you would hit the HOST-IP:MAPPED-PORT, so that Vagrant received the re-routed request from the HOST machine. I think adding these lines should help:

config.vm.network :forwarded_port, guest: 8080, host: 8081 
config.vm.network :forwarded_port, guest: 443, host: 8082 
config.vm.network :forwarded_port, guest: 80, host: 8083

# For Public IP
config.vm.network :public_network

You should be able to then access Bahmni at https://HOST-IP:8082

Many thanks for the fast response.

The link on method 1 seems to indicate that t

The change as suggested created an error on “vagrant up” - I think that the default ip for the forward_port is 0.0.0.0 which causes the error and so I read that one should use 127.0.0.1 as below. However after this I still have the original problem of a timeout from the another LAN connected PC browser.

Here is the current vagrantfile:


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

Vagrant.configure(2) do |config|
# Paul Chinn line below was first attempt to get an external port that we could access on the LAN the rest were suggested by Thoughtworks
#  config.vm.network :forwarded_port, guest: 443, host: 8070, host_ip: "127.0.0.1", guest_ip: "192.168.33.10", auto_correct: true
config.vm.network :forwarded_port, guest: 8080, host: 8081, host_ip: "127.0.0.1" 
config.vm.network :forwarded_port, guest: 443, host: 8082, host_ip: "127.0.0.1"
config.vm.network :forwarded_port, guest: 80, host: 8083, host_ip: "127.0.0.1"

# For Public IP
  config.vm.network :public_network
# Paul Chinn end
  config.vm.box = "bahmni-team/bahmni"
  config.vm.box_check_update = true
  config.ssh.insert_key = false
#  config.vm.network "private_network", ip: "192.168.33.10"

  config.vm.synced_folder "..", "/bahmni", :owner => "vagrant"
  config.vm.provider "virtualbox" do |v|
     v.customize ["modifyvm", :id, "--memory", 3092, "--cpus", 2, "--name", "Bahmni-RPM"]
  end
end

127.0.0.1 is the default IP assiged to every machine (to point to itself). So if you enter this on a machine in network, it will hit itself, and not the machine running vagrant box.

See this video: https://www.youtube.com/watch?v=d3wrp2BEvuE

What you need to enter is the IP address of the host machine. See this discussion:

I have watched the tutorial and think I understand in principle. As I mentioned my server is a Windows server 2016 system and not Ubuntu. This may have something to do with the issue.

I explicitly copied the :public_network, ip: “192.168.0.117” (there was no real explanation of this ip) and eliminated port forwarding. My LAN attached PC failed to find this address. The windows server has a static ip of 192.168.8.202 I guess that windows is listening for this ip and that the windows firewall will only allow packets addressed there and where the port has been explicitly allowed and so perhaps not a surprise.

I have tried replacing the the ip from the post with my static ip and also an ip in the same range. Vagrant up then fails saying the port is in use.

Finally I set the host_ip in the forwarded_port to the static ip of the windows server included :public_network but without an ip and voila everything seems to work.

Below is the current working vagrantfile.

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

Vagrant.configure(2) do |config|
# Paul Chinn
# For public_network forwarded_port from the static ip of the server
  config.vm.network :forwarded_port, guest: 8080, host: 8081, host_ip: "192.168.8.202"
  config.vm.network :forwarded_port, guest: 443, host: 8082, host_ip: "192.168.8.202"
  config.vm.network :forwarded_port, guest: 80, host: 8083, host_ip: "192.168.8.202"
  config.vm.network "public_network"
# Paul Chinn end
  config.vm.box = "bahmni-team/bahmni"
  config.vm.box_check_update = true
  config.ssh.insert_key = false
# Paul Chinn commented out config.vm.network "private_network",ip: "192.168.1.30"
  config.vm.synced_folder "..", "/bahmni", :owner => "vagrant"
  config.vm.provider "virtualbox" do |v|
     v.customize ["modifyvm", :id, "--memory", 3092, "--cpus", 2, "--name", "Bahmni-RPM"]
  end
end

Yes, when you use:

config.vm.network "public_network"

then Vagrant uses DHCP to dynamically try and get an IP from the network. Do note, that this means the IP can dynamically again change when this box is restarted – although the network controller in most cases usually gives the same IP to the same machine… but there is no guarantee.

Read more: https://technet.microsoft.com/en-us/library/dd145320(v=ws.10).aspx

I thought you had to explicitly say “DHCP”?