How to setup a NFS Server on Ubuntu

Good day my friend,
in this article I am guiding you through the installation and configuration process to setting a NFS Server on you Ubuntu Server.

NFS (Network File System) is a distributed filesystem protocol that allows clients such and other server and desktop computers to access remote files and directories as if they are available locally on their systems. This allows client systems to leverage large centrally shared storage. Users and systems can access the same data from any system across their network.

NFS Server on Ubuntu
NFS Server

It is required that you already have a Ubuntu Server setup and running but if you need help doing so please read: Simple Ubuntu Server 20.04 LTS installation.

Installation & Configuration

Lets get started by checking for server updates and install them if needed.

sudo apt update
sudo upgrade -y
sudo dist-upgrade -y

Now that this is out of the way lets move on and install the NFS Server with the following command:

sudo apt install nfs-kernel-server -y

It should look something like the screenshot below.

NFS Server install on Ubuntu
NFS Server install

At this point the NFS Server is installed and ready to be configured. My personal preference is to use the /srv directory and configure NFS to share from there as I do with other services as well but you can use whatever your preference is. Let’s create a directory and set ownership with the following command:

sudo mkdir -p /srv/nfs
sudo chown nobody:nogroup /srv/nfs

The directory is created lets edit the /etc/exports file next with the following command:

sudo vim /etc/exports

In the exports configuration file we will specify what we share and to whom, add the following line to it and save the file:

/srv/nfs *(rw,sync,no_subtree_check)

Here is the breakdown on that configuration line

  • /srv/nfs : that’s the directory that will be served to others
  • * : the asterisk symbolizes all client IP’s are allowed a better option would be a specific IP address or a Subnet like 192.168.1.0/24 or device DNS names will work as well.
  • rw :this specifies the permission level rw is read-write permission and ro is read-only
  • sync : to ensures that the NFS Server syncs all requests first before it replies to other requests hence it is safer that data has been committed
  • no_subtree_check : with this option subtree checking will be disabled, which has a mild security implication but improved reliability.

If you like to read more about this I recommend to check the man pages for more. Run the following command:

man exports

One last step needs to happen, the NFS Share needs to be exported. Execute the following command:

sudo exportfs -a

Conclusion

So my friends, this concludes the install and configuration of the NFS Server and in the following Article I will show you how to get a Client connected to the NFS Share. If you like to read more about the NFS Kerner Server implementation read here.