12

I've setup a local virtual machine (ubuntu 12.4) using Vagrant (www.vagrantup.com) and need to share its resources on my local wifi network. It is basically running a webserver which should be accessible by other machines on the local network.

My local wifi adapter gets a dynamic IP address from a router.

My current config looks like this, but i cannot access the machine from another machine using the IP:

config.vm.network :private_network, ip: "192.168.56.101"
    config.vm.network :forwarded_port, guest: 80, host: 8080

How can I make this happen? Any help is highly appreciated!

Philipp
  • 161
  • 1
  • 1
  • 4
  • Did you ever get this figured out? I've been spending all day on this and am driving myself crazy. The main answer on this page isn't very helpful. – Ryan Apr 13 '17 at 16:14

2 Answers2

14

The private_network is a network that is only between your host and the guest vm. If you want to make the guest vm available to others systems on the same network as your host you need to use the "public_network" setup in vagrant. This will allow your guest to get/use an IP address on the network that your host is on.

config.vm.network "public_network"

http://docs.vagrantup.com/v2/networking/public_network.html

kberg
  • 241
  • 1
  • 3
  • 1
    In my particular setup, I had to leave both the `private_network` and `public_network` options enabled. This creates 3 adapters on `vagrant up` but it was fixed and works as expected. – Joum Oct 28 '15 at 14:53
0

If you're using VirtualBox as your provider, you can change this on the fly, so you can have it be private by default (which is of course more secure), and then you can go change it in VirtualBox to expose the port.

To expose the port:

  • Start Virtual Box
  • Select your VM in the left hand side bar
  • Click Settings | Network | Advanced | Port Forwarding
  • Find the port you want to expose in the port list
  • Set it's Host IP to an empty string, and click OK.

The port is now available to other machines on your network, and possibly the internet, so don't do this unless you're positive you're ok with opening up the port!

Brad Parks
  • 713
  • 13
  • 20