How to set up Network File System on Ubuntu 18 Server

How to set up Network File System on Ubuntu 18 Server

Introduction

Network File System allows for the sharing of directories and files with other users and programs remotely over a network. These users and programs access the shared resources as if they were locally mounted on their devices. NFS is generally implemented in file servers and has a number of benefits including:

  • Users in the network need not create different home directories as the only one can be created and shared.
  • Less disk space is needed on client devices as most of the files are stored in the centralized storage and shared over the network.
  • External storage devices are needed less as folders and files may be shared over the network. Bear in mind that external storage devices are a major contribution to the introduction and spread of malware in an organizational protocol.
  • It allows confidentiality of data is enhanced to be enforced as the central storage may be accessed using implementations such as Kerberos.

Prerequisite

  • 2 running instances of an Ubuntu 18.04 servers or the second one be an ubuntu 18.04 client operating systems connected in a private network
  • Both instances should be having a non-root user with sudo privileges
  • Some basic knowledge of Linux and Linux commands

Steps

Update system packages on both machines

$ sudo apt update && sudo apt upgrade

On the host

This is where the NFS server will be installed. The client will mount directories from this machine, hence the server.

Install the NFS server packages

$ sudo apt install -y nfs-kernel-server

Configuration

Head over to /etc/exports to configure the directories that you want to export. For my case, I am exporting the /home directory. Edit the ip address to the one you are using on your host machine.

$ sudo nano /etc/exports
# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
/home 104.248.223.49(rw,sync,no_root_squash)

Available options include:

  • rw means read-write access, the alternative option may also be ro (read-only).
  • Sync means changes made to the host directory must be written before replying, this ensures the content shared is up to date. You can ignore by using the async option
  • no_root_squash means the client can have root privileges on the shared content located in the host machine.
  • no_subtree_check which means nfs will not go to the shared directory’s parent folders to verify its permission hence increasing reliability but reducing security. subtree_check on the other hand does the opposite

Exit editor while saving changes.

Configure firewall rules

$ sudo ufw enable 
$ sudo ufw allow from 104.248.223.51 to any port nfs

On the Client

Install the nfs client package

$ sudo apt install nfs-common

Create the local mounting points

Create the directories to which your mounted directories will be placed. You can create it where you want.

$ mkdir /home/nfs

Mount the exported folder to your created directory

$ sudo mount 104.248.223.49:/home/nfs

Special Note: The local directory to which your mounting your folder must exist, in the above instance, the /home/nfs directory exists.

Conclusion

That’s it, you have successfully mounted a remote directory onto another machine by use of the network file system.To unmount the shared folder, you can use the umount command on the client’s machine:

$ sudo umount /home/nfs

Check out these top 3 Linux hosting services

FastComet
£1.42 /mo
Starting price
Visit FastComet
Rating based on expert review
  • User Friendly
    4.7
  • Support
    5.0
  • Features
    4.8
  • Reliability
    4.5
  • Pricing
    5.0
Kamatera
£3.17 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
    3.5
  • Support
    3.0
  • Features
    3.9
  • Reliability
    4.0
  • Pricing
    4.3
HostArmada
£1.97 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0

How to Create a Non-root User on Your Ubuntu 18.04 VPS or Dedicated Server

This guide shows you how to create a user on your Ubuntu 18.04 virtual server.
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester

How to Install a Self-Signed SSL Certificate on Your Ubuntu 18.04 VPS or Dedicated Server

This how-to article will teach you how to create a self-signed SSL certificate o
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester

How to Set Up Cron Jobs on Your Ubuntu 18.04 Dedicated Server or VPS

This guide shows webmasters and administrators how to set up cron jobs on your U
3 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Install WordPress on Your Ubuntu 22.04 VPS or Dedicated Server

This tutorial will show you how to install WordPress on your Ubuntu 22.04 virtua
3 min read
Idan Cohen
Idan Cohen
Marketing Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top