這是一個後續我的評論發佈到問題本身。
允許客戶端(客戶端)訪問直接或通過同一個網絡服務器(網關)通過SSH在另一臺計算機的遠程計算機(服務器)上的端口,你只需要使用-L標誌。
從客戶機到服務器直接(端口8080的客戶機上就會隧道80在服務器上):
ssh -L 8080:localhost:80 server
從客戶機到服務器通過客戶機上的網關(端口8080將隧道80服務器)上:
ssh -L 8080:server:80 gateway
從手冊頁的ssh,這裏是你如何使用-L標誌:
-L [bind_address:]port:host:hostport
Specifies that the given port on the local (client) host is to be
forwarded to the given host and port on the remote side. This
works by allocating a socket to listen to port on the local side,
optionally bound to the specified bind_address. Whenever a
connection is made to this port, the connection is forwarded over
the secure channel, and a connection is made to host port
hostport from the remote machine. Port forwardings can also be
specified in the configuration file. IPv6 addresses can be
specified by enclosing the address in square brackets. Only the
superuser can forward privileged ports. By default, the local
port is bound in accordance with the GatewayPorts setting.
However, an explicit bind_address may be used to bind the
connection to a specific address. The bind_address of
``localhost'' indicates that the listening port be bound for
local use only, while an empty address or `*' indicates that the
port should be available from all interfaces.
這並不完全回答你的問題,但我會以不同的方式處理。我會將SSH連接與應用程序分開。你有沒有想過爲你所說的兩個通道中的每一個打開一個端口,然後如果客戶端不能直接訪問這些端口,你可以讓它們通過ssh連接上的'-L'標誌通過ssh連接來通道這些端口命令? – bohney
@bohney:+1。更簡單,更容易設置和維護。 – Axel
不知道我明白,但我基本上是爲我們使用的第三方服務編寫模擬,所以我對建築選項有點限制。另外,我將它集成到Akka應用程序中(在scala中) – Alexandre