1. Ensure the NFS client is installed
First, verify that the NFS client is installed on the system. Use the following command to install:
bashsudo apt-get install nfs-common # For Debian-based systems, such as Ubuntu
Or, for RPM-based systems, such as CentOS:
bashsudo yum install nfs-utils
2. Create a mount point
Next, create a directory to serve as the local mount point for the NFS share:
bashsudo mkdir /mnt/nfs_share
3. Edit the /etc/fstab file
The /etc/fstab file defines filesystems that are automatically mounted at system boot. Edit this file to add a line specifying the NFS server details and mount configuration.
Assuming the NFS server IP is 192.168.1.100 and the shared directory is /exported/path, the added line would be:
plaintext192.168.1.100:/exported/path /mnt/nfs_share nfs defaults 0 0
Here, defaults specifies the use of default mount options, and 0 0 are the dump and pass options for the filesystem, typically set to 0 for NFS mounts.
4. Test the mount configuration
Before rebooting, verify the mount by manually testing:
bashsudo mount -a
This command attempts to mount all filesystems defined in /etc/fstab. If successful, check the mount result with:
bashdf -h
Or:
bashmount | grep nfs
5. Verify after system reboot
Finally, reboot the system to ensure the mount occurs automatically at boot:
bashsudo reboot
After rebooting, run df -h or mount | grep nfs again to confirm that the NFS share is automatically mounted.
Example
For instance, in my previous work, we needed to ensure application servers automatically connected to a central NFS server upon each boot to retrieve configuration files and application data. By following these steps, we ensured services could immediately resume after system restarts while maintaining configuration consistency and data availability.
This configuration method is general-purpose and applicable to most Linux distributions. Adjust mount options such as read-only (ro) or read-write (rw) to meet specific application requirements.