NFS mounts have two parts. The first part is the server that hosts the share point. The second part is the client that access the share point. You can have one or more clients accessing the same share point on an NFS server, similar to an SMB or AFP share
For the following tutorial we will assume the following IP addresses:
Server: 10.0.0.10
Client: 10.0.0.101
Set Up the NFS Server
First we need to use yum to install the required software on the server
sudo yum install nfs-utils nfs-utils-lib
Next, start up the NFS daemon
sudo chkconfig nfs on
sudo service rpcbind start
sudo service nfs start
Export the Shared Directory
You now need a directory that you want to share to the network client(s). By editing the file /etc/exports we can specify one or more directories to share as well as options and permissions for them
As an example, we’ll share the directory /home
First edit the exports file in /etc
sudo vi /etc/exports
Specify that this directory is to be shared by adding the following lines to the bottom of the file
/home 10.0.0.101(rw,sync,no_root_squash,no_subtree_check)
These settings accomplish several tasks:
rw: Allows both read and write requests on this NFS volume. The default if this is not specified is to make the share read-only for network clients.
sync: Replies to requests only after the changes have been committed to stable storage. This means that the NFS server will only tell the client that it’s done when it’s written all changes to disk, not just when it’s received the data and it’s still in the cache before it’s been written.
no_subtree_check: Tells the NFS server to not check the entire subtree for permissions. When checking to see if you have permissions to access a particular file or folder, it doesn’t check all the way back up the directory tree to the root directory, it just checks up as far as the directory that is the top-level of the NFS share. This is a bit less secure but generally makes things work more reliably.
no_root_squash: This setting lets the root user connect, as root, to an NFS share. By default NFS will connect the root user on one machine to a share as a non-root user for security.
Once you have edited the exports file, save it (esc, :, w, q if using vi) and then run exportfs to update the mounts
exportfs -a
Set up the NFS client
As before, install the NFS software using yum:
sudo yum install nfs-utils nfs-utils-lib
Mount the MFS Share
Make a directory on the client machine that you want to mount the NFS server on, e.g.:
sudo mkdir -p /mnt/nfs/home
Start the RPC portmapper
sudo service rpcbind start
And then, mount the NFS server onto the directory you have just created
sudo mount 10.0.0.10:/home /mnt/nfs/home
You can then use the mount command to check that it’s mounted and then df -h to see that there’s another filesystem there with it’s own free space. Testing the NFS Mount.
To make sure that the NFS share is remounted when the server is restarted, add it to the fstab
sudo vi /etc/fstab
10.0.0.10:/home /mnt/nfs/home nfs auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0