Question

I have an application running in a VirtualBox VM that for testing purposes needs to connect to the host machine. The VM is started with Vagrant and managed by Puppet.

What is the best way to set-up this connection? For example, om my host machine the app runs on port 9200. So from my VM I'd like to go to myhostmachine:9200.

Currently I'm thinking of hacking in a small command that adds hostvm as a entry to /etc/hosts using a simple command like this to figure out my host ip (which is the same as the default route).

/sbin/ip -4 route list 0/0 | grep -m 1 default | awk '/default/ { print $3 }'

And just let Puppet run that every time using the exec functionality. However, I get the feeling there has to be a better way.

The guest OS is Ubuntu 12.04 and the Host is OS-X.

Thanks!

Was it helpful?

Solution

As far as I know, at the moment Vagrant always sets up a natted interface to connect to virtualbox, so I think that the ip of your host machine will always be the 10.0.2.2 address you mentioned. I reckon a puppet host declaration might be easier to manage than running that command each time.

host { 'myhostmachine':
  ip => '10.0.2.2',
}

The puppet resource reference for hosts has all the other params you can set too.

I was then able to access the host using myhostmachine:9200

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top