How to set up NFS Mount on Ubuntu Linux

|

|

The post guides Linux admins and students on setting up NFS (Network File System) mount points, which allow client computers to access network resources. Procedures for installing NFS server and client packages, creating folders to export to clients, configuring the NFS Exports file, mounting the NFS share on the client, and un-mounting folders are given.…

This article explains setting up NFS mount points in Ubuntu Linux.

Setting up NFS mount points on Ubuntu Linux is a great way for client computers to access network resources. NFS (Network File System) is a distributed file system that can be enabled in a client/server environment.

It is easy to configure for those wishing to allow NFS client machines to access NFS mount points on a server using the NFS protocol. NFS is also suitable for public access to network resources. Overall, NFS is a reliable and efficient way to share files and folders between Linux machines.

This brief tutorial shows users how to set up NFS mount points on a server for client access. It should be quick and easy to understand, even for new users.

For this tutorial, we’re going to be using two systems:

  1. Server Computer with IP address 192.168.71.131
  2. Client Computer with IP address 192.168.71.133
  3. Share Resource Namepublic data

Installing NFS Server packages on the Host computer

To get the NFS server working, you must install the server packages. To do that, run the commands below:

sudo apt-get update
sudo apt-get install nfs-kernel-server

When the server packages are installed, switch to the client to install the client package.

Installing NFS client packages on the client systems

You must install NFS client packages to access NFS mount points on the server. To do that, run the commands below

sudo apt-get update
sudo apt-get install nfs-common

After installing the client packages, switch to the server to configure a mount point to export to the client.

Creating the folder/directory to export (share) to the NFS clients

Now that NFS’s server and client components have been installed, you can make the folder or directory to export to the clients.

We’re creating a publicdata folder in the /mnt/ directory for this tutorial. To make the folder, run the command below.

sudo mkdir -p /mnt/publicdata

Since we want this location to be viewed by all clients, we will remove the restrictive permissions. To do that, change the folder permission to be owned by nobody in no group.

sudo chown nobody:nogroup /mnt/publicdata
sudo chmod 777 /mnt/publicdata

The folder is ready to be exported so the client can access it. Subfolders can be created there as well.

Configuring the NFS Exports file

Now that the location is created on the host system open the NFS export file and define the client access.

Access can be granted to a single client or an entire network subnet. For this tutorial, we’re allowing access to the client mentioned above.

NFS export file is at /etc/exports

In that file is where you define client access. The configuration format is as follows:

/server_share_resource          client_IP(share option1, .. share_optionN)

So, permit access to only the client with IP 192.168.71.133. To do that, open the export file by running the commands below:

sudo nano /etc/exports

Then add the line below:

/mnt/publicdata          192.168.71.133(rw,sync,no_subtree_check)

And save the file. Only clients with the IP address defined above will access that location remotely.

To allow an entire subnet.

/mnt/publicdata          192.168.71.0/24(rw,sync,no_subtree_check)

The options in the setting above are: rw= read/write, sync=write changes to disk before applying, and no_subtree_check= prevents subtree checking.

Export the shares by running the commands below.

sudo exportfs -a

Restart the NFS server by running the commands below.

sudo systemctl restart nfs-kernel-server

Mounting the NFS share on the client

Next, switch to the client to mount the NFS directory defined on the server. To do that, create a mount point on the client where the host mounts the shares. This can be anywhere.

sudo mkdir -p /mnt/publicdata

After creating the mounting point, use the command below to mount the server NFS folder on the client

The format to mount directories on the client is as shown below:

sudo mount server_IP:/NFS_directory_on_server   /client_mount_point

sudo mount 192.168.71.131:/mnt/publicdata /mnt/publicdata

This command above mounts the directory on the client’s computer.

You can automatically mount the directory by editing the /etc/fstab file by adding the lines below and saving the file.

sudo nano /etc/fstab

Then add the line below and save.

192.168.71.131:/mnt/publicdata /mnt/publicdata nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0

To un-mount the folder, use the umount command.

sudo umount /mnt/publicdata

If, for some reason, the client can’t access the host folder, open the Ubuntu firewall to the client on the host computer.

sudo ufw allow from 192.168.71.133 to any port nfs

That’s it!

This is how to set up an NFS mount for clients in a client/server environment using the NFS protocol.

Enjoy!

You may also like the post below:

Like this:



One response to “How to set up NFS Mount on Ubuntu Linux”

  1. mahajneh Avatar
    mahajneh

    Hi,

    This is a great article, it helped me alot, but you are missing a tiny thing:
    At the automount on the client side you mentioned to edit the fstab and add the below line:
    192.168.71.131:/mnt/publicdata /mnt/publicdata auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0
    it should be:
    192.168.71.131:/mnt/publicdata /mnt/publicdata nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0
    * you should add nfs before auto to work.
    Thank you Again.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.