Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to setup NFS server and client

📅 2013-Mar-17 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

NFS is a popular method to share a directory for read and write access between two Linux computers. The computer whose hard disk where the shared directory actually resides is the NFS server. The computer which will mount the directory on the NFS server for read and write access is the NFS client.

On the NFS server computer

$ sudo apt install nfs-kernel-server
/home/joe_on_server/workspace *(rw,sync,no_subtree_check)

The * indicates that NFS clients of all IP addresses can access this shared filesystem. rw indicates that the NFS client can read and write to this directory. async improves performance. no_subtree_check also improves performance by not checking the sub-directories. no_root_squash prevents the normal behavior of converting access by root user to normal user. insecure turns off the checking if the access is originating from reserved ports. More information about the options can be seen in man exports.

/home/joe_on_server/workspace 192.168.0.100(rw,sync,no_subtree_check)

Remember to ping and be sure that the hostname or IP address works.

/home/joe_on_server/workspace 192.168.0.100(rw,sync,no_subtree_check,all_squash,anonuid=1001,anongid=1001)
$ sudo exportfs -a
$ sudo service nfs-kernel-server restart
$ showmount -e

On the NFS client machine

$ sudo apt install nfs-common
$ showmount -e nfs_server_hostname
$ sudo mkdir /mnt/joe_nfs_share

I do not recommend mounting to a directory inside your home directory. This can lead to all kinds of irritating UID and GID permission problems.

nfs_server_hostname:/home/joe_on_server/workspace  /mnt/joe_nfs_share none bind 0 0
$ sudo mount /mnt/joe_nfs_share

That is it! You should be able to have read and write access to files in your NFS share on the client machine.

If you run into any problems, please check these:

I found the NFS Overview and Gotchas very useful to setup and debug my NFS problems.

Tried with: Ubuntu 14.04