The Network File System is a protocol originally developed by Sun Microsystems. It provides a way to share directories under Unix operating systems in a similar way to Samba. This article describes how to set up an NFS share between two similar Unix-based systems, FreeBSD and Linux. For a background on FreeBSD's way of doing things, see NFS Server.
Above an output of the df command indicates both local file system usage and a remote directory running on a remote system, 10.0.0.5:/files, which is mounted to the local directory /files. It looks and works in a similar way to mapped network shares using Samba.
By definition, the NFS Server makes one or more directories available for the NFS Client to connect to. Once the client has connected, the directory appears and behaves like a local directory - albeit slightly slower, depending on network performance.
Install NFS Server Support
1. Open a terminal and run the following command..
sudo apt-get install nfs-kernel-server nfs-common portmap
Note when configuring portmap do =not= bind loopback..
2. Create a directory on the server which will be shared with the client..
sudo mkdir /files
3. The /etc/exports file is used for creating a share on the NFS server. Crank up your editor-of-choice and add an entry to the end of the file..
sudo vi /etc/exports
# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
/files 10.0.0.100 (ro,async)
In the above example the new directory is made available to another system of specified IP Address, with additional rules in brackets.
4. Save and close the file and then run the following command in a terminal..
sudo /etc/init.d/nfs-kernel-server restart
5. After making changes to /etc/exports, it is also necessary to type:
sudo exportfs -a
Install NFS Client Support
1. Run the following command in a terminal..
sudo apt-get install portmap nfs-common
2. Create a directory on the client which will be mounted to the server's directory..
sudo mkdir /music
3. The systems should now be ready to connect. Run the command to mount the server's directory locally..
sudo mount 10.0.0.5:/files /music
Note if things don't work at first it may be necessary to restart the following services thus..
sudo /etc/init.d/portmap restart
sudo /etc/init.d/nfs-common restart
Mounting at boot using /etc/fstab
On the client, edit fstab and add the above mount command to the end of the file..
sudo vi /etc/fstab
Again many options exist, such as in this example..
-fstype=nfs,soft,intr,rsize=8192,wsize=8192,nosuid server.example.com:/home
The Red Hat NFS Manual notes some common mount point options:
- hard or soft specifies whether the program using a file via an NFS connection should stop and wait (hard) for the server to come back online if the host serving the exported file system is unavailable, or if it should report an error (soft).
- If hard is specified, the user cannot terminate the process waiting for the NFS communication to resume unless intr option is also specified.
- If soft, is specified, the user can set an additional timeo=<value> option, where <value> specifies the number of seconds to pass before the error is reported.
- intr allows NFS requests to be interrupted if the server goes down or cannot be reached.
- nolock is occasionally required when connecting to older NFS server. To require locking, use the lock option.
- noexec does not permit the execution of binaries on the mounted file system. This is useful if the system is mounting a non-Linux file system via NFS that contains
incompatible binaries.
- nosuid does not allow set-user-identifier or set-group-identifier bits to take effect.
- rsize=8192 and wsize=8192 may speed up NFS communication for reads (rsize) and writes (wsize) by setting a larger data block size, in bytes, to be transferred at one time. Be careful when changing these values; some older Linux kernels and network cards may not work well with larger block sizes.
- nfsvers=2 or nfsvers=3 specify which version of the NFS protocol to use.
Further Reading
Mounting NFS Filesystems (Red Hat Linux)
How NFS Works (FreeBSD)
Ubuntu Linux NFS Client Configuration to mount nfs share
- A.