通过SSH反向隧道挂载NFS服务器

这是我的设置:

  • 办公室计算机在networking中,无法从外部访问,(OC)
  • embedded式计算机领域(FC)
  • 服务器在办公室,包含现场计算机需要访问的数据。 办公室计算机从这台服务器挂载一个目录,它是NFS

我经常通过SSH在现场计算机上工作,问题是从现场计算机访问办公室服务器上的数据。

到目前为止,我通过用sshfs将现场计算机安装在办公室计算机上解决了这个问题。 它工作正常,但它有缺点。 我想直接从我的SSH会话中获取和推送信息,而不是从本地办公室计算机上的另一个本地会话中获取信息(例如,从sshfs挂载点运行git的速度非常慢)。

我知道这可以通过SSH反向隧道来实现。

这是我试过的,从办公室计算机(OC)login到现场计算机(FC):

 gauthier@OC $ ssh -R 9001:<nfs_server_name>:2049 FC 

(FC在我的~/.ssh/config

据我了解,这将打开FC上的端口9001,以听取端口2049上的OC的<nfs_server_name>的想法。

9001可以是任何不保留的,2049是NFS的端口。

我可以从OC中ping <nfs_server_name>

SSH到FC之后,我尝试挂载端口为NFS:

 gauthier@FC $ mkdir mp_test gauthier@FC $ sudo mount -t nfs localhost:9001 mp_test/ 

这只是挂起,然后超时。

我以为我可能需要在NFS服务器上给path,所以我也试过:

 gauthier@FC $ sudo mount -t nfs localhost:9001:/path/to/directory/I/usually/mount mp_test/ 

显然我做错了,无论是与端口或与mount

一直在努力的是使FC的端口9001在端口80上监听OC的<nfs_server_name> 。然后我可以在FC上打开localhost:9001并查看NFS服务器的Web界面。 这让我觉得我相当接近。

如何在现场计算机上安装办公室NFS服务器目录?


经过一些更多的search ,我试过这个:

 gauthier@OC $ ssh -R 5100:<server>:2049 -R 5200:<server>:2233 FC gauthier@FC $ sudo mount -v -t nfs -o port=5100,mountport=5200 localhost:/path/to/share/dir mp_test [sudo] password for gauthier: mount.nfs: timeout set for Thu Apr 30 14:14:27 2015 mount.nfs: trying text-based options 'port=5100,mountport=5200,vers=4,addr=127.0.0.1,clientaddr=127.0.0.1' mount.nfs: mount(2): Protocol not supported mount.nfs: trying text-based options 'port=5100,mountport=5200,addr=127.0.0.1' mount.nfs: prog 100003, trying vers=3, prot=6 mount.nfs: portmap query retrying: RPC: Program not registered mount.nfs: prog 100003, trying vers=3, prot=17 mount.nfs: portmap query failed: RPC: Program not registered mount.nfs: requested NFS version or transport protocol is not supported 

tcp (在这一点上,你可以看到我正在尝试黑魔法公式,而不理解我在做什么:/):

 gauthier@FC $ sudo mount -v -t nfs -o tcp,port=5100,mountport=5200 localhost:/path/to/share/dir mp_test/ mount.nfs: timeout set for Thu Apr 30 14:15:04 2015 mount.nfs: trying text-based options 'tcp,port=5100,mountport=5200,vers=4,addr=127.0.0.1,clientaddr=127.0.0.1' mount.nfs: mount(2): Protocol not supported mount.nfs: trying text-based options 'tcp,port=5100,mountport=5200,addr=127.0.0.1' connect_to <server> port 2233: failed. connect_to <server> port 2233: failed. connect_to <server> port 2233: failed.