Rich
Rich

Reputation: 1156

Can't connect to Vagrant public network

I've recently switched from MAMP to Vagrant (using VirtualBox). With MAMP any computer connected to my WiFi network would have access to a project by simply entering the host IP into it's web browser. With Vagrant however, I can only connect to the VM from the computer that's running it.

Changing config.vm.network "private_network" to config.vm.network "public_network" isn't working for me. In fact, even though the VM will launch and allow me to SSH, I can no longer access it from my browser.

Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "scotch/box"
  config.vm.network "public_network"
  config.vm.network "forwarded_port", guest: 80, host: 8080, auto_correct: true
  config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]
end

I've tried both setting and not setting the IP address, and use en1: Wi-Fi (AirPort) for the bridged network interface.

What am I doing wrong? Is this possible with Vagrant?

Upvotes: 1

Views: 4948

Answers (2)

evanhsu
evanhsu

Reputation: 323

I've been able to fix this issue by assigning a static IP to my Vagrant VM that is in the same local range as my host machine.

For example:

My Host machine is: 192.168.1.123

This will work:

config.vm.network "public_network", ip: "192.168.1.201"

But this will NOT:

config.vm.network "public_network", ip: "192.168.0.201"

Upvotes: 8

Danny Watson
Danny Watson

Reputation: 165

Remember to do a vagrant destroy as sometimes certain changes are not made until the box is recreated from scratch.

Upvotes: 1

Related Questions