Linux Commands

How To Mount And Use NFS Shares On Linux Sharing Files Easily Using NSF

Developed by Sun Microsystems in 1984, NFS or Network File Shares is a file system protocol used for accessing files over a network similar to a local storage device.

NFS Shares are powerful and popular as they allow users to share files and directories over a local network and the internet. However, it is better to limit NFS shares to local and trusted networks as files don’t get encrypted on the machines. However, the problem was addressed and fixed on a recent version of the NFS protocol. You may need to set up complex authentication methods such as Kerberos.

This tutorial will walk you through how to set up NFS shares on a Linux system. Let us get started.

Setting up NFS Server

Let us start by setting up the NFS server. This process is fairly simple, with only a few commands:

sudo apt-get update

sudo apt-get install nfs-kernel-server

Next, create a directory in the local system which will be used as the NFS’ share root directory:

sudo mkdir /var/nfs

Set the appropriate permissions to the directory:

sudo chown nobody:nogroup /var/nfs

Next, edit the exports file in /etc/exports and add the following entry

/var/nfs <hostname>(rw,sync,root_squash,no_subtree_check)

Setting Up An NFS Client

For you to mount NFS Shares on Linux, you will need to install nfs client tools using the command:

sudo apt-get update
sudo apt-get install nfs-common

Mounting an NFS Filesystem

The process of mounting NFS file shares is very similar to mounting a regular file system in Linux. You can use the command mount. The general syntax is as:

mount <option> <nfs-server-address>:<export-directory> <mount-point>

To accomplish this, start by creating a directory to use as the NFS Share’s mount point.

sudo mkdir /mnt/shares

Next, mount the NFS share using the mount command as shown below:

sudo mount –t nfs 127.0.0.1/var/nfs /mnt/shares

Once completed, you should have access to the remote shares on the server.

Unmounting File shares

Since an NFS share is similar to a file system, you can unmount it with umount command as:

sudo umount <ip-address>/var/nfs
sudo umount /mnt/shares

You can use other options with umount command, such as a force to force-unmount the NFS shares.

Conclusion

The above is a simple guide on how to use and mount NFS shares on a Linux system. There is more to NFS than what we have discussed here; feel free to utilize external resources to learn more.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list