Vagrant reverse port forwarding?

portforwarding, vagrant

Solution

When you run `vagrant ssh`, it's actually using this underlying command:

`ssh -p 2222 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=ERROR -o IdentitiesOnly=yes -i ~/.vagrant.d/insecure_private_key vagrant@127.0.0.1`

SSH supports forwarding ports in the direction you want with the `-R guestport:host:hostport` option. So, if you wanted to connect to port `12345` on the guest and have it forwarded to `localhost:80`, you would use this command:

`ssh -p 2222 -R 12345:localhost:80 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=ERROR -o IdentitiesOnly=yes -i ~/.vagrant.d/insecure_private_key vagrant@127.0.0.1`

As Eero correctly comments, you can also use the command `vagrant ssh -- -R 12345:localhost:80`, which has the same effect in a much more concise command.

Problem

I'm working on a web services architecture. I've got some software that I need to run on the native host machine, not in Vagrant. But I'd like to run some client services on the guest. Vagrant's `config.vm.forwarded_port` parameter will open a port on the host and send the data to the guest. But how can I open a port on the guest and send the data to the host? (It's still port forwarding, but in the reverse direction.)

Original source

Related problems