无用的反向端口转发? [英] Vagrant reverse port forwarding?
问题描述
我正在研究Web服务体系结构.我有一些需要在本地主机上运行的软件,而不是在Vagrant中运行.但是我想在来宾上运行一些客户端服务.
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的config.vm.forwarded_port
参数将打开主机上的端口,并将数据发送给来宾.但是,如何在客户机上打开端口并将数据发送到主机? (它仍然是端口转发,但方向相反.)
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.)
推荐答案
运行vagrant ssh
时,它实际上是在使用以下基本命令:
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通过-R guestport:host:hostport
选项支持按您想要的方向转发端口.因此,如果要连接到来宾上的端口12345
并将其转发到localhost:80
,则可以使用以下命令:
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
随着Eero正确地注释,您还可以使用命令vagrant ssh -- -R 12345:localhost:80
,该命令在更简洁的命令中具有相同的效果.
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.
这篇关于无用的反向端口转发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!