【问题标题】:Ssh port forwarding google compute engineSSH 端口转发 google 计算引擎
【发布时间】:2015-02-02 08:19:30
【问题描述】:

我正在尝试使用 google 实例转发流量,但没有运气。 这是场景: 我目前有 2 个实例主服务器和迷你服务器 1 我想从主服务器 ssh mini-server-1 并创建一个动态端口转发,如下所示:

gcloud compute ssh "mini-server-1" --zone="us-central1-f" --ssh-flag="-D:5551" --ssh-flag="-N" --ssh- flag="-n" &

我有这个错误:

绑定:无法分配请求的地址

我试过了:ssh -N username@mini-server-1(all ips internal external, hostname) -D 5551 &

当我运行 netstat 时,我可以看到端口是空闲的。 这是来自主服务器的带有代理的 wget

wget google.com -e use_proxy=yes -e http_proxy=127.0.0.1:5551

正在连接到 127.0.0.1:5551... 已连接。
代理请求已发送,正在等待响应...

有人知道我怎样才能做到这一点吗?

【问题讨论】:

  • 附言。另外我修改了 sshd_config 并添加了 AllowTcpForwarding 是的,但结果仍然相同
  • 如果使用http_proxy会连接不上,用wget命令中的https_proxy测试

标签: linux ssh google-compute-engine


【解决方案1】:

运行带有调试标志的命令以帮助您找到更多信息:

gcloud compute ssh --ssh-flag=-vvv "mini-server-1" \
                   --zone="us-central1-f" \
                   --ssh-flag="-D:5551" \
                   --ssh-flag="-N" \
                   --ssh-flag="-n" &

正如我之前评论中提到的,使用 https_proxy。

【讨论】:

  • 是的,这行得通,显然它绑定到了 ipv6,所以我添加了 --ssh-flag="-4"。并且还使用标准 ssh,例如 ssh -N -o StrictHostKeyChecking=no -o ServerAliveInterval=5 -o ServerAliveCountMax=100000,只需添加 --ssh-flag="ServerAliveCountMax=100000" ?
【解决方案2】:

更简单的语法:

gcloud compute ssh my-vm-name --zone=europe-west1-b -- -NL 4000:localhost:4000

您可以传递任意数量的选项:

-NL 8080:localhost:80 -NL 8443:localhost:443

【讨论】:

  • 哇,我不知道一个人可以同时转发多个端口 :-) 谢谢。顺便提一句。 -NL 127.0.0.1:8080: .... 更安全一点? (只能从 localhost 访问隧道)
猜你喜欢
  • 1970-01-01
  • 2018-05-21
  • 2019-01-10
  • 2022-01-01
  • 2013-12-05
  • 1970-01-01
  • 2017-07-22
  • 2014-10-29
  • 2023-04-10
相关资源
最近更新 更多