ssh -NfR 远端主机listen port : 远端连回时导向的主机 : 远端连回本地主机时导向主机的port帐号@远端主机
ssh参数解释:
-N:不执行任何指令
-f:背景执行
-R:主要建立reverse tunnel的参数
具体实例:
1.在内网主机建立从内网到外网的tunnel
#ssh -p 6120 -NfR 10086:localhost:22 la@67.217.*.22
2.在外网主机上建立到内网的连接
#ssh -p 10086 lai@localhost
问题:若要在任何时候都能连接到内网,则必须保证从内网主机建立的到外网主机的连接不掉线。为了要预防ssh tunnel断线,第一种方式请在.ssh/config内加入「serveraliveinterval 60」保持KeepAlive连线;第二种可以透过autossh帮忙维持连线,若有任何断线会再自动帮忙连线。
* the connection between destination and source must be alive at all time.
Tip: you may run a command (e.g. watch, top) on Destination to keep the connection active.