Inside the vagrant machine localhost
refers to the guest vagrant machine, i.e. localhost
doesn't refer to host machine. One way to access host machine from guest is to configure a private network. You can specify a static private IP for vagrant, like this:
Vagrant.configure("2") do |config|
config.vm.network "private_network", ip: "192.168.50.4"
end
After this guest is accessible from host via 192.168.50.4
and host is accessible from guest via 192.168.50.1
, i.e. the end octate for host's IP will be 1
inside guest machine.
After vagrant up
, you can do this from inside guest machine:
$ ping 192.168.50.1
$ curl http://192.168.50.1:3000
Note that, if you have some strict firewall setup then you have to allow connection from 192.168.50.4
.
config.vm.network "private_network", ip: "192.168.50.1"
– Okay