nfs

Linux automatically mounts NFS file systems

NFS Network File System is a distributed file system protocol

2 min read
By myfreax
Linux automatically mounts NFS file systems
Linux automatically mounts NFS file systems

NFS Network File System is a distributed file system protocol that allows you to share remote directories over the network.

With NFS, you can mount remote computer directories on your system and use remote computer files as if they were local files.

The NFS protocol is unencrypted and, unlike Samba, does not provide user authentication. Use the client IP address or host name to restrict client access to the server.

In this tutorial, we'll show you how to mount an NFS share on Linux. To mount an NFS share on a Linux system, you first need to install the NFS client. Client package names vary between Linux distributions.

Install NFS client

On the client machine, we simply need to install the software tools needed to mount the remote NFS file system.

If your computer is running a Debian-based Linux distribution, such as Ubuntu, Linux mint. Run sudo apt update && sudo apt install nfs-common to install the NFS file system mounting software.

If your computer is running a Linux distribution based on RedHat, such as CentOS, Fedora. Run sudo yum install nfs-utils to install the NFS file system mounting software.

sudo apt update && sudo apt install nfs-common
sudo yum install nfs-utils

/etc/fstab Automatically mounts NFS file system

Typically, you need to automatically mount a remote NFS shared directory when your local computer starts. The /etc/fstab file contains a list of mount points that define where and how the file system will be mounted at system startup.

To automatically mount NFS shares during Linux startup, add a line to the /etc/fstab file. This line must contain the host name or IP address of the NFS server, the NFS shared directory, and the mount point of the local computer.

Create the mount point of the NFS shared directory on the local computer and run sudo mkdir /var/backups.

Then open the /etc/fstab file with your favorite text editor. In this tutorial, we will use the vim editor to open the file /etc/fstab.

10.10.0.10 is the IP address of the NFS server, /backup is the NFS shared directory, and /var/backups is the local mount point.

When the editing is complete, save the file and exit the vim editor. Then you simply run the mount command to mount the NFS file system.

The mount command reads the records in the /etc/fstab file and mounts the unmounted records.

The next time you reboot the system, the NFS shared directory will be automatically mounted.

sudo mkdir /var/backups
sudo vim /etc/fstab
sudo mount
# <file system>     <dir>       <type>   <options>   <dump>	<pass>
10.10.0.10:/backups /var/backups  nfs      defaults    0       0
/etc/fstab

If you want to specify additional mount options, specify multiple options in the column, separated by commas.

To obtain all mount options, run the man mount command on the terminal. To verify that the NFS shared directory has been successfully mounted, run the mount or df -h command.

After an NFS shared directory is successfully mounted, the mount point becomes the directory of the local file system.

The df -h command displays detailed information about the mounted file system.

df -h

conclusion

We have shown you how to mount a remote NFS share. The same command works with any Linux distribution, including Ubuntu, CentOS, RHEL, Debian, and Linux Mint. If you have any questions, please feel free to comment.