Craig Ward
Craig Ward

Reputation: 2485

Connecting to a Vagrant VM externally

I use Vagrant when developing websites and have done for the last year or so. I would like to test out some functionality on an iPad but I can't figure out how to get the iPad to connect to the Vagrant box on my Mac.

Is it possible to do this?

Upvotes: 31

Views: 36335

Answers (3)

AntonioCS
AntonioCS

Reputation: 8496

This is an old question but for anyone using vagrant 1.5 or greater you can just use vagrant share

Upvotes: 8

renegade
renegade

Reputation: 423

If you configure your network this way in the Vagrant file:

config.vm.network :forwarded_port, guest: 4000, host: 4000

And then serve files on that port. You will be able to hit it externally. Assuming you are running the vagrant box on a Mac it would be (machine).local:4000, for example I'm joe.local:4000

Quite convenient to be able to use an iPad and an iPhone as your preview monitors as you work on a responsive site, if you have livereload or equivalent going you don't even need to touch them.

Upvotes: 24

cgeisel
cgeisel

Reputation: 255

Take a look at Bridged Networking in the Vagrant documentation. Enabling it will allow your VM to appear as a device on the network, and allow you to connect to its IP address and the port your web server is listening on.

Huge caveat: you haven't given any information about your local network, so it's entirely likely that the IP of the VM will not be reachable to your iOS device, which is likely connected via WiFi--and many routers' factory configurations do not allow communication between devices connected wirelessly and those connected via ethernet.

But it's possible.

Upvotes: 10

Related Questions