With NFS (Network File System), you can share files and folders with other systems in a network. NFS is based on a client-server architecture that allows users to remotely connect and access files through the network. With NFS, users can access shared files and folders as if they exist in their own system.
In this article, we will be discussing how to mount NFS on Debian 11 system. We will cover:
- Mounting the NFS file system manually
- Mounting the NFS file system automatically
- Unmounting the NFS file system
We have used Debian 11 machine for explaining the commands and procedures mentioned in this article. More or less the same procedure can be followed in Ubuntu and older Debian distributions.
We will run the commands on Debian Terminal. To open the Terminal, hit the super key on your keyboard and search for it using the search bar that appears. From the results, click the Terminal application to open it.
If you do not have an NFS server yet, see here how to configure NFS server on Debian and NFS server on Ubuntu.
Prerequisites
For the client machine:
- Debian 11 or Debian 10
- User with sudo privileges
For the remote server:
- NFS server is installed
- NFS server shared directory is exported
- NFS clients are allowed through the firewall
Once you have the above prerequisites completed, you can follow the below procedures in order to mount NFS on the client machine.
Install NFS Client Package on the client machine
You will need to install the NFS client package on the client machine in order to mount share directories on it. To install the NFS client package on the client computer, run the following commands in the Terminal:
$ sudo apt install nfs-common
After running the above command, the system might ask for confirmation if you want to continue the installation or not. Press y to continue, after that, the NFS client package will be installed on your system.
Step 1: Create a mount point for the shared directory of NFS server’s
You will need to create an empty directory for the mount points on the client machine. This empty directory will act as the mount point for the folders shared remotely.
Under the directory /mnt, we created a new mount folder “client_sharedfolder” using the below command:Advertisement
$ sudo mkdir -p /mnt/client_ shareddirectory
Step 2: Mount the NFS server shared folder on the client
Use the following syntax to mount the shared NFS folder into the client’s mount point directory.
$ sudo mount [nfs_server]:/[nfs_shareddirectory] [client_mountpoint]
Where
- [nfs_server] is the NFS server’s IP address which you can find by running the “$ ip a” command on the NFS server.
- [nfs_ shareddirectory] is the shared folder on the NFS server
- [client_mountpoint] is the mount point folder on the client’s machine
From the above screenshot, you can see that 192.168.72.144 is the IP address of the NFS server. The /mnt/sharedfolder is the shared folder on the NFS server and the /mnt/client_sharedfolder is the mount point folder on the client’s machine.
Once you have mounted the NFS server shared folder on the client machine, you can verify it. Issue the following command in Terminal to do so:
$ df -h
From the above screenshot, you can see the shared folder mounted on the client’s machine mount point.
Step 3: Verify NFS share
Once the NFS server share is mounted on the NFS client, try to access some files located on the server machine. Create any test file or directory on the NFS server computer, and try to access it from the client system.
In the NFS server machine, move inside the shared folder and create some files or folders.
Now in the client machine, issue the following command to check if these files exist:
$ ls /mnt/client_sharedfolder/
The method we have discussed above only mounts the file system temporarily on the client’s system. After you restart the system, the NFS file system will no longer remain mounted on the system.
Mount an NFS File System automatically
You also have the option to automatically mount the file system. It saves you from the hassle of mounting the file system manually every time the machine is restarted. For this purpose, you will need to edit the /etc/fstab file. Issue the following command in Terminal in order to do so:
$ sudo nano /etc/fstab
Then insert an entry in this file using the below syntax:
[nfs_server]: [nfs_shareddirectory] [client_mountpoint] nfs defaults 0 0
Where:
- [nfs_server] is the NFS server’s IP address
- [nfs_shareddirectory] is the shared folder on the NFS server
- [client_mountpoint] is the mount point on the client’s machine
- nfs is the file system type.
From the above screenshot, you can see that the 192.168.72.144 is the IP address of the NFS server, /mnt/sharedfolder is the shared folder on the NFS server and the /mnt/client_sharedfolder is the mount point on the client’s machine.
Once you have done with the above configurations, save, and close the /etc/fstab file. Now when you will restart the system, the NFS file system will be automatically mounted at the specified mount point.
Unmount the NFS File System
If you do not want the NFS file system to remain mounted anymore, you can unmount it from the client’s machine. To do so, issue the following command in Terminal:
$ sudo umount [mountpoint_name]
Replace the [mountpoint_name] by the actual name of your mount point folder.
Note: Mounting the NFS files system using the /etc/fstab file automatically mounts the file system to the specified mount point on the next restart even if you unmount it using the umount command.
Mounting the NFS file system on Linux is an easy task for storing and accessing the files through the network. In this article, you have learned about mounting and unmounting the NFS file system on the Debian 11 machine. I hope it will be helpful if you ever need to mount or mount the NFS file system on any Debian or Ubuntu machines.