How Can We Help?
< All Topics
Print

Enabling Network File System (NFS) on Your VPS: A Comprehensive Guide

The Network File System (NFS) is a network protocol that facilitates distributed file sharing, improving file management efficiency by defining the storage and retrieval of data from storage devices such as hard drives, solid-state drives, and tape drives across a network.

a) Linux

Network File System

1. First, open a terminal, execute the sudo apt update and sudo apt install nfs-kernel-server commands, then enter Y and press ENTER to install the NFS server.

2. Then, type the sudo mkdir -p /mnt/nfs_share command to create a directory that is shared by all client systems.

3. Next, enter the sudo chown -R nobody:nogroup /mnt/nfs_share/ command to set permissions, and enter the sudo chmod 777 /mnt/nfs_share/ command to set the file permissions of the “nfs-share” directory file.

4. After that, enter the sudo nano /etc/exports command to grant access to the client system. If you prefer VIM, you can enter the sudo vim /etc/exports command there.

5. Next, enter /mnt/nfs_share ”EntireSubnetIP” (rw,sync,no_subtree_check). command to specify access to a subnet, single client, or multiple clients, and then press CTRL+O to save the file.

The above command does:

  • The “rw” option allows the client to access both read and write access to the server directory.
  • Sync” allows modifications to be written to NFS, ensuring clients can always see the host’s actual actions.
  • The subtree process may cause issues when the user renames a file, as no subtree checking is disabled.

6. The /mnt/nfs_share client_IP_1 (re,sync,no_subtree_check) command allows access to a single client, while the /mnt/nfs_share client_IP_1 (re,sync,no_subtree_check)  /mnt/nfs_share client_IP_2 (re,sync,no_subtree_check) order allows access to multiple clients.

7. Then, use the sudo exportfs -a command to export all registered shared directories in a file, and then use the sudo systemctl restart nfs-kernel-server command to restart the NFS kernel server.

8. After that, if you are using UFW, type sudo ufw allowed from [clientIP or clientSubnetIP] to any port nfs command to allow clients to access the server. If the firewall is off, type the sudo ufw enable command. Check for changes using the sudo ufw status command.

9. Next, use sudo apt update and sudo apt install nfs-common commands to install the NFS client for Debian and Ubuntu, or sudo yum install nfs-utils commands for CentOS and Fedora, then type y and press ENTER.

10. Then, enter the sudo mkdir -p /mnt/nfsdir_client command to create a mount point, enter the sudo mount host_IP:/mnt/nfsdir /mnt/nfsdir_client command to mount the shared directory on the client system, and then enter the df -h command to verify it. To unmount a shared folder, you can type the sudo umount /mnt/nfsdir_client command. Note: Watch to not run ‘’unmount’’ instead of umount.

11. After that, create some files in the NFS share directory on the server by typing cd /mnt/nfs_share/ and touching file1.txt, file2.txt, and file3.txt to check if your NFS setup is working properly.

12. Next, enter the ls -l /mnt/nfs_clientshare/ command to check if the file exists in the directory.

13. Then, use the sudo nano /etc/fstab or sudo vim /etc/fstab command to maintain the folder mounted after restarting the computer.

14. Next,copy the following lines to the file’s bottom: host_IP:/mnt/nfsdir /mnt/nfsdir_client nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0 and add this line to any desired folder.

15. To remove the NFS server, use the command sudo apt-remove nfs-kernel-server.

16. To remove the NFS client, use the command sudo apt-remove nfs-common.

b) Windows

1. First, press the Win + X buttons or click the Start button, search for Server Manager, and click it to open Server Manager in Windows Server.

2. Then, click on the Manage option in the upper right corner and select Add Roles and Features. On the Before You Begin page before clicking the Next button to continue.

3. Next, select the “Role-based or feature-based” installation option and click “Next” to proceed with the installation process.

4. Then, click the Select server from server pool option in the Server Selection section, and then click “Nextto mount NFS on a target server.

5. After that, navigate to the Select Server Role page and select the “Server for NFS” option. If not, expand File and Storage Services and select File and iSCSI Services. In a pop-up window, add and confirm required features by clicking “Add Features” > “Next“.

6. Next, check the added features and click the “Next” button on the “Select Features” page, since you have already added the required features.

7. Then, review and confirm the installation selection on the Confirm Installation Selection page, then click the Install button to install the NFS server.

8. Finally, wait until it completes the installation before clicking the “Close” button.

Configure and create NFS shares on Windows Server.

1. First, open Server Manager and expand File and Storage Services on the left side of the screen to access the Shares option.

2. Then, click on Tasks in the sharing window’s upper right corner and choose “New Share” from the drop-down menu to create a new share.

3. The New Share wizard allows users to select a profile for a NFS share, choosing between the NFS Share-Quick and NFS Share-Advanced options. The “NFS Share-Fast” option is suitable for basic settings, while “NFS Share-Advanced” allows advanced settings like folder owners, data classification, access policies, and quotas. For this task, the NFS Share-Quick option is preferred, and click Next.

4. After that, select the server and custom path for this share section, choose Type a custom path option, use the Browse button to select the desired directory and folder, and click Next to create an NFS share.

5. Next, provide a specific name for the NFS share and select the Next button on the Share Name page to create an NFS share.

6. The Authentication section allows you to select the appropriate authentication method for the NFS share, assign client Kerberos authentication, and mark items in the Serverless Authentication section to enable clients without Kerberos to access the NFS share:

  • Serverless Authentication (AUTH_SYS)
  • Enable unmapped user access.
  • Allow unmapped user access via UID or GID.

7. To access the NFS share, go to the Specify Share Permissions page and add the NFS clients you want to access. Select “All machines” to grant permissions to all machines. To allow read and write access, expand the sharing permissions menu and select “Read/Write“. Add the permissions and return to the Specify Sharing Permissions page. Click next to proceed.

8. Check the permissions you set on the Specify Permissions to Control Access page, and after confirming the assigned permissions, click the Next button.

9. Confirm the NFS share settings’ accuracy on the Confirm Selection page, then click the Create button, and after completing the share creation process, click the Close button.

10. To create an NFS share, open Server Manager, navigate to File and Storage Services > Shares, and verify that the share has been created.

Table of Contents