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
- Install the NFS server software:
$ sudo apt install nfs-kernel-server
- Add an entry in
/etc/exportsthat informs the NFS server which directory is being shared, to which computer on the network and with what settings.
For example, if user
joe_on_serverwants to share his
workspacedirectory to all computers on the network:
* 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
- If we want to share only with a specific computer on the network, then specify its IP address or hostname:
Remember to ping and be sure that the hostname or IP address works.
- If the user on the NFS client machine has a different UID or GID from the UID or GID of the directory and files being shared from the NFS server, you will get
permission deniederrors. If this is the case, then specify what UID and GID on the NFS server should be used to map all users who access on NFS client:
- Export the share:
$ sudo exportfs -a
- Restart the NFS server:
$ sudo service nfs-kernel-server restart
- Check if the share is visible:
$ showmount -e
On the NFS client machine
- Install NFS client software:
$ sudo apt install nfs-common
- Check if the share of server is visible:
$ showmount -e nfs_server_hostname
- Create a directory where you want to mount the NFS share:
$ 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.
- Add an entry in
/etc/fstabto request NFS to mount to this directory:
nfs_server_hostname:/home/joe_on_server/workspace /mnt/joe_nfs_share none bind 0 0
- Mount the NFS share:
$ 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:
- Hostname or IP should be pingable
- UID and GID of users on NFS server and NFS client machines
- If you make any change to file permissions, remember to
umounton NFS client machine and mount again.
I found the NFS Overview and Gotchas very useful to setup and debug my NFS problems.
Tried with: Ubuntu 14.04