If you need to share common data among different client systems, you will find NFS helpful for sharing directories and files with other clients. In this article, you will learn how to Install and Configure NFS on Ubuntu. Network File Share (NFS) is a protocol used to share files and directories over a network of Linux clients. Regardless of the distribution, you are using, Network File System enables you to share directories over a network that is created on the NFS server and files added to it. Since the NFS protocol is not encrypted by default, it does not provide user authentication, and you can access the server by the client’s IP address or hostname.
Prerequisites to Install NFS on Ubuntu
To let this tutorial works correctly, provide the options below and move on.
- A system running Ubuntu.
- A non-root user with
- Have access to the command line/Terminal.
- Two Ubuntu machines.
Tip: Your Ubuntu running machine will act as an NFS server and the second one runs any other Linux distribution that the share will be mounted on it. While the server and the clients must communicate together over a private network, you are recommended to use public IP addresses and also configure the server firewall to allow traffic on port 2049 only from trusted sources.
Tutorial Install and Configure NFS on Ubuntu
Let’s go through the steps of this guide to install and configure NFS on Ubuntu and other Debian-based distributions. In the end, you are an expert in installing and configuring an NFS server on your Ubuntu and also the way of installing NFS clients on the client Linux system.
Step 1: Installing the NFS Server
For the first step, you should start with setting up the NFS server. Before that, updating the system packages is reasonable. Then, you are ready to install the NFS server. So, run:
$ sudo apt update $ sudo apt install nfs-kernel-server
When you are prompted, type Y and press ENTER to let the installation start automatically.
Step 2: Create a Shared NFS Directory
To Configure the NFS server, you need to make a directory to be shared by all the client systems. Here we name it ‘’nfs-share’’. So, run:
$ sudo mkdir -p /mnt/nfs_share
Step 3: Configure Directory Permissions
When your directory is created, all the client machines should be able to access it easily. So, set the permissions of it by running the following command:
$ sudo chown -R nobody:nogroup /mnt/nfs_share/
Step 4: Establish File Permissions
The 4th step to install and configure NFS on Ubuntu is where you can set the file permissions to the ‘’nfs-share’’ directory file.
$ sudo chmod 777 /mnt/nfs_share/
In this way, read, write, and execute permissions will be allocated.
Step 5: Grant NFS Access
To access the NFS server, you need to grant access to the client system. Open “/etc/exports” in your favorite editor. Here we use nano.
$ sudo nano /etc/exports
And if you prefer Vim:
$ sudo vim /etc/exports
Then, add the required line depending on whether you prefer to grant access to the entire subnet, single, or multiple clients. Then press CTRL+O to save the file
The functions of the above command are:
- Clients are given read-and-write access to server directories using the “rw” option.
- In order to reply to the client, “sync” causes NFS to write modifications. By using this option, clients will always see the host’s actual condition.
- Subtree checking is disabled by “no subtree check” When users rename files, the subtree procedure could lead to issues.
Use the command below to grant access to a single client.
/mnt/nfs_share client_IP_1 (re,sync,no_subtree_check)
And if you prefer multiple clients, you need to specify each client on a separate file as you see below:
/mnt/nfs_share client_IP_1 (re,sync,no_subtree_check) /mnt/nfs_share client_IP_2 (re,sync,no_subtree_check)
Step 6: Export the NFS Share Directory
As the edits are made on /etc/exports, you can export all shared directories you registered in that file. To do this, run:
$ sudo exportfs -a
Next, type the following command to restart the NFS Kernel Server to apply the changes to the configuration.
$ sudo systemctl restart nfs-kernel-server
Step 7: Grant NFS Access through the Firewall
In this step, you are going to allow clients to access the server if you are using UFW. In this way, accessing and mounting the shared directory will be possible.
sudo ufw allow from [clientIP or clientSubnetIP] to any port nfs
Also, if the firewall is turned off, enable it:
$ sudo ufw enable
Then, you can use the command below to check the changes:
sudo ufw status
When you see that the traffic in the port
2049 (default file share) is allowed in your output, it means you’re all set.
Step 8: Set Up the NFS Clients on Ubuntu
So far, you installed the NFS server and exported the shares. Let’s configure the clients and mount the remote file system. The same process is possibly to be done on macOS and Windows machines to mount the NFS share on them. Run the commands below to enable NFS on client machines and install the NFS common package.
To install the NFS client on Debian and Ubuntu:
$ sudo apt update $ sudo apt install nfs-common
To install the NFS client on CentOS and Fedora:
$ sudo yum install nfs-utils
And finally, type “y” and press ENTER to start the installation.
Step 9: Create a Mount Point on the NFS Client System
Since the client machine needs a mount point for the shared directory exported by the server, use the following command to create a directory.
sudo mkdir -p /mnt/nfsdir_client
Next, run the command below to mount the shared directory on the client system.
sudo mount host_IP:/mnt/nfsdir /mnt/nfsdir_client
Verify if the mounting folder is done successfully by using the
df -h command.
Run the command below to unmount the shared folder when you no longer need it.
sudo umount /mnt/nfsdir_client
Note: Watch to not run ‘’unmount’’ instead of
Step 10: Test the NFS Share on the Client System
You can create a few files in the NFS share directory located on the server to check that your NFS setup is working correctly.
$ cd /mnt/nfs_share/ $ touch file1.txt file2.txt file3.txt
To check whether the files exist in the directory or not, head back to the NFS client system:
$ ls -l /mnt/nfs_clientshare/
On your Output, check if you can access the files you created on the NFS server or not. If files are successfully accessed on the client via the NFS server you’re all set.
How to Mount NFS Shared Directories on OS Boot
You can run the command below to let the folders stay mounted after you restart the machine. Just add them to the /etc/fstab file.
sudo nano /etc/fstab
sudo vim /etc/fstab
Next, copy the following line to the bottom of the file, replacing “host_IP” with the actual IP address of the host:
host_IP:/mnt/nfsdir /mnt/nfsdir_client nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0
In this way, all folders on the list will be mounted automatically on every boot. You can add the line for any folder you need.
How to Uninstall the NFS Server on Ubuntu
If you consider uninstalling the NFS server, use the following command.
$ sudo apt remove nfs-kernel-server
How to Uninstall the NFS Client on Ubuntu
Run the command below to uninstall the NFS client.
$ sudo apt remove nfs-common
In this article, you learned How to Install and Configure NFS on Ubuntu. You reviewed all the required steps to set up an NFS server and mount the remote file systems on the client machines. As we mentioned, the NFS protocol is not encrypted by default. So, if you are considering implementing NFS in production and sharing worthy data, you are recommended to enable Kerberos authentication.
As a good solution for remote access to data, NFS comes with an easy setup and well performs. This guide can help you to set up an NFS network on your Ubuntu machines (on the server and client sides). But if you encounter any problems, please do not hesitate to contact us. Our technical support team will try their best to solve your problems.