ssh 端口转发在公司网络上不起作用

ssh 端口转发在公司网络上不起作用

我正在进行 ssh 反向端口转发,以通过公共 IP 访问只能在本地访问的 Web 服务器。

在我的笔记本电脑上执行此命令后:

ssh -v -o "ExitOnForwardFailure yes" -o GatewayPorts=yes -g username@remoteserver -R '*:9080:localhost:3000' 

当我通过浏览器访问时http://remoteserver:9080,我会看到本地主机(我的笔记本电脑)3000 端口上运行的服务器提供的内容。

当我在家里的笔记本电脑上完成此操作或通过我的 iPhone(网络共享 3G 连接)连接到互联网时,它按预期工作。

如果我在公司网络后面,则无法工作我目前就职的公司:

  • ssh 命令连接成功,甚至显示All remote forwarding requests processed(见下面的日志)
  • 但是:http://remoteserver:9080从公司网络内部的客户端访问只会显示“无法连接错误”
  • 并且:笔记本电脑上运行的 Web 服务器在端口 3000 处未收到任何连接

更新:感谢保罗的评论,我发现http://remote server:9080与公司网络之外的客户端连接是可行的。

为什么(在哪里?)来自企业网络-> 远程服务器->笔记本电脑连接本地网络[via ssh]被封锁了吗?


我尝试编辑命令的末尾使其如下所示:

… -R '*:9080:local_ip_address_of_my_laptop:3000'

但它并没有改变任何事情。

为什么它不起作用?
我该如何修复它?

在下面的日志中,我看到一行我不知道它是什么意思,也找不到原因/含义:debug1: Roaming not allowed by server

OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to remoteserver [IP_ADDRESS] port 22.
debug1: Connection established.
debug1: identity file redacted type 2
debug1: identity file redacted type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3p2 Debian-9etch3
debug1: match: OpenSSH_4.3p2 Debian-9etch3 pat OpenSSH_4*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA redacted
debug1: Host 'remoteserver' is known and matches the RSA host key.
debug1: Found key in /Users/redacted/.ssh/known_hosts:17
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering DSA public key: redacted
debug1: Server accepts key: pkalg ssh-dss blen 434
debug1: Authentication succeeded (publickey).
Authenticated to remoteserver ([ip_address]:22).
debug1: Remote connections from *:9080 forwarded to local address localhost:3000
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: remote forward success for: listen 9080, connect localhost:3000
debug1: All remote forwarding requests processed
debug1: Sending environment.
debug1: Sending env LC_CTYPE = UTF-8
debug1: Sending env LANG = 
debug1: Sending env LC_ALL = fr_FR

答案1

公司网络的传出连接无法正常工作的常见原因是防火墙阻止了会话,而不是 ssh 本身的问题。

如果您可以通过端口 22 进行访问,您可能能够执行本地端口转发而不是反向转发,具体取决于您要实现的目标。

相关内容