Home » » How do I mount a NFS share with NFS version 4 (nfs4) through an encrypted SSH tunnel ?

How do I mount a NFS share with NFS version 4 (nfs4) through an encrypted SSH tunnel ?

Written By 1 on Tuesday, June 14, 2011 | 3:15 AM

Resolution:
The basic setup is similar to a normal mount process with nfs shares, except some config changes and that the IP addresses are changed to 127.0.0.1 (the loopback address). Here is the configuration on the server as well as the client:

Server Configuration:

  1. In the /etc/exports file, the share is exported by inserting the following line: 

    /myshare      127.0.0.1(rw,fsid=0,insecure,no_subtree_check,sync)

  2. Re-export the share or restart the nfs service: 

    # exportfs -rv
    exporting localhost.localdomain:/myshare
    or 

    # exportfs -v
    /myshare        localhost.localdomain(rw,wdelay,insecure,root_squash,no_subtree_check,fsid=0)


The server configuration is done.

Client Configuration:

  1. In the /etc/fstab file, give the mount parameters as follows: 

    127.0.0.1:/     /mnt/nfs4       nfs4    rw,hard,intr,proto=tcp,port=3333,noauto  0 0

  2. Now setup an SSH tunnel with port forwarding. Any encryption can be used, for example the blowfish encryption is used here. The standard port for nfs mount is 2049, but for the local port, it is not compulsory to use this port. Any random port can be used and the NFSv4 clients and SSH tunnels do not care which ports they use. Open up an SSH session from the NFS client to the NFS server: 

    # ssh -c blowfish -L 3333:127.0.0.1:2049 <server-address>
    root@server's password:

  3. Back on the NFS client host (client), open another terminal session as "root" and then mount the filesystem: 

    # mount -v /mnt/nfs4
    127.0.0.1:/ on /mnt/nfs4 type nfs4 (rw,hard,intr,proto=tcp,port=3333,addr=127.0.0.1)
    The NFSv4 share will be mounted as if it were local, but actually it is an encrypted remote filesystem.
  4. In order to unmount it, first use the command: 

    # umount -v /mnt/nfs4

  5. Exit the SSH session.

0 Comment:

Post a Comment