NFS stands for Network File Share and it’s a common protocol used for sharing files and directories over a local or public network. In simple terms, it is a shared directory where other clients (computers, servers) can easily access them.
In this article we will show the simple steps of installing and configuring the NFS server on Ubuntu 22.04 and Debian 22 servers; the commands are identical for both environments.
Steps to Install NFS Server on Debian 12 & Ubuntu 22.04
While writing this tutorial we used the root account on a Debian 12 server. If you are using a non-root account please prepend “sudo” in all of the following commands, e.g. sudo apt update.
Step 1: Update Packages
First step is to update our system’s packages by running this command:
root@localhost:~$ apt update -y
Step 2: Install NFS Server
You are now ready to install NFS Server on your Ubuntu or Debian server through apt, as follows:
root@localhost:~$ apt install nfs-kernel-server -y
Sample Output:
At this point NFS has been successfully installed on your system. We are not done yet though. Let’s proceed to configure our NFS server so remote NFS clients can start connecting to it.
Steps to Configure NFS Server on Debian 12 & Ubuntu 22.04
Step 1: Create the directory to be shared
In our example we are creating the directory named “share_me” under /home.
root@localhost:~$ mkdir /home/share_me
Step 2: Set directory & file permissions
It is important to set the right permissions on your newly created directory, so that all client machines can access it:
root@localhost:~$ chown -R nobody:nogroup /home/share_me
In similar way, we set the permissions for the files. In our example we are giving permissions to read, write and execute to all files under /home/share_me:
root@localhost:~$ chmod 777 /home/share_me/
Step 3: Grant NFS Access
This is the most important step in configuring an NFS server. The right access must be given depending on who you want to be able to access your shared directory.
Edit the file /etc/exports using the nano editor:
root@localhost:~$ nano /etc/exports
Add the following line(s) in the end of the file:
/home/share_me 192.168.10.3/32 (rw,sync,subtree_check)
/home/share_me 172.16.1.230/32 (rw,sync,subtree_check)
In our example, we have granted access to two individual IPs (192.168.10.3 , 172.16.1.230) to access our NFS Shared directory. Feel free to adjust as needed.
Regarding the parameters that follow the IP address, please take a look at this guide.
Now, save and exit the file.
Step 4: Export the NFS directory
The following command will export your newly created NFS directory:
root@localhost:~$ exportfs -a
Step 5: Restart NFS Server & Auto-start on Boot
Changes will be applied by restarting NFS server as follows:
root@localhost:~$ systemctl restart nfs-kernel-server
Then, ensure that the service auto-starts on server boot:
root@localhost:~$ systemctl enable nfs-kernel-server
Finally, firewall plays an important role whether remote clients will be able to access your NFS share or not.
Port 2049 is the one responsible for NFS protocol, so allow it on your firewall (firewalld, iptables or ufw).
That’s all! Congratulations on setting up your NFS Server on Debian 12 or Ubuntu 22.04 server!