Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 472
Craig Ward Avatar asked Aug 29 '12 10:08

Craig Ward


People also ask

How do I find my vagrant IP?

The IP address can be determined by using vagrant ssh to SSH into the machine and using the appropriate command line tool to find the IP, such as ifconfig .

What is the command to connect to a running virtual machine using vagrant?

Command: vagrant ssh [name|id] [-- extra_ssh_args] This will SSH into a running Vagrant machine and give you access to a shell.


1 Answers

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.

like image 197
renegade Avatar answered Oct 14 '22 00:10

renegade