ssh連接埠轉發

ssh連接埠轉發

我想使用 ssh 隧道連接到使用特定機器的一組機器。但在找到的所有解決方案中,我需要在 ssh 設定檔中為每台機器指定一個條目。我想以這種方式使用通配符:

   Host *.mydomain.com
   // some magic here

目前,找到的最佳解決方案是:

http://magazine.redhat.com/2007/11/27/advanced-ssh-configuration-and-tunneling-we-dont-need-no-stinking-vpn-software/

答案1

如果您可以在隧道伺服器上執行諸如ncnetcat之類的程序,則可以使用 a而不是連接埠轉送:socatProxyCommand

# Only necessary if it matches the *.mydomain.com wildcard. Useless otherwise.
Host tunnelbox.mydomain.com
    ProxyCommand none

Host *.mydomain.com
    ProxyCommand ssh tunnelbox.mydomain.com nc %h %p
    #ProxyCommand ssh tunnelbox.mydomain.com ncat %h %p
    #ProxyCommand ssh tunnelbox.mydomain.com socat stdio tcp:%h:%p
    #ProxyCommand ssh tunnelbox.mydomain.com netcat %h %p

根據隧道伺服器安裝的工具,取消註解對應的 ProxyCommand。


請注意,這將為每個建立的隧道建立和拆除單獨的 SSH 連接,這意味著連接將比透過 SOCKS 慢。 (不會影響性能然而,連接。

如果您的 SSH 版本支持,您可以啟用連線重複使用:

Host tunnelbox.mydomain.com
    ControlMaster no
    ControlPath none

Host *.mydomain.com
    ControlMaster auto
    ControlPath ~/.ssh/S.%l.%r@%h:%p
    ControlPersist 10m

相關內容