0

I couldn't manage to publish a virtual machine's port this way:

config.vm.define "n1" do |n1|
    n1.vm.hostname = "n1"
    n1.vm.network "private_network", ip: "172.20.20.10"
    n1.vm.network "forwarded_port", guest: 8500, host: 8080
end

Access inside the VM works fine:

vagrant@n1:~$ curl http://localhost:8500/v1/health/state/any

but host access (outside of the VM, from my computer web browser) won't work:

http://localhost:8080/v1/health/state/any

Is what I try to achieve possible? Can somebody give me an hint, please?

Thomas Escolan
  • 985
  • 1
  • 8
  • 17
  • Got this at Consul startup, if proven to be of any help: vagrant@n1:~$ consul agent -node=agent1 -bind=172.20.20.10 -server -data-dir=/tmp/consul -config-dir=/e tc/consul.d -bootstrap-expect=1 ==> WARNING: BootstrapExpect Mode is specified as 1; this is the same as Bootstrap mode. ==> WARNING: Bootstrap mode enabled! Do not enable unless necessary ==> Starting Consul agent... ==> Starting Consul agent RPC... ==> ... Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400) Cluster Addr: 172.20.20.10 (LAN: 8301, WAN: 8302) ... – Thomas Escolan Mar 13 '17 at 17:22

1 Answers1

0

I am not vagrant expert. BUT, in networking, you CANNOT forward port that bind to localhost(127.0.0.1) without explicitly mentioned it. Universal binding only works for 0.0.0.0.

You may try this, but I wouldn't guarantee it will works

n1.vm.network "forwarded_port", guest: 8500, guest_ip: 127.0.0.1, host: 8080

It is better to start your application binding to IP address then do the forwarding.

mootmoot
  • 12,845
  • 5
  • 47
  • 44
  • You were quite right! **n1.vm.network "forwarded_port", guest: 8500, guest_ip: "172.20.20.10", host: 8080** and **-client=172.20.20.10** Consul option made together the trick. Thank you very much. – Thomas Escolan Mar 14 '17 at 13:35