Last Updated: February 25, 2016
·
1.084K
· pmaoui

How to share a folder between 2 servers with NFS

Server-side configuration

You need to install nfs-kernel-server

NFS is a pseudo filesystem. You will need to mount a folder with the option --bind :

mount --bind /home/user/folder_to_share /nfs_share/folder

and set that permanently with :

/home/user/folder_to_share /nfs_share/folder none bind 0 0

About permissions, put in /etc/idmapd.conf :

[Mapping]
Nobody-User = nobody
Nobody-Group = nogroup

It permits to the server and the client to doesn't share their UID et GUID

Then to activate the share, put in /etc/exports :

/nfs_share/         x.x.x.x/24(rw,fsid=0,insecure,no_subtree_check,async)
/nfs_share/nfs_test x.x.x.x/24(rw,nohide,insecure,no_subtree_check,async)

Client-side configuration

You need to install nfs-common

Configuration is in /etc/default/nfs-common :

NEED_IDMAPD=yes (uid and guid will be matched based on name)

Activate the NFS module with :

sudo modprobe nfs
mount -t nfs4 -o proto=tcp,port=2049 IP_NFS_SERVER:/nfs_test /mnt

And then you should be able to read and write on the remote folder from the client. Thank you for reading. Tell me if anything goes wrong.

1 Response
Add your response

Nice one. You can also use SSHFS if you don't need the whole performance stuff, cannot setup new services or are concerned about encryption if you cannot install NFS 4 (providing that SSH is already set up on the remote of course).

over 1 year ago ·