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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…