NFS, also called “Network File System,” is a network file-sharing protocol that allows us to share and mount a remote file system over the network. It works in a client-server architecture and allows multiple systems or users to access the same shared folder or file. With NFS, you can share a common application among multiple users, eliminating the need for local disk space and reducing storage costs.
This post will show you how to install and configure an NFS server on Debian 11.
Step 1 – Update Server
Once logged in to your server, run the following command to update your base system with the latest available packages.
apt-get update -y
Step 2 – Install NFS Server
The NFS package is included in the Debian 11 default repository by default. You can install it by just running the following command:
apt-get install nfs-kernel-server -y
Once the NFS server has been installed, you can proceed to the next step.
Also Read
How to Install FTP Server with ProFTPD on Oracle Linux 8
Step 3 – Create the Export Directory
Next, you must create a directory you want to share with the client machine. You can create it with the following command:
mkdir /nfsshare
Next, create some files inside the shared directory:
touch /nfsshare/file1.txt touch /nfsshare/file2.txt
Next, set proper permissions on the created directory:
chown nobody:nogroup /nfsshare chmod 755 /nfsshare
Also Read
How to Use chown (Change Ownership) Command in Linux
Step 4 – Configure the Export Directory
Next, you must edit the NFS server’s main configuration file and define the directory path you want to share. You can do it with the following command:
nano /etc/exports
Add the next line:
/nfsshare nfs-client-ip(rw,sync,no_subtree_check)
Where:
- RW – Provide read and write access to the shared directory.
- sync – Reply to requests only after the changes have been committed to stable storage.
- no_subtree_check – Disables subtree checking.
Save and close the file when you are finished. Finally, restart the NFS service to apply the changes:
systemctl restart nfs-server
You can check the status of NFS using the following command:
systemctl status nfs-server
You will get the following output:
● nfs-server.service - NFS server and services Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; vendor preset: enabled) Active: active (exited) since Sat 2022-01-29 05:50:54 UTC; 6s ago Process: 2117 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS) Process: 2118 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS) Main PID: 2118 (code=exited, status=0/SUCCESS) CPU: 7ms Jan 29 05:50:53 nfsserver systemd[1]: Starting NFS server and services... Jan 29 05:50:54 nfsserver systemd[1]: Finished NFS server and services.
Step 5 – Install and Configure NFS Client
Next, you must install the NFS client package on the remote system and access the NFS share.
Run the following command to install the NFS client package:
apt-get install nfs-common -y
Now, mount the remote shared directory on the /mnt directory using the following command:
mount nfs-server-ip:/nfsshare /mnt
Next, verify the NFS mount using the following command:
df -h
You should see the NFS mount in the following output:
Filesystem Size Used Avail Use% Mounted on udev 976M 0 976M 0% /dev tmpfs 199M 388K 198M 1% /run /dev/sda1 50G 1.5G 46G 4% / tmpfs 992M 0 992M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 199M 0 199M 0% /run/user/0 69.28.91.99:/nfsshare 50G 1.5G 46G 4% /mnt
You can also list all files inside the shared directory using the following command:
ls -l /mnt
You will get the following result:
-rw-r--r-- 1 root root 0 Jan 29 05:49 file1.txt -rw-r--r-- 1 root root 0 Jan 29 05:50 file2.txt
Conclusion
In the above guide, we explained how to set up an NFS server on Debian 11. We also explained how to access the NFS share from the client machine. Create a file server for your organization on dedicated hosts from Atlantic.Net!